OpenGL texture mapping with texCoordArray

This is a discussion on OpenGL texture mapping with texCoordArray within the Game Programming forums, part of the General Programming Boards category; So I'm trying to work out how texture mapping with a texture coordinate array works, but whatever I seem to ...

  1. #1
    Registered User nempo's Avatar
    Join Date
    Aug 2007
    Posts
    39

    Question OpenGL texture mapping with texCoordArray

    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.

  2. #2
    Registered User nempo's Avatar
    Join Date
    Aug 2007
    Posts
    39
    I apparently some way along the way made the assumption that GL_RGB mapped to '3', which it obviously didn't, so instead of the 'bytesperpixel', I just had to use GL_RGB instead.

    Must take note about checking for returned error codes in the future.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Texture mapping anomaly opengl
    By Shakti in forum Game Programming
    Replies: 1
    Last Post: 04-11-2009, 02:09 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. Texture mapping in OpenGL
    By Dragon in forum Game Programming
    Replies: 5
    Last Post: 10-19-2003, 09:47 AM
  4. Texture mapping in OpenGL
    By Mithoric in forum Game Programming
    Replies: 3
    Last Post: 09-12-2003, 09:03 AM
  5. OpenGL texture mapping problems.
    By KnightSword in forum Game Programming
    Replies: 2
    Last Post: 07-12-2002, 10:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21