Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL can't send attribute data to shader
    primarykey
    data
    text
    <p>I'm able to render a VBO with vertices but when I try adding in colours (using shader attributes) nothing shows up. What am I doing wrong here? I can find a lot of online examples showing this working for interleaved VBO's, but I'd rather use this method (serialized array) instead. Any ideas? </p> <p>Buffer Generation &amp; Allocation</p> <pre><code>glGenVertexArrays( 1, &amp;vao ); glBindVertexArray( vao ); glGenBuffers( 1, &amp;vbo ); glBindBuffer( GL_ARRAY_BUFFER, vbo ); glBufferData( GL_ARRAY_BUFFER, ( vertices.size() + colors.size() ) * sizeof(float), NULL, GL_STATIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0, vertices.size() * sizeof(vertices[0]), vertices.data() ); glBufferSubData( GL_ARRAY_BUFFER, vertices.size() * sizeof(vertices[0]), colors.size() * sizeof(colors[0]), colors.data() ); /* HERE if I replace the lower block with this top portion, things show up fine glEnableClientState( GL_VERTEX_ARRAY ); glVertexPointer( 3, GL_FLOAT, 0, (void*)0); */ glEnableVertexAttribArray( 0 ); glEnableVertexAttribArray( 1 ); glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, 0 ); glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertices.size() * sizeof(GLfloat)) ); glGenBuffers( 1, &amp;ibo ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ibo ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, faces.size() * sizeof(GLushort), faces.data(), GL_STATIC_DRAW ); </code></pre> <p>Drawing here</p> <pre><code>glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClearDepth( 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glUseProgram( gl ); glBindVertexArray( vao ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ibo ); glDrawElements( GL_TRIANGLE_FAN, faces.size(), GL_UNSIGNED_SHORT, (void*)0 ); glutSwapBuffers(); glutPostRedisplay(); </code></pre> <p>vert shader</p> <pre><code>#version 130 layout (location = 0 ) in vec3 in_Position; layout (location = 1 ) in vec3 in_Color; out vec3 out_Color; void main() { out_Color = in_Color; gl_Position = vec4(in_Position,1.0); } </code></pre> <p>frag shader</p> <pre><code>#version 130 in vec3 out_Color; void main() { gl_FragColor = vec4(out_Color, 1.0); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload