Hey all, I have a very basic texture map problem in GL on iPhone, and I'm wondering what strategies there are for debugging this kind of thing.
(Frankly, just staring at state machine calls and wondering if any of them is wrong or misordered is no way to live-- are there tools for this?)
I have a 512x512 PNG file that I'm loading up from disk (not specially packed), creating a CGBitmapContext
, then calling CGContextDrawImage
to get bytes out of it. (This code is essentially stolen from an Apple sample.) I'm trying to map the texture to a "quad", with code that looks essentially like this-- all flat 2D stuff, nothing fancy:
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
GLfloat vertices[8] = {
viewRect.origin.x, viewRect.size.height,
viewRect.origin.x, viewRect.origin.y,
viewRect.size.width, viewRect.origin.y,
viewRect.size.width, viewRect.size.height
};
GLfloat texCoords[8] = {
0, 1.0,
0, 0,
1.0, 0,
1.0, 1.0
};
glBindTexture(GL_TEXTURE_2D, myTextureRef); // This was previously bound to
glVertexPointer(2, GL_FLOAT , 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
- My supposedly textured area comes out just black.
- I see no debug output from the CG calls to set up the texture.
glGetError
reports nothing.- If I simplify this code block to just draw the verts, but set up a pure color, the quad area lights up exactly as expected.
- If I clear the whole context immediately beforehand to red, I don't see the red-- which means something is being rendered there, but not the contents of my PNG.
What could I be doing wrong? And more importantly, what are the right tools and techniques for debugging this sort of thing, because running into this kind of problem and not being able to "step through it" in a debugger in any meaningful way is a bummer.
Thanks!