Combining Graphics and GL context?

BlitzMax Forums/BlitzMax Programming/Combining Graphics and GL context?

Beaker(Posted 2004) [#1]
How would you go about combining a normal bmax Graphics session with a GL drawn 2D quad?

Is this wise?


teamonkey(Posted 2004) [#2]
You should be able to do it without any problems at all.

Something like:
Graphics 640,480,0

glBegin GL_QUADS
    glVertexf 100,100
    glVertexf 140,100
    glVertexf 140,140
    glVertexf 100,140
glEnd

WaitKey



Beaker(Posted 2004) [#3]
Thanks for the help, that doesnt compile, but this does:
Graphics 640,480,0

glBegin GL_QUADS
    glVertex2f 100,100
    glVertex2f 140,100
    glVertex2f 140,140
    glVertex2f 100,140
glEnd

Flip
WaitKey



ImaginaryHuman(Posted 2004) [#4]
You should be able to combine any Max2D stuff with direct OpenGL since Max2d is based on OpenGL. For example the Graphics command called bglCreateContext, which in turn calls the OpenGL glCreateContext (?) command.

Anything you do with OpenGL commands should show in the Graphics screen or window.

Also, the example above didn't compile? Or it did compile but it showed nothing because you didn't do a Flip?

One thing to note is that Max2D changes and tries to keep track of the state of some variables such as the TEXTURE2D status. I found that on my iBook I had to manually disable that flag before doing custom OpenGL, and enable it again at the end, whereas on an iMac it wasn't needed. I don't know why, but if you mess with the flags that Max2D is trying to maintain you might get into a mess.


teamonkey(Posted 2004) [#5]
One thing to note is that Max2D changes and tries to keep track of the state of some variables such as the TEXTURE2D status. I found that on my iBook I had to manually disable that flag before doing custom OpenGL, and enable it again at the end, whereas on an iMac it wasn't needed. I don't know why, but if you mess with the flags that Max2D is trying to maintain you might get into a mess.


Yeah - see my post here: http://www.blitzbasic.com/Community/posts.php?topic=41768


Beaker(Posted 2005) [#6]
AngelDaniel - it didn't compile cos you spelt glVertex2f wrong. :D

Another question:
How can I control the drawing order of GL and Max2D stuff?


fredborg(Posted 2005) [#7]
You simply draw it in the order you want it drawn :)

And a happy New Year!


taxlerendiosk(Posted 2005) [#8]
What's the easiest way of setting the texture to be used from an image? Do you have to draw it? Surely there's a better way, SetTexture or something.


ImaginaryHuman(Posted 2005) [#9]
Um, you can either sort everything into z order and draw in the right order, or, you can use OpenGL's depth buffer and make sure to position your objects with slightly different Z positions and use depth checking so that only the front most stuff is drawn.


marksibly(Posted 2005) [#10]

How would you go about combining a normal bmax Graphics session with a GL drawn 2D quad?



I don't really recommend this right now, as it could severely limit our ability to tinker with things - ie: people shouldn't really be depending on the way Max2D works internally.

But I can definitely see a use for it (fullscreen rotation effects etc) so perhaps Max2D should have a 'SaveState/RestoreState' type system?


Is this wise?



Nope!


N(Posted 2005) [#11]
But I can definitely see a use for it (fullscreen rotation effects etc) so perhaps Max2D should have a 'SaveState/RestoreState' type system?


First of all, that would be a good idea.

Second of all, there are uses for it that I think you're overlooking, such as drawing HUDs/UIs/'2D' graphics for 3D games. Or writing an application that needs a GUI and a 3D viewport (e.g., world editors such as Maplet or Radiant).

Perhaps a SetupMatrices() method for the GLMax2D driver would work for the drawing stuff. Just an idea.


Paul "Taiphoz"(Posted 2005) [#12]
I think what mark was meaning is that it might be better to wait for GLMax3D before starting to bodge our own 3D stuff in 2D sorta thing.

I might be wrong though.


Dreamora(Posted 2005) [#13]
or simply not tinker around with a module that possibly could change that much that all your stuff you build in it is broken afterwards.


Beaker(Posted 2005) [#14]
I am making a small FONText lib for BlitzMax 2D (I don't want it to rely on a 3D module for it to work). Currently, I can't do what I want to do with Max2D alone. It doesnt let me set UVs for quads etc.

'SaveState/RestoreState' sounds like a great idea.

When I asked about the drawing order I didn't mean within the GL stuff I'm drawing, but more between the GL stuff and Max2D stuff. I ask cos DrawText() (and maybe others) always seem to draw on top of any of my custom GL drawings, regardless of what order I do them in code!


Difference(Posted 2005) [#15]
SaveState/RestoreState sounds good!