Jump to content

  • Log In with Google      Sign In   
  • Create Account

Troubles with glEnableVertexAttribArray


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

#1 Cucus   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 May 2011 - 01:21 PM

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;
glGenBuffers(1,&vertexs);
glBindBuffer(GL_ARRAY_BUFFER,vertexs);
glBufferData(GL_ARRAY_BUFFER,sizeVertex*sizeof(GLfloat),vertexArray,GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

the render function:
void Joint::render(){ glDrawArrays(GL_TRIANGLES,0,sizeVertex);}

Can you see a problem? Thanks


Sponsor:

#2 ShadowKyuzo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 17 May 2011 - 05:04 PM

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;
glGenBuffers(1,&vertexs);
glBindBuffer(GL_ARRAY_BUFFER,vertexs);
glBufferData(GL_ARRAY_BUFFER,sizeVertex*sizeof(GLfloat),vertexArray,GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

the render function:
void Joint::render(){ glDrawArrays(GL_TRIANGLES,0,sizeVertex);}

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




#3 V-man   Members   -  Reputation: 809

Like
0Likes
Like

Posted 17 May 2011 - 09:45 PM

Maybe you didn't setup your shader correctly.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#4 Riztro   Members   -  Reputation: 240

Like
0Likes
Like

Posted 17 May 2011 - 10:35 PM

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




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