Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, OpenGL does not really have a "camera". What it has is a transformation pipeline (either fixed function, or programmable). Also OpenGL does not maintain a "scene" but just draws points, lines and triangles to a framebuffer, one at a time.</p> <p>Once you've wrapped your mind around the fact, that you're essentially not a very different thing like using any other drawing API (<code>goTo(x,y); lineTo(x,y);</code> or similar) a lot of things in OpenGL make a lot more sense.</p> <p>So a "camera" in OpenGL is merely a viewing transformation applied at some point in the vertex transformation pipeline. Usually as the last transformation in the modelview matrix – model transformation followed by view transformation, hence model-view.</p> <p>There are many ways to specify the view transformation, and a typical helper function often used for this is <code>gluLookAt</code>. Since transformations are applied in the opposite order they're multiplied onto a matrix (if OpenGL's glMultMatrix or one of the built in matrix manipulation functions is used, at least) the viewing transformation comes first, when defining the modelview matrix. So in your drawing function the code usually looks like</p> <pre><code>glMatrixMode(GL_MODELVIEW) glLoadMatrix(view.transformation) # same as glLoadIdentity(); glMultMatrix(view.transformation) foreach(object o in objects): glMatrixMode(GL_MODELVIEW) glPushMatrix() glMultMatrix(o.transformation) o.draw() glMatrixMode(GL_MODELVIEW) glPopMatrix() </code></pre> <p>Did you notice how I always make sure I'm in the right matrix mode before each matrix manipulation? That's because object::draw may switch to another matrix mode (like say GL_TEXTURE), and switching matrix modes has only neglectible cost, so you should always do it, before a sequence of matrix manipulations.</p> <p>As a further hint: You should always place your code for setting viewport and the projection matrix at the beginning of the drawing code. <em>Do not</em> place it in a window's resize event handler.</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