<p>I'm trying to do a simple rotation in OpenGL but must be missing the point.
I'm not looking for a specific fix so much as a quick explanation or link that explains OpenGL rotation more generally.</p>

<p>At the moment I have code like this:</p>

<pre><code>glPushMatrix();
  glRotatef(90.0, 0.0, 1.0, 0.0);
  glBegin(GL_TRIANGLES);        
    glVertex3f( 1.0, 1.0, 0.0 );        
    glVertex3f( 3.0, 2.0, 0.0 );        
    glVertex3f( 3.0, 1.0, 0.0 );        
  glEnd();
glPopMatrix();
</code></pre>

<p>But the result is not a triangle rotated 90 degrees.</p>

<p><strong>Edit</strong>
Hmm thanks to Mike Haboustak - it appeared my code was calling a SetCamera function that use glOrtho.  I'm too new to OpenGL to have any idea of what this meant but disabling this and rotating in the Z-axis produced the desired result. </p>

[{'answer_id': 23925, 'author': 'spate', 'author_id': 2276, 'author_profile': 'https://Stackoverflow.com/users/2276', 'pm_score': 3, 'selected': False, 'text': "<p>Ensure that you're modifying the modelview matrix by putting the following before the glRotatef call:</p>\n\n<pre><code>glMatrixMode(GL_MODELVIEW);\n</code></pre>\n\n<p>Otherwise, you may be modifying either the projection or a texture matrix instead.</p>\n"}, {'answer_id': 23926, 'author': 'Mike Haboustak', 'author_id': 2146, 'author_profile': 'https://Stackoverflow.com/users/2146', 'pm_score': 4, 'selected': True, 'text': '<p>Do you get a 1 unit straight line? It seems that 90deg rot. around Y is going to have you looking at the side of a triangle with no depth.</p>\n\n<p>You should try rotating around the Z axis instead and see if you get something that makes more sense. </p>\n\n<p>OpenGL has two matrices related to the display of geometry, the ModelView and the Projection.  Both are applied to coordinates before the data becomes visible on the screen. First the ModelView matrix is applied, transforming the data from model space into view space. Then the Projection matrix is applied with transforms the data from view space for "projection" on your 2D monitor. </p>\n\n<p>ModelView is used to position multiple objects to their locations in the "world", Projection is used to position the objects onto the screen.</p>\n\n<p>Your code seems fine, so I assume from reading the documentation you know what the nature of functions like glPushMatrix() is. If rotating around Z still doesn\'t make sense, verify that you\'re editing the ModelView matrix by calling glMatrixMode.</p>\n'}, {'answer_id': 38800, 'author': 'Ant', 'author_id': 3709, 'author_profile': 'https://Stackoverflow.com/users/3709', 'pm_score': 1, 'selected': False, 'text': '<p>When I had a first look at OpenGL, the <a href="http://nehe.gamedev.net/" rel="nofollow noreferrer">NeHe tutorials</a> (see the left menu) were invaluable.</p>\n'}, {'answer_id': 39212, 'author': 'Adam Hollidge', 'author_id': 4069, 'author_profile': 'https://Stackoverflow.com/users/4069', 'pm_score': 1, 'selected': False, 'text': '<p>I\'d like to recommend a book:</p>\n\n<p><strong><a href="https://rads.stackoverflow.com/amzn/click/com/0521821037" rel="nofollow noreferrer" rel="nofollow noreferrer">3D Computer Graphics : A Mathematical Introduction with OpenGL</a></strong> by Samuel R. Buss</p>\n\n<p>It provides very clear explanations, and the mathematics are widely applicable to non-graphics domains. You\'ll also find a thorough description of orthographic projections vs. perspective transformations.</p>\n'}, {'answer_id': 65788, 'author': 'Adi', 'author_id': 9090, 'author_profile': 'https://Stackoverflow.com/users/9090', 'pm_score': 1, 'selected': False, 'text': '<p>Regarding Projection matrix, you can find a good source to start with here:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/bb147302(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb147302(VS.85).aspx</a></p>\n\n<p>It explains a bit about how to construct one type of projection matrix.  Orthographic projection is the very basic/primitive form of such a matrix and basically what is does is taking 2 of the 3 axes coordinates and project them to the screen (you can still flip axes and scale them but there is no warp or perspective effect).</p>\n\n<p>transformation of matrices is most likely one of the most important things when rendering in 3D and basically involves 3 matrix stages:</p>\n\n<ul>\n<li>Transform1 = Object coordinates system to World (for example - object rotation and scale)</li>\n<li>Transform2 = World coordinates system to Camera (placing the object in the right place)</li>\n<li>Transform3 = Camera coordinates system to Screen space (projecting to screen)</li>\n</ul>\n\n<p>Usually the 3 matrix multiplication result is referred to as the WorldViewProjection matrix (if you ever bump into this term), since it transforms the coordinates from Model space through World, then to Camera and finally to the screen representation.</p>\n\n<p>Have fun</p>\n'}, {'answer_id': 67998, 'author': 'Perry', 'author_id': 10359, 'author_profile': 'https://Stackoverflow.com/users/10359', 'pm_score': 3, 'selected': False, 'text': '<p>The "accepted answer" is not fully correct - rotating around the Z will not help you see this triangle unless you\'ve done some strange things prior to this code.  Removing a glOrtho(...) call might have corrected the problem in this case, but you still have a couple of other issues.</p>\n\n<p>Two major problems with the code as written:</p>\n\n<ul>\n<li><p>Have you positioned the camera previously?  In OpenGL, the camera is located at the origin, looking down the Z axis, with positive Y as up.  In this case, the triangle is being drawn in the same plane as your eye, but up and to the right.  Unless you have a very strange projection matrix, you won\'t see it.  gluLookat() is the easiest command to do this, but any command that moves the current matrix (which should be MODELVIEW) can be made to work.</p></li>\n<li><p>You are drawing the triangle in a left handed, or clockwise method, whereas the default for OpenGL is a right handed, or counterclockwise coordinate system.  This means that, if you are culling backfaces (which you are probably not, but will likely move onto as you get more advanced), you would not see the triangle as expected.  To see the problem, put your right hand in front of your face and, imagining it is in the X-Y plane, move your fingers in the order you draw the vertices (1,1) to (3,2) to (3,1). When you do this, your thumb is facing away from your face, meaning you are looking at the back side of the triangle.  You need to get into the habit of drawing faces in a right handed method, since that is the common way it is done in OpenGL.</p></li>\n</ul>\n\n<p>The best thing I can recommend is to use the NeHe tutorials - <a href="http://nehe.gamedev.net/" rel="noreferrer">http://nehe.gamedev.net/</a>.  They begin by showing you how to set up OpenGL in several systems, move onto drawing triangles, and continue slowly and surely to more advanced topics.  They are very easy to follow. </p>\n'}]
['https://Stackoverflow.com/questions/23918', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/364/']