Skip to main content
gamedev.net
🔒 Locked

indice problem

Started by Asem 0 replies 950+ views
Original Post
Asem
Asem
I'm doing a simple plane using vbo's to make sure I understand vbo's but I've run into a problem. It's just to be clear of vbo's for myself. I'm trying to do a simple plane that is divided n times. I store the vertices into a stl vector. I then store the indices into a stl vector that I generate through a for loop. It works but for some reason when I have too many indices the plane screws up and the plane will not look right.


struct Vertex
{
    void setXYZ(float x_ = 0.0f, float y_ = 0.0f, float z_ = 0.0f){v[0]=x_; v[1]=y_; v[2]=z_;}
    float v[3];
};

vector<Vertex> vList; //Array Of Vertices
vector<unsigned short> iList; //Array Of Indices

void drawPlaneInit()
{
    //Push 48 vertices into vList and set position.
    //simple 2d like plane
    Vertex vert;
    for(int i=0; i<6; i++)
    {
        for(int j=0; j<8; j++)
        {
            vert.setXYZ(j, i, 0.0f);
            vList.push_back(vert);
        }
    }


    //create the indices needed to form the triangles

    //Problem: Everything looks okay until I set the loop to stop before 25.    
    //The plane would look like it's broken in parts unless it less than 25. I've 
    //printed iList to the console to confirm that the indices should be correct 
    //(which they are).

    unsigned short it=0;
    for(unsigned int i=0; i<24; i++)
    {
        if(it == 7)
        {   it = 0;
            continue;
        }
        else
        {
            //1 square is triangle 1 and 2
            //Triangle 1
            iList.push_back(i+1);
            iList.push_back(i+8);
            iList.push_back(i);

            //Triangle 2
            iList.push_back(i+1);
            iList.push_back(i+9);
            iList.push_back(i+8);

            it++;
        }
    }

    glGenBuffersARB(1, &vBuf);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vBuf);

    glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(Vertex)*vList.size(), &(*vList.begin()), GL_STATIC_DRAW_ARB);
    glVertexPointer(3, GL_FLOAT, 0, 0);

    glGenBuffersARB(1, &eBuf);
    glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, eBuf);

    glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(unsigned short)*iList.size(), &(*iList.begin()) , GL_STATIC_DRAW_ARB);

}

//Then Draw blah blah...




Everything is arb since unfortunately at the moment I'm relying on an intel gpu that only supports ogl 1.4 somewhat 1.5 for now. example of i<24 when creating the indices for iList your_link_text example of i<25 or higher when creating the indices for iList. your_link_text hopefully this is clear. [Edited by - Asem on January 7, 2009 12:03:35 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.