So I'm trying to work out how texture mapping with a texture coordinate array works, but whatever I seem to do I only get a white quad instead of a textured quad.
This is a modified texture mapping example I found on the net, but using vertex and texCoord pointers instead of glTexCoord2f and glVertex3f and whatnot.
Anyway, here's the relevent sections of the code:
variables:
Code:
double vertexArray[] = { -0.75, -0.75, -6,
0.75, -0.75, -6,
0.75, 0.75, -6,
-0.75, 0.75, -6 };
double colorArray[] = { 1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 1.0, 0.0 };
double texCoordArray[] = { 0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0 };
(somewhat messy) Code that is suppose to render the quad.
Code:
void DrawAQuad() {
glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1., 1., -1., 1., 1., 20.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);
glClientActiveTexture(textureID);
glVertexPointer(3, GL_DOUBLE, 0, vertexArray);
//glColorPointer(3, GL_DOUBLE, 0, colorArray);
glTexCoordPointer(2, GL_DOUBLE, 0, texCoordArray);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
//glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Code used to upload the texture data:
Code:
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, bytesperpixel, width, height, 0, bytesperpixel, GL_UNSIGNED_BYTE, imageData);
imageData is an array with unsigned char's containing data for a 256x256 map loaded from a uncompressed, unmapped TGA, basically just an ordinary bitmap.
So, the big question, what am I doing wrong? As stated, all I get is a white quad.