Optimized 2D Tile Scrolling in OpenGL
Posted
by silicus
on Stack Overflow
See other posts from Stack Overflow
or by silicus
Published on 2010-04-29T05:50:13Z
Indexed on
2010/04/29
5:57 UTC
Read the original article
Hit count: 192
Hello,
I'm developing a 2D sidescrolling game and I need to optimize my tiling code to get a better frame rate. As of right now I'm using a texture atlas and 16x16 tiles for 480x320 screen resolution. The level scrolls in both directions, and is significantly larger than 1 screen (thousands of pixels). I use glTranslate for the actual scrolling.
So far I've tried:
- Drawing only the on-screen tiles using glTriangles, 2 per square tile (too much overhead)
Drawing the entire map as a Display List (great on a small level, way to slow on a large one)
Partitioning the map into Display Lists half the size of the screen, then culling display lists (still slows down for 2-directional scrolling, overdraw is not efficient)
Any advice is appreciated, but in particular I'm wondering:
- I've seen Vertex Arrays/VBOs suggested for this because they're dynamic. What's the best way to take advantage of this? If I simply keep 1 screen of vertices plus a bit of overdraw, I'd have to recopy the array every few frames to account for the change in relative coordinates (shift everything over and add the new rows/columns). If I use more overdraw this doesn't seem like a big win; it's like the half-screen display list idea.
- Does glScissor give any gain if used on a bunch of small tiles like this, be it a display list or a vertex array/VBO
- Would it be better just to build the level out of large textures and then use glScissor? Would losing the memory saving of tiling be an issue for mobile development if I do this (just curious, I'm currently on a PC)? This approach was mentioned here
Thanks :)
© Stack Overflow or respective owner