Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Simple Vertex Buffer/Array Object question.


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
No replies to this topic

#1 Syerjchep   Members   -  Reputation: 180

Like
0Likes
Like

Posted 16 February 2013 - 12:39 PM

So I'm trying to make two seperate objects and render them in a rendering loop.

This is the code after the initilization that creates them:

 

    glGenVertexArrays(1, &vaoHandle1);
    glBindVertexArray(vaoHandle1);
    glGenBuffers(1, &vertexbuffer1);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer1);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL);
    glGenBuffers(1, &colorbuffer1);
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, colorbuffer1);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data),g_color_buffer_data, GL_STATIC_DRAW);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL);
 
    glGenVertexArrays(1, &vaoHandle2);
    glBindVertexArray(vaoHandle2);
    glGenBuffers(1, &vertexbuffer2);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer2);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data2), g_vertex_buffer_data2, GL_STATIC_DRAW);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL);
    glGenBuffers(1, &colorbuffer2);
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, colorbuffer2);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data),g_color_buffer_data, GL_STATIC_DRAW);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL);

For reference here are the actual vertex arrays:

http://pastebin.com/fCTC7Hsn

 

And this is my main rendering loop:

 

 
void renderCallback()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glUseProgram(programID);
    glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
 
    glBindVertexArray(vaoHandle1);
    glDrawArrays(GL_TRIANGLES, 0, 12*3);
    glBindVertexArray(vaoHandle2);
    glDrawArrays(GL_TRIANGLES, 0, 12*3);
    glBindVertexArray(0);
 
    glutSwapBuffers();
    glutPostRedisplay();
 
    frames++;
}

This worked when I was only rendering one object, but after I modifyed it, it screwed everything up.

Unfortunatly there aren't a lot of opengl tutorials out there that deal with versions 3 and 4.

And of those, I haven't found one that explains how to render more than one object (VBO/VAO) in the same program, which is obviously essential.


Edited by Syerjchep, 16 February 2013 - 12:43 PM.


Sponsor:



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