View Full Version : Blitting to offscreen surface in OpenGL
lakibuk
04-02-2007, 06:41 AM
The game i am working on is not tile-based.
It's more of a free landscape where individual pixels can be destroyed (like in Lemmings and Worms):
http://www.blueskied.com/images/misc/landscape.jpg
So i can't draw the whole playfield everytime.
That's why i draw it on a offscreen plain (as it's called in DirectX).
I copy this surface to the backbuffer every frame:
Offscreen plain (playfield)
|
copy to
|
Backbuffer
|
draw sprites on backbuffer
|
switch backbuffer to Front
The problem is that blitting to a offscreen surface is not possible in OpenGL (and therefore PTK which i would like to use for MAC etc.).
Anyone know a solution to this problem?
As far as I know you have two options to do this in OpenGL:
1) Use the frame buffer object extension. http://www.gamedev.net/reference/articles/article2331.asp
or
2) Use glCopyTexImage2D( )
http://www.opengl.org/sdk/docs/man/xhtml/glCopyTexImage2D.xml
I believe the first option is the faster/more modern approach, but requires an extension which may be a problem depending on your target audience. In most cases, using the second option may work fine.
I hope this was along the lines of what you need :)
Edit: I missed the part about PTK in there :) Have you set up PTK to handle raw OpenGL calls? It isn't particularly hard, but I don't recommend it.
I wrote an FPS style 3D movement prototype using PTK but it wasn't very pleasant. (Reason I did something so silly: I wanted to use PTK's easy x-platform windowing/input, texture loading and ksound class to speed up development of a real 3D prototype.)
Hi,
If I understand you correctly, you're just trying to blit large blocks of pixels directly the the backbuffer. There's functions like 'glDrawPixels' to do just this sort of work. I understand it's usually fairly quick even on software OpenGL implementations too.
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/drawpixels.html
lakibuk
04-02-2007, 08:04 AM
Thanks.
@MFS: glCopyTexImage2D() sounds good. It does what i need: Blitting to a offscreen surface. Have to check it out though, i know nothing about OpenGL.
Why don't you recommend to use raw OpenGL calls with PTK? Cause you made a mistake or is it problematic for other reasons?
@-B-: Blitting to the frame buffer is no problem. What i want to do is blitting to a offscreen surface (texture in OpenGL?).
It is possible for sure, but PTK does a lot of state management in its own calls. So you have to be careful to consider the order and placement of your OpenGL calls when mixing with PTK calls, as often a PTK call will alter your settings 'behind the scenes'.
For example you might run into some issues with glEnable( ) for textures, if you use are using the PTK blit calls, which will enable and disable textures within that call (I think, not 100% sure).
In the end, it is definitely doable, just pay close attention to how you try and do things, otherwise you will go crazy like me looking for 'mistakes' when you are really just mis-configuring your GL states. Knowing exactly how PTK operates behind the scenes will definitely help you in this area.
PTK is great by the way :)
Good luck with your project :) Destructible terrain is always fun.
glPushAttrib/glPopAttrib (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/pushattrib.html) can help with preserving the gl state you need. Apparently it's not particularly helpful for performance though.
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.