MaxGUI: How to select other buffers for canvas?

BlitzMax Forums/BlitzMax Programming/MaxGUI: How to select other buffers for canvas?

I was going to ask how to do this, then I figure out how to do it. You just set the buffers you want as the default buffers when selecting the driver to use.

This lets you open a MaxGUI canvas and give it the buffers you want to use in OpenGL. I presume this works for DirectX driver too.

Example...
'Select what buffers you want for a MaxGUI canvas
'(select them in the default for the driver!)

Strict

'Choose what buffers you want as part of the driver default
'before setting up the canvas
SetGraphicsDriver(GLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_ALPHABUFFER|GRAPHICS_ACCUMBUFFER|GRAPHICS_DEPTHBUFFER|GRAPHICS_STENCILBUFFER)

'Open window with canvas graphics
Local Window:TGadget=CreateWindow("win",0,0,640,480,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Local Canvas:TGadget=CreateCanvas(0,0,640,480,Window)
Local GraphicContext:TGraphics=CanvasGraphics(Canvas)
SetGraphics GraphicContext

'Print the bits per component/buffer
Local a:Int
glGetIntegerv(GL_RED_BITS,Varptr(a))
Print "Red bits: "+a
glGetIntegerv(GL_GREEN_BITS,Varptr(a))
Print "Green bits: "+a
glGetIntegerv(GL_BLUE_BITS,Varptr(a))
Print "Blue bits: "+a
glGetIntegerv(GL_ALPHA_BITS,Varptr(a))
Print "Alpha bits: "+a
glGetIntegerv(GL_DEPTH_BITS,Varptr(a))
Print "Depth bits: "+a
glGetIntegerv(GL_ACCUM_RED_BITS,Varptr(a))
Print "Accum Red bits: "+a
glGetIntegerv(GL_ACCUM_GREEN_BITS,Varptr(a))
Print "Accum Green bits: "+a
glGetIntegerv(GL_ACCUM_BLUE_BITS,Varptr(a))
Print "Accum Blue bits: "+a
glGetIntegerv(GL_ACCUM_ALPHA_BITS,Varptr(a))
Print "Accum Alpha bits: "+a
glGetIntegerv(GL_STENCIL_BITS,Varptr(a))
Print "Stencil bits: "+a

'Cleanup
EndGraphics 'Maybe not needed?
FreeGadget Canvas
FreeGadget Window
End


Watch out if you're:
1) Using Direct X; and
2) Using multiple canvases in MaxGUI.

If you close a canvas under these conditions, for some reason the DX7 context is lost, and subsequent operations on the other canvas results in a crash.

No problem under OpenGL, though.

My multimedia authoring software uses OpenGL for the unser interface, and switches to DirectX for the full-screen runs.

As far as I can tell, you only need to FreeGadget the window. This will automatically free all the child gadgets.

Neil