Note that there are some explanatory texts on larger screens.

plurals
  1. POVBO verses Vertex Array, vertex normals issue in VBO
    primarykey
    data
    text
    <p>I don't know what's wrong here, everything is working fine except normals. When I use vertex array, model looks perfect but when I switch to VBO, model looks worse because of vertex normals. I spent a lot of time to fix it but do not know what's wrong. VBO generation seems perfect. but still do not know. any idea?</p> <pre><code>#define BUFFER_OFFSET(i) ((char *)NULL + (i)) void InitVBO(){ glGenBuffers(1, &amp;vboNormID); glBindBuffer(GL_ARRAY_BUFFER, vboNormID); glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, VertNormals); glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12)); glGenBuffers(1, &amp;vboVertID); glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, p_VERTICES); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0)); glGenBuffers(1, &amp;indexVBOID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(GLFace)*nb_Faces, p_indices); //glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, p_indices, GL_DYNAMIC_DRAW);} </code></pre> <p>Rendering code is followed. VBO + Vertex Array Vertex array is working perfect. I can see the perfect shape of model with vertex normals, but with VBO there is some issue with vertex normals. I think I am doing something wrong with BUFFER_OFFSET(12).</p> <pre><code>void RenderTringularModel(GLvoid){ if(VertNormals &amp;&amp; !MESH_SMOOTH) { glBindBuffer(GL_ARRAY_BUFFER, vboNormID); glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12)); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0)); glDrawElements(GL_TRIANGLES, nb_Faces*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glPopClientAttrib(); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } else { //glShadeModel (GL_FLAT); glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), p_VERTICES); glNormalPointer(GL_FLOAT, sizeof(GLpoint), VertNormals); glDrawElements(GL_TRIANGLES, 3*nb_Faces, GL_UNSIGNED_INT, p_indices); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glPopClientAttrib(); } </code></pre> <p>}</p> <p><strong>UPDATE 1:</strong> I think you are talking about InitVBO.. I was wrong at that point. How about this...But it is also not working.. actually the issue it.. in many ways i tried to bind the vertex normals in InitVBO().. but result comes the same every time.</p> <pre><code> glGenBuffers(1, &amp;vboVertID); glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, p_VERTICES); glBufferSubData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, sizeof(GLpoint)*nb_Vertices, VertNormals); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0)); glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12)); </code></pre> <p><strong>Update 2:</strong> Ok ... i don't bind the vertex normals (vboNormID). I am discarding it. is it ok now ? Now it should work.. Actually i have done everything in that way.. to bind the vertex normals with vboVertID and with vboNormID etc etc.. but not every single mathod is working.. give me any suggestion by analyzing this code.</p> <pre><code> void RenderTringularModel(GLvoid){ if(VertNormals &amp;&amp; !MESH_SMOOTH) { glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12)); glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0)); glDrawElements(GL_TRIANGLES, nb_Faces*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); </code></pre> <p><strong>Update 3:</strong></p> <p>I don't know who told me to use BUFFER_OFFSET()... just crap.. I have fixed it now, now working fine without this stupid BUFFER_OFFSET().. Now the fixed code it really simple as follows:</p> <pre><code>void InitVBO(){ glGenBuffers(1, &amp;vboVertID); glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, p_VERTICES, GL_DYNAMIC_DRAW); glGenBuffers(1, &amp;vboNormID); glBindBuffer(GL_ARRAY_BUFFER, vboNormID); glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, VertNormals, GL_DYNAMIC_DRAW); glGenBuffers(1, &amp;indexVBOID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, p_indices, GL_DYNAMIC_DRAW);} void RenderTringularModel(GLpoint *P, GLpoint *Vn, GLFace *T, int nbF){ glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, vboVertID); glVertexPointer(3, GL_FLOAT, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, vboNormID); glNormalPointer(GL_FLOAT, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glDrawElements(GL_TRIANGLES, nb_Faces*3, GL_UNSIGNED_INT, 0); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glPopClientAttrib();} </code></pre> <p>Now guys kindly guide me how can I update these buffers in real-time. I mean to say I need to update the whole data in real-time, normals, vertices, triangles. for example: after subdivision of triangles, i would need to update the triangles buffer with vertices and normals too.. and another thing is, during cutting simulation of model, i need to update the vertices position and normals, so i would need to update the buffer at that point too.. so tell what do i do for this kind of issue ? how can i make it up ? do i need to delete the buffers and regenerate again ? if yes then how ?</p>
    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.
    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