I've been forced over to OpenGL due to not getting enough performance using the 2D API, and I'm a bit at a loss. I've had a look at several examples and much code, like NeHe, Replica Island and Rokon. Another example I've been looking at is OpenGL tiling. I've figured out how to draw (probably not optimized) and add textures in a very basic way I suppose. One thing I haven't been able to figure out so far is how to crop the texture instead of resizing it.
My hands on example is:
I've got a large "map", background of the whole game level. I build it up from background tiles drawing on a Bitmap through a Canvas:
The whole thing is persistent during the game so drawing every tile individually seems like a big waste, so I figure this way is a sane route to walk down. This large bitmap gives me a bit of headache though:
1. It's very likely to not be a POW 2, can I still load it up with GLUtils.texImage2D?
2. How to only draw the visible part of it? What I've tried (with small images only) is to load them into IntBuffers, together with an Intbuffer of squares then do
gl.glVertexPointer(2, GL10.GL_FIXED, 0, mVertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, mTextureBuffer);
gl.glColor4f(1, 1, 1, 1);
for (int i = 0; i < yTiles*xTiles*8; i += 4) // 8 being 4 pairs of x,y for a square
gl.glNormal3f(0, 0, 0);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i, 4);
If the vertexes are larger than the texture will it stretch, and shrink the texture if it's small. I suppose this will be the case with my map too? If I make a square covering the full screen will it shrink my map to fit, how to prevent that?
3. In general, is it possible and practical to have several layers on the screen? In my case am I thinking one for the map, which only changes if there is a scroll event, one which I draw sprites of the player/other things moving around (updated very often) and one with explosions. In my mind would that make things more optimized, I'd only need to redraw the layer having a change. My plan was to have the game 3D with background furthest back and only clear the depth of what's needed. Or is this just wishful thinking?
Sorry for the length and I'd really appreciate if someone could shed some light on these problems for me.