Note that there are some explanatory texts on larger screens.

plurals
  1. POGLSL : Vertices are missing
    text
    copied!<p>When I use immediate mode, it draws correctly but when i pass the same vertices to the GPU, or even point them, it doesn't work.</p> <p>there is a position buffer holding vertices :</p> <pre><code>std::vector&lt;glm::vec3&gt; posbuf; </code></pre> <p>and indices for it.</p> <p>immediate mode :</p> <pre><code>for (unsigned int i =0; i &lt; indices.size(); i++) { glBegin(GL_TRIANGLES); glVertex3f(posbuf[indices[i].index[0]].x, posbuf[indices[i].index[0]].y, posbuf[indices[i].index[0]].z); glVertex3f(posbuf[indices[i].index[1]].x, posbuf[indices[i].index[1]].y, posbuf[indices[i].index[1]].z); glVertex3f(posbuf[indices[i].index[2]].x, posbuf[indices[i].index[2]].y, posbuf[indices[i].index[2]].z); glEnd(); } </code></pre> <p>and this is the vertex attribute code :</p> <pre><code>glEnableVertexAttribArray(GL_ATTRIB_POS); glVertexAttribPointer(GL_ATTRIB_POS, 3, GL_FLOAT, GL_FALSE, 0,&amp;posbuf[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indVBO); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDisableVertexAttribArray(GL_ATTRIB_POS); </code></pre> <p>and a shader for it :</p> <pre><code>#version 120 attribute vec3 position; void main() { vec4 finalv=vec4(position, 1.0); gl_Position = gl_ModelViewProjectionMatrix * vec4(finalv.xyz,1.0); } [frag] #version 120 void main() { gl_FragColor = vec4(1.0,0.0,0.0,1.0); } </code></pre> <p>immediate result : <img src="https://i.stack.imgur.com/HoTbX.png" alt="enter image description here"></p> <p>shader result: <img src="https://i.stack.imgur.com/BPUdc.png" alt="enter image description here"></p> <p>I don't know what's wrong, i also tried to pass posbuf using glm::value_ptr, they all give the same result. I am on fedora 18, supporting glsl up to #version 140, opengl 3.3. </p> <p>EDIT :</p> <pre><code>glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indVBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Triangle) * indices.size(), &amp;indices[0], GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); struct Triangle { int index[3]; }; </code></pre>
 

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