Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Simple Vertex Buffer/Array Object question.

4: Adsense

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   

212
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.





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.