Jump to content
  • Advertisement
Sign in to follow this  
Cucus

OpenGL Troubles with glEnableVertexAttribArray

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

Hi,

I'm trying to render a robot which has 7 joints. Each joint is an object called "Joint". I load the vertices correctly but I don't know why I can just see the first joint. I new in openGL so I don't understand very well if my calls are correct or not and the reason why...

Here you can check my code:

vertexArray is the array where I put my vertexs points previously.
GLuint vertexs[color="#000000"];
glGenBuffers[color="#000000"]([color="#000080"]1[color="#000000"],&vertexs[color="#000000"]);
glBindBuffer[color="#000000"](GL_ARRAY_BUFFER[color="#000000"],vertexs[color="#000000"]);
glBufferData[color="#000000"](GL_ARRAY_BUFFER[color="#000000"],sizeVertex[color="#000000"]*[color="#808000"]sizeof[color="#000000"](GLfloat[color="#000000"]),vertexArray[color="#000000"],GL_DYNAMIC_DRAW[color="#000000"]);
glEnableVertexAttribArray[color="#000000"]([color="#000080"]0[color="#000000"]);
glVertexAttribPointer[color="#000000"]([color="#000080"]0[color="#000000"], [color="#000080"]3[color="#000000"], GL_FLOAT[color="#000000"], GL_FALSE[color="#000000"], [color="#000080"]0[color="#000000"], [color="#000080"]0[color="#000000"]);

the render function:
[color="#808000"]void Joint[color="#000000"]::render[color="#000000"]()[color="#000000"]{ glDrawArrays[color="#000000"](GL_TRIANGLES[color="#000000"],[color="#000080"]0[color="#000000"],sizeVertex[color="#000000"]);}

Can you see a problem? Thanks

Share this post


Link to post
Share on other sites
Advertisement

Hi,

I'm trying to render a robot which has 7 joints. Each joint is an object called "Joint". I load the vertices correctly but I don't know why I can just see the first joint. I new in openGL so I don't understand very well if my calls are correct or not and the reason why...

Here you can check my code:

vertexArray is the array where I put my vertexs points previously.
GLuint vertexs[color="#000000"];
glGenBuffers[color="#000000"]([color="#000080"]1[color="#000000"],&vertexs[color="#000000"]);
glBindBuffer[color="#000000"](GL_ARRAY_BUFFER[color="#000000"],vertexs[color="#000000"]);
glBufferData[color="#000000"](GL_ARRAY_BUFFER[color="#000000"],sizeVertex[color="#000000"]*[color="#808000"]sizeof[color="#000000"](GLfloat[color="#000000"]),vertexArray[color="#000000"],GL_DYNAMIC_DRAW[color="#000000"]);
glEnableVertexAttribArray[color="#000000"]([color="#000080"]0[color="#000000"]);
glVertexAttribPointer[color="#000000"]([color="#000080"]0[color="#000000"], [color="#000080"]3[color="#000000"], GL_FLOAT[color="#000000"], GL_FALSE[color="#000000"], [color="#000080"]0[color="#000000"], [color="#000080"]0[color="#000000"]);

the render function:
[color="#808000"]void Joint[color="#000000"]::render[color="#000000"]()[color="#000000"]{ glDrawArrays[color="#000000"](GL_TRIANGLES[color="#000000"],[color="#000080"]0[color="#000000"],sizeVertex[color="#000000"]);}

Can you see a problem? Thanks



I can see one problem with your code:

On the call to glDrawArrays, the last parameter is the number of indices you want to render (in this case, the number of triangles), not the total size of the vertex array.
Assuming that on vertexArray, you store your vertices in the form x, y, z, x, y, z, etc,...
and sizeVertex is the size of this array you should pass ( sizeVertex / 3 ) to glDrawArrays.

Other than that, it's hard to tell why is not working, can you post more code?

ps: someone correct me if i'm wrong, im still kinda new to opengl and etc :P


Share this post


Link to post
Share on other sites
Did you rebind the buffer before you drew? It also seems like you didn't call the program with the shader before you drew..

Also are you planning on moving the robot? If so where did you learn how to move it? I am trying to figure out how to move stuff with vbo's

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!