I’m working on a kind of iPhone game where player travels through programmically generated wormhole. To draw the wormhole I chose to draw to arrays of textured vertical lines a pixel width to implement top and bottom walls of the wormhole. Every frame all the lines must be shifted left to implement the player movement and new lines must be drown in free space at right. But drawing 1000 textured rectangles every frame is killing my FPS.
And I’m looking for a solution to save all the lines that was drown at previous frame and redraw them altogether to the new shifted position.
It would be terrific if there is a way to draw textured rectangles in some kind of buffer that is bigger than screen, and then render this buffer to the screen.
I guest these are newbie questions cause I’m totally new in OpenGL.
I spent hours trying to figure this out, but haven’t succeeded. So Any help appreciated.
To expand on @Jerry’s answer, I’ll walk you through the steps, since you’re new. First, we’ll create the frame buffer object:
Next, we’ll create the empty texture to hold our snapshot. This is just the usual OpenGL texture creation stuff, and you can modify it to fit your needs, of course. The only line to notice is the
glTexImage2Dline – note that instead of pixel data as the last coordinate, you can passNULL, which creates an empty texture.Now we bind the texture to the frame buffer:
and check to see if everything went OK:
Now we’re all set up to draw!
And finally, clean up the frame buffer, if you don’t need it any more:
Some caveats: