OpenGl & max2D in GUI App
BlitzMax Forums/MaxGUI Module/OpenGl & max2D in GUI App| 
 | ||
| I just brought the GUI kit last night but I'm missing some fundamentals here. How can I mix OpenGL (as in the glcube example) and Max2d functionality (DrawImage etc)? I've tried searching without any luck. Thanks in advance. | 
| 
 | ||
| Use a Canvas gadget. | 
| 
 | ||
| Thanks Brucey.  That's what the glcube sample is doing.. ... SetGraphicsDriver GLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER ... Local c:TGadget = CreateCanvas(0,0,w.ClientWidth(),w.ClientHeight(),w,0) c.setlayout 1,1,1,1 CreateTimer( 60 ) While True WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_TIMERTICK RedrawGadget c Case EVENT_GADGETPAINT SetGraphics CanvasGraphics( c ) 'loads of gl specific stuff... 'but it crashes on any max2d calls DrawRect( 0, 0, 100, 100 ) Flip EndSelect Wend | 
| 
 | ||
| I've done some more digging.  It seems there is no valid Max2d graphics object created in this example (usually created with a Graphics w,h command) while there are GLDrawRect and GLDrawPixmap functions. Does this mean; a) I have to find another way of initialising Max2d, or b) i have to stick to using opengl? | 
| 
 | ||
| Use this - GLMax2DGraphicsDriver() - instead of GLGraphicsDriver(). | 
| 
 | ||
| Close :)  It's GLMax2DDriver.  I scanned for GLMax2DGraphicsDriver and found nothing, so scanned for GLGraphicsDriver and GLMax2DDriver in with it. The next issue is that it doesn't automatically handle window resize. I solved that with capturing WINDOWSIZE events and completely recreating the gadget to the new client size; 
Case EVENT_WINDOWSIZE
    FreeGadget( c )
    c = CreateCanvas(0,0,w.ClientWidth(),w.ClientHeight(),w,0)
Is there anything wrong with this? I was losing loaded images tho (so, I guess they're tied to a canvas?) Loading them after recreating the canvas somehow didn't stop them from being garbage collected a few frames later. This only worked when I suspended GC.. 
Case EVENT_WINDOWSIZE
    FreeGadget( c )
    c = CreateCanvas(0,0,w.ClientWidth(),w.ClientHeight(),w,0)
    r = LoadImage( "iconstrip1.png" )
So ultimately I had to ensure the image was completely deleted and recreated.. 
Case EVENT_WINDOWSIZE
    r = Null
    FreeGadget( c )
    GCCollect 
    c = CreateCanvas(0,0,w.ClientWidth(),w.ClientHeight(),w,0)
    r = LoadImage( "iconstrip1.png" )
I think I've about hacked this to death :/ | 
| 
 | ||
| When you resize, you need to reset your ViewPort() to the correct dimensions.   Close :) It's GLMax2DDriver  Apologies... I should look them up rather than try to remember stuff ;-) | 
| 
 | ||
| ViewPort() -- that's more like it!  I think you'll agree this is a bit cleaner... 
case EVENT_WINDOWSIZE
    SetViewport( 0, 0, w.ClientWidth(), w.ClientHeight() )
 Apologies... I should look them up rather than try to remember stuff ;-)  No worries, your memory is a lot more effective than my ignorant fumbling. Cheers Brucey! |