Results 1 to 3 of 3

Thread: VertexArray glBindTexture not working

  1. #1
    Guest

    VertexArray glBindTexture not working

    Hello, I'm trying to learn how to use vertex arrays, but I must have some error, or there must be something I'm not understanding, because for some reason my little test app is not working as expected.
    Just trying to draw one textured triangle using vertex arrays. If I call glBindTexture() before calling glDrawArrays() or glDrawElements() no texture is shown, but if I omit the texture binding everything works 'right'. Tell me if you see the problem in this implementation:
    Code :
    float vertices[] = { -10.0f, -10.0f, 0.0f, 
                         -10.0f,  10.0f, 0.0f, 
                          10.0f,  10.0f, 0.0f };
     
    float colors[] =   { 1.0f, 1.0f, 0.0f, 
                         1.0f, 1.0f, 1.0f, 
                         1.0f, 1.0f, 1.0f };
     
    float texcoords[] = { 0.0f, 0.0f,
                          1.0f, 0.0f,
                          1.0f, 1.0f };
     
    int indices[] = { 0, 1, 2 };
    in my init function:
    Code :
    LoadJPG( "cool.JPG" );
      glVertexPointer(3, GL_FLOAT, 0, vertices);
      glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
      glColorPointer(3, GL_FLOAT, 0, colors);
     
      glEnableClientState( GL_VERTEX_ARRAY );
      glEnableClientState( GL_TEXTURE_COORD_ARRAY );
      glEnableClientState( GL_COLOR_ARRAY );
    then in my Draw function:
    Code :
    //glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices);
      glBindTexture(GL_TEXTURE_2D, textureID);
      glDrawArrays (GL_TRIANGLES, 0, 3);
    ...and the polygon renders non textured.

    Thank you.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: VertexArray glBindTexture not working

    Where do you cal glGenTextures and glTexImage and everything else that needs to be called? And, does textureID have the same scope?

  3. #3
    Guest

    Re: VertexArray glBindTexture not working

    Yes, its inside the LoadJPG() function. textureID is a global defined variable. The code I'm using to load/display texture is already tested it has not given me any problems (when not using VertexArrays). I don't think that is the problem. Thanks

Similar Threads

  1. Assimp vertexArray problem
    By rgbaboy in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-21-2016, 11:45 AM
  2. VertexArray and VertexAttribArray, what's different?
    By reader1 in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 03-27-2015, 01:38 AM
  3. problem in using glcolorpointer in vertexarray
    By Janani in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-21-2010, 08:09 PM
  4. VertexArray glBindTexture not working.
    By Anonymous Coward in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 05-07-2003, 10:55 AM
  5. A better VertexArray.
    By CS in forum OpenGL: General
    Replies: 11
    Last Post: 11-30-2000, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean