More OpenGL with MAX2D

BlitzMax Forums/OpenGL Module/More OpenGL with MAX2D

tonyg(Posted 2005) [#1]
How do you access the extra OpenGl buffers such as stencil etc when using the Graphics command?
If I run Nehe27 I get a nice display of shadows.
If I change the blcreatecontext to a graphics command the shadows don't appear.


ImaginaryHuman(Posted 2005) [#2]
I tried doing the same sort of thing here, where I exchanged the Graphics for the bglCreateContext and got a blank screen.

The Graphics command sets up a number of things - does several other OpenGL calls to initialize some things and get things into the right mode, setting up a viewport and so on.

bglCreateContext doesn't do that, it just creates a graphics context but doesn't set up any of the OpenGL machine. You have to explicitly define your own viewport, Ortho2D orthagonal projection matrix, and any other settings you need, etc.

I found that in general, trying to use Max2D at the same time as interspersing your own OpenGL calls isn't very reliable. Max2D is trying to keep track of a number of states and conditions and any extra calls you add in are likely to interfere with that. With OpenGl direct, you're stepping in through the back door and fiddling under the hood of Max2D. If you don't know exactly what states Max2D has set up and how to preserve them, you will mess things up and get unexpected results.

What I decided to do was to just ditch most of Max2D and do everything with custom OpenGL calls. About the only part of Max2D I use is to load pixmaps and get the location of the pixmap data, along with the pitch etc. I do all my texture uploading and world setting-up myself. You have more control that way too.

I don't think you can just exchange Graphics for bglCreateContext and expect them to be the same, Graphics does a number of other things that the create context doesn't do.


ImaginaryHuman(Posted 2005) [#3]
I might've read your question right. I don't think you can use a stencil buffer with the Graphics mode, because you have to define what buffers you want when you define the context. "Graphics" defines a context already and I'm fairly sure it doesn't include a stencil buffer. You will have to use bglCreateContext.


tonyg(Posted 2005) [#4]
Yep, I'm guessing that as well. It's a bit of a shame. Unless I'm missing something there's all the power of raw OGL, all the benefits of BMax modules but no way to use all of both together.


teamonkey(Posted 2005) [#5]
No, the stencil buffer's always there, you don't need to specify it when you create your context. The problem's probably the orthographic mode or something. Does anything draw at all?


tonyg(Posted 2005) [#6]
Yep, only the shadows are missing (9800pro Winxp sp2)


teamonkey(Posted 2005) [#7]
I've just worked out why, and it's pretty obvious. Graphics doesn't set up a depth buffer :)


tonyg(Posted 2005) [#8]
That's right. The question was, really, how do you get an OpenGl context with all the buffers available while using the Graphics command.


teamonkey(Posted 2005) [#9]
The answer is, you can't - you have to use bglCreateContext. Unfortunately this also means that you can't use some of the Max features mechanism.

Actually, what you could do (and this would be an almighty hacky way of doing things) is something like:
Graphics width, height, depth, hertz
' Grab the actual width, height, depth and screen hertz Graphics has generated
bglDeleteContext
bglCreateContext width, height, depth, hertz, flags
' Set the viewport etc.

That way you might be able to hang on to Max2D while being able to use the depth buffer. But as I said, it's one hell of a hack if it even works.


ImaginaryHuman(Posted 2005) [#10]
Or you could chop out the code for Graphics and modify it?