Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large scrolling background in OpenGL ES

I am working on a 2D scrolling game for iPhone. I have a large image background, say 480×6000 pixels, of only a part is visible (exactly one screen’s worth, 480×320 pixels). What is the best way to get such a background on the screen?

Currently I have the background split into several textures (to get around the maximum texture size limit) and draw the whole background in each frame as a textured triangle strip. The scrolling is done by translating the modelview matrix. The scissor box is set to the window size, 480×320 pixels. This is not meant to be fast, I just wanted a working code before I get to optimizing.

I thought that maybe the OpenGL implementation would be smart enough to discard the invisible portion of the background, but according to some measuring code I wrote it looks like background takes 7 ms to draw on average and 84 ms at maximum. (This is measured in the simulator.) This is about a half of the whole render loop, ie. quite slow for me.

Drawing the background should be as easy as copying some 480×320 pixels from one part of the VRAM to another, or, in other words, blazing fast. What is the best way to get closer to such performance?

like image 853
zoul Avatar asked Oct 20 '08 09:10

zoul


1 Answers

That's the fast way of doing it. Things you can do to improve performance:

  • Try different texture-formats. Presumably the SDK docs have details on the preferred format, and presumably smaller is better.
  • Cull out entirely offscreen tiles yourself
  • Split the image into smaller textures

I'm assuming you're drawing at a 1:1 zoom-level; is that the case?

Edit: Oops. Having read your question more carefully, I have to offer another piece of advice: Timings made on the simulator are worthless.

like image 148
Menkboy Avatar answered Sep 30 '22 07:09

Menkboy