Sign in to follow this  

drawing model issue

This topic is 1427 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

The problem I have kinda has to do with glDrawArrays. Basically, if I have a number of vertices that isn't divisible by 3 it won't work. It works based on triangles. I need it to work generically. If I have 4 verts I need it to draw a quad if I have 3 it needs to draw a triangle.

This is my drawModel function right now:
 

 
void Model::drawModel(glm::mat4& v2s_matrix, glm::mat4& w2v_matrix){



    glm::mat4 mvp = v2s_matrix * w2v_matrix * m2w_matrix;

    GLuint mvploc = glGetUniformLocation(data.file_header.shader_program, "mvp");

    glUniformMatrix4fv(mvploc, 1, GL_FALSE, &mvp[0][0]);



    glUseProgram(data.file_header.shader_program);



    for(int x = 0; x < data.file_header.object_count; x++){

        glBindBuffer(GL_ARRAY_BUFFER,vbo_list.at(x));

        if(data.model_object.at(x).object_header.coord_flag != 0){

            glEnableVertexAttribArray(0);

            glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)COORD_OFFSET);

        }



        if(data.model_object.at(x).object_header.color_flag != 0){

            glEnableVertexAttribArray(1);

            glVertexAttribPointer(1,4,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)COLOR_OFFSET);

        }



        glDrawArrays(GL_TRIANGLES,0,data.model_object.at(x).object_header.vertex_count);

        glDisableVertexAttribArray(0);

        glDisableVertexAttribArray(1);

    }



    return;

}
 

I have two basic models. A square and a triangle I am testing. 4 verts and 3 verts. This works for the triangle. For the square, it draws a triangle not including the last point.

Any suggestions would be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites

Use GL_TRIANGLE_STRIP instead of GL_TRIANGLES. This does assume your model data is set up properly for triangle strips, but it probably already is if you're using a library to import the data.

Share this post


Link to post
Share on other sites

This topic is 1427 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this