GraphicsWidth(), Height() only returns

BlitzMax Forums/MaxGUI Module/GraphicsWidth(), Height() only returns

JoshK(Posted 2007) [#1]
When used with a canvas and OpenGL gfx driver, GraphicsWidth() and Height() return the original size of the canvas, not the current canvas size.


TaskMaster(Posted 2007) [#2]
Why is the Canvas size changing?

I think it is best to destroy the canvas and make a new one when you need to resize it.


TomToad(Posted 2007) [#3]
This works for me.
SuperStrict
SetGraphicsDriver GLMax2DDriver()

Global Window:TGadget = CreateWindow("Graphics",100,100,640,480)
Global Canvas:TGadget = CreateCanvas(0,0,ClientWidth(Window),ClientHeight(Window),Window)
SetGadgetLayout(Canvas,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED)
Global timer:TTimer = CreateTimer(60)
AddHook EmitEventHook, MyHook

Repeat
	WaitEvent()
Forever

Function MyHook:Object(id:Int,Data:Object,Context:Object)
	Local Event:TEvent = TEvent(Data)
	
	Select Event.id
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(Canvas)
			Cls
			DrawText GraphicsWidth()+" "+GraphicsHeight(),10,10
			Flip
			Return Null
		Case EVENT_WINDOWSIZE
			SetGraphics CanvasGraphics(Canvas)
			SetViewport 0,0,ClientWidth(Window),ClientHeight(Window)
			RedrawGadget Canvas
			Return Null
		Case EVENT_TIMERTICK
			RedrawGadget Canvas
			Return Null
	End Select
	Return data
End Function

Although I'd think you'd want to use GadgetWidth() and GadgetHeight() on a canvas.

Edit: Didn't notice you were having problems with only OpenGL, so I changed the above code to use OpenGL instead of DirectX. Still works though :)


skidracer(Posted 2007) [#4]
In the case of (at least the original) dx7 driver, the graphics context was setup as a single backbuffer the size of the primary desktop screen shared by all canvas, so in theory this is what should be being reported back as the SetViewPort command is of course useful for rendering back into images (grabpixmap instead of flip) not just to attached canvas gadgets.

I don't know about OpenGL, please post some code.