Jump to content
  • Advertisement
Sign in to follow this  
Dougie

Another glDrawElements thread

This topic is 5409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I'm trying to use glDrawElements to replace the calls in between the /* */ comment tags. However, my replacement code don't work; I end up with a blank screen, were there should be a multicoloured square. I'm using SDL to control the windows, etc.
static const Uint8      Indice[] = { 0, 1, 2, 3};
    static const GLfloat    Vertice[] = { -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 
                                             -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f };
    static const GLfloat    Colours[] = {1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 
                                            1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f };

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    PerformCameraTransform();
    
    /*
    glBegin(GL_TRIANGLE_STRIP);

    glColor3f(Colours[0], Colours[1], Colours[2]);
    glVertex3f(Vertice[0], Vertice[1], Vertice[2]);

    glColor3f(Colours[3], Colours[4], Colours[5]);
    glVertex3f(Vertice[3], Vertice[4], Vertice[5]);

    glColor3f(Colours[6], Colours[7], Colours[8]);
    glVertex3f(Vertice[6], Vertice[7], Vertice[8]);

    glColor3f(Colours[9], Colours[10], Colours[11]);
    glVertex3f(Vertice[9], Vertice[10], Vertice[11]);

    glEnd();

    glLoadIdentity();
    */
    
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_INDEX_ARRAY_POINTER);
    glIndexPointer(GL_FLOAT, 0, Colours);
    glVertexPointer(3, GL_FLOAT, 0, Vertice);
    glDrawElements(GL_TRIANGLE_STRIP, 2, GL_UNSIGNED_BYTE, Indice);

    glLoadIdentity();

    SDL_GL_SwapBuffers();

Btw, I checked the code between the tags and it works

Share this post


Link to post
Share on other sites
Advertisement
The second parameter is the number of indices you want to draw (usually, the number of indices in the index array). You're only drawing 2 vertices, but a triangle needs atleast 3 to form a complete triangle. 4 is the correct value in this case.

And why are you using the index color array for the RGB color array? You should probably use glColorPointer instead.

Share this post


Link to post
Share on other sites
Ahh, much better now. It now works correctly. The reason why I used glIndexPointer was because of the msdn library statement:

The glIndexPointer function defines an array of color indexes.

Which confused me. Anyway, thanks for your help

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!