iDevGames Forums
OpenGL ES Scrolling Background - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: OpenGL ES Scrolling Background (/thread-2256.html)

OpenGL ES Scrolling Background - abdm436 - Oct 20, 2008 05:06 PM


I'm trying to make a scrolling background using the Texture2D class. I assuming the best way to do this is to create an image that is like 4800 pixels and then just use coordinates to just load part of the picture and keep shifting the coordinates every x time period to shift the image. Is there a better way?

The Texture2D class seems to be limiting the file to 1024 pixels (kMaxTextureSize), can you change that? When I load my file of 4800 it ends up really blurry.


OpenGL ES Scrolling Background - arekkusu - Oct 20, 2008 10:33 PM

The best way to do this depends on what you want to do.

Is your background one giant unique image, or built out of tiles?
Will the background only scroll in integral pixel amounts, or do you want to support rotating/zooming/subpixel scrolling?

Whatever you want to do, you need to work within the hardware limits.

OpenGL ES Scrolling Background - abdm436 - Oct 21, 2008 04:57 AM

The background is currently one big image, do I need to chop it up?


OpenGL ES Scrolling Background - Bachus - Oct 21, 2008 06:43 AM

Assuming "glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);" is accurate, the max texture size on the iPhone is 1024x1024. If you want larger than that you'll need multiple textures, or a tiling/repeating texture.

OpenGL ES Scrolling Background - abdm436 - Oct 21, 2008 06:45 AM

Thanks for the reply, so I've cut it up into multiple textures, but now I'm having a tough time getting them lined up. Can someone help me understand the following two methods:


I'm trying to find some picture that will help me understand what the coordinates should be. I'm using GL_TRIANGLE_STRIP


OpenGL ES Scrolling Background - AnotherJake - Oct 21, 2008 09:30 AM

Bachus Wrote:... the max texture size on the iPhone is 1024x1024.

Yes, it actually says that in the iPhone programming guide.

@abdm436: glTexCoordPointer is used to tell OpenGL where to find the array of texture coordinates for the object you are about to draw. You will also need at least glVertexPointer specified as well which does the same thing for your array of vertex coordinates. Plus you'll need to make sure you've glEnableClientState(GL_VERTEX_ARRAY); and glEnableClientState(GL_TEXTURE_COORD_ARRAY); once before drawing. Plus you need to glBindTexture to specify which texture to use, and glEnable(GL_TEXTURE_2D) to turn on texturing. Then you can do your transforms and call glDrawArrays, which takes the vertex and texCoord arrays you specified with glVertexPointer and glTexCoordPointer, and draws an object with them.