Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL buffer update
    primarykey
    data
    text
    <p>Currently I'm writing a program that simulates water. Here are the steps that I do:</p> <ol> <li>Create water surface - plane.</li> <li>Create VAO</li> <li>Create vertex buffer object in which I store normals and vertices.</li> <li>Bind pointers to this VBO.</li> <li>Create index buffer object.</li> </ol> <p>Then I render this plane using glDrawElements and then I invoke an update() function which changes positions of vertices of water surface. After that I invoke glBufferSubData function to update vertices positions.</p> <p>When I do that - nothing happens as if the buffer isn't changed.</p> <p>Here's the code snippet:</p> <pre><code>glGenBuffers(1, &amp;vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(Oscillator) * nOscillators, oscillators, GL_DYNAMIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Oscillator), 0); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Oscillator), (const GLvoid*)12); glEnableVertexAttribArray(0); // Vertex position glEnableVertexAttribArray(2); // normals position glGenBuffers(1, &amp;indicesBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * nIndices, indices, GL_DYNAMIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer); glBindVertexArray(0); </code></pre> <p>Then render:</p> <pre><code>glBindVertexArray(vaoHandle); glDrawElements(GL_TRIANGLES, nIndices, GL_UNSIGNED_INT, 0); update(time); </code></pre> <p>And update function:</p> <pre><code>//some calculations glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Oscillator) * nOscillators, oscillators); </code></pre> <p><b><i>Oscillator</i></b> - it's a structure that has: 8 floats respectively - x, y, z (vertex position), nx, ny, nz (normals), upSpeed, newY</p> <p><b><i>oscillators</i></b> - this is an array of Oscillator structures.</p> <p>What I do wrong?</p>
    singulars
    1. This table or related slice is empty.
    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