Jump to content

  • Log In with Google      Sign In   
  • Create Account


drawing model issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 meiryousa   Members   -  Reputation: 113

Like
0Likes
Like

Posted 19 February 2014 - 04:36 AM

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.



Sponsor:

#2 Sponji   Members   -  Reputation: 1149

Like
0Likes
Like

Posted 19 February 2014 - 04:51 AM

Just convert quads to triangles when you're loading the model.


Derp

#3 richardurich   Members   -  Reputation: 1187

Like
0Likes
Like

Posted 19 February 2014 - 05:38 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS