Jump to content

  • Log In with Google      Sign In   
  • Create Account


problem with glDrawElements and 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.

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

#1 bradbobak   Members   -  Reputation: 1003

Like
0Likes
Like

Posted 14 February 2013 - 12:37 AM

 Hi. I'm having a problem getting glDrawElements working right with a vbo and index buffer.

 

 Heres the render code: (error checking omitted for brevity).

 

// ... load shaders and program
 
GLfloat verts[] = ( 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0 };
GLushort idx[] = ( 0, 1, 2 };
 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
GLuint v1, v2;
glGenBuffers(1, &v1);
glBindBuffer(GL_ARRAY_BUFFER, v1);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 9, verts, GL_STATIC_DRAW);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, 0);
glEnableVertexAttribArray(1);
 
glGenBuffers(1, &v2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, v2);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * 3, idx, GL_STATIC_DRAW);
 
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, 0);
 
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 
glDisableVertexAttribArray(1);
glDeleteBuffers(1, &v1);
glDeleteBuffers(1, &v2);

 

Vertex shader:

#version 330
 
layout (location = 1) in vec3 position;
 
uniform mat4 from_identity = mat4(1.0); // identity for now, this will change
 
void main()
{
  gl_Position = from_identity * vec4(position, 0);
}

 

Frag shader:

#version 330
 
void main()
{
  gl_FragColor = vec4(0.5, 1, 0, 0.5);
}

 

 This renders nothing.

 

 If I change the vertex shader to "gl_Position = gl_Vertex;" and draw the triangle with the old stuff (glBegin(GL_TRIANGLES); ...; glEnd();) it draws fine.

 

 Any suggestions?

 

 

 

 

 

 



Sponsor:

#2 Sponji   Members   -  Reputation: 1125

Like
0Likes
Like

Posted 14 February 2013 - 01:16 AM

For positions, w should be 1 instead of 0.


Derp

#3 bradbobak   Members   -  Reputation: 1003

Like
0Likes
Like

Posted 14 February 2013 - 03:06 AM

 I've found the problem. I was using glX rather than glut, and wasn't creating an opengl 3 context (was just using the old-style context) with glX.






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