Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Okay, here it goes again: ^1</em></p> <blockquote> <p>OpenGL is not a scene graph. OpenGL does not maintain a scene, knows about objects or keeps tracks of geometry. OpenGL is a <em>drawing</em> API. You give it a canvas (in form of a Window or a PBuffer) and order it to draw points, lines or triangles and OpenGL does exactly that. Once a primitive (=point, line, triangle) has been drawn, OpenGL has no recollection about it whatsoever. If something changes, you have to redraw the whole thing.</p> </blockquote> <p>The proper steps to redraw a scene are:</p> <ol> <li><p>Disable the stencil test, so that the following step operates on the whole window.</p></li> <li><p>Clear the framebuffer using <code>glClear(bits)</code>, where <em>bits</em> is a bitmask specifying which parts of the canvas to clear. When rendering a new frame you want to clear everything so <code>bits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT</code>;</p></li> <li><p>set the viewport, build an apropriate projection matrix</p></li> <li><p>for each object in the scene load the right modelview matrix, set uniforms, select the vertex arrays and make the drawing call.</p></li> <li><p>finish the rendering by flushing the pipeline. If using a single buffered window <code>glFinish()</code>, if using a double buffered window call <code>SwapBuffers</code>. In case of higher level frameworks this may be performed by the framework.</p></li> </ol> <p><strong>Important</strong> Once the drawing has been finished on a double buffered window, you must not continue to send drawing operations, as by performing the buffer swap the contents of the back buffer you're drawing to are undefined. Hence you must start the drawing anew, beginning with clearing the framebuffer (steps 1 and 2).</p> <p>What your code misses are exactly those two steps. Also I have the impression that you're performing OpenGL drawing calls in direct reaction to input events, possibly in the input event handlers themself. <em>Don't do this!</em>. Instead use the input events to add to a list of primitives (lines in your case) to draw, then send a redraw event, which makes the framework call the drawing function. In the drawing function iterate over that list to draw the desired lines.</p> <p><strong>Redrawing the whole scene is canonical in OpenGL!</strong></p> <hr> <p><em>[1] (geesh, I'm getting tired of having to write this every 3rd question or so…)</em></p>
 

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