# OpenGL learning

I spent 2 days looking to a code and asking me: “Why this do not work?
Everything is like NeHe, it should be working.” Then, after some hours
reading the redbook (I have found an old version PDF on
http://www.opengl.org/documentation/red_book_1.0/) I finally understood:
everything I have thought about how OpenGL works was wrong, so I could
make the code works. This is an advice to anyone interested in learning
OpenGL: do not enter NeHe site before have read and understood all the
concepts of the redbook (I do not know if it is the best information
source, but it is better than NeHe). Before I realize how it works, I
never asked myself “Why, in hell, I reset Modelview Matrix at every
frame?” or even “What is a Modelview Matrix?”.

I do not want to say that NeHe is bad, it is bad to learn OpenGL from
beginning, but it is a good source of information where you can find
nice techniques and effects, just do not try them before knowing what
you are doing.

I would like to suggest the webmaster (who is the webmaster?) to change
the OpenGL Documentation page: set the first link to where you can find
more theoretical information first (like
http://www.opengl.org/documentation/red_book_1.0/), and put NeHe as a
techniques and effects source.–
Lucas Clemente Vella
@Lucas_Clemente_Vella

I don’t know, I taught myself OpenGL using the tutorials on the NeHe
site just fine. Rereading tutorial 1, it seems pretty obvious and
intuitive to me. The part that deals with the Projection Matrix in the
first tutorial (inside the GLvoid ReSizeGLScene(GLsizei width, GLsizei
height) function):

The following lines set the screen up for a perspective view. Meaning
things in the distance get smaller. This creates a realistic looking
scene. The perspective is calculated with a 45 degree viewing angle
based on the windows width and height. The 0.1f, 100.0f is the starting
point and ending point for how deep we can draw into the screen.

glMatrixMode(GL_PROJECTION) indicates that the next 2 lines of code will
affect the projection matrix. The projection matrix is responsible for
It restores the selected matrix to it’s original state. After
glLoadIdentity() has been called we set up our perspective view for the
scene. glMatrixMode(GL_MODELVIEW) indicates that any new transformations
will affect the modelview matrix. The modelview matrix is where our
object information is stored. Lastly we reset the modelview matrix.
Don’t worry if you don’t understand this stuff, I will be explaining it
all in later tutorials. Just know that it HAS to be done if you want a
nice perspective scene.
– end of comments section –

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix

Lucas Clemente Vella wrote:> I spent 2 days looking to a code and asking me: "Why this do not work?

Everything is like NeHe, it should be working." Then, after some hours
reading the redbook (I have found an old version PDF on
http://www.opengl.org/documentation/red_book_1.0/) I finally understood:
everything I have thought about how OpenGL works was wrong, so I could
make the code works. This is an advice to anyone interested in learning
OpenGL: do not enter NeHe site before have read and understood all the
concepts of the redbook (I do not know if it is the best information
source, but it is better than NeHe). Before I realize how it works, I
never asked myself “Why, in hell, I reset Modelview Matrix at every
frame?” or even “What is a Modelview Matrix?”.

I do not want to say that NeHe is bad, it is bad to learn OpenGL from
beginning, but it is a good source of information where you can find
nice techniques and effects, just do not try them before knowing what
you are doing.

I would like to suggest the webmaster (who is the webmaster?) to change
the OpenGL Documentation page: set the first link to where you can find
more theoretical information first (like
http://www.opengl.org/documentation/red_book_1.0/), and put NeHe as a
techniques and effects source.

The cutting planes are not explained very well here. When I used this
code with Cal3d, it took me some time (days) to figure out why the
object disappeared after moving the object some distance deep into the
scene.

Michael B. Edwin Rickert wrote:> I don’t know, I taught myself OpenGL using the tutorials on the NeHe

site just fine. Rereading tutorial 1, it seems pretty obvious and
intuitive to me. The part that deals with the Projection Matrix in the
first tutorial (inside the GLvoid ReSizeGLScene(GLsizei width, GLsizei
height) function):

The following lines set the screen up for a perspective view. Meaning
things in the distance get smaller. This creates a realistic looking
scene. The perspective is calculated with a 45 degree viewing angle
based on the windows width and height. The 0.1f, 100.0f is the starting
point and ending point for how deep we can draw into the screen.

glMatrixMode(GL_PROJECTION) indicates that the next 2 lines of code will
affect the projection matrix. The projection matrix is responsible for
It restores the selected matrix to it’s original state. After
glLoadIdentity() has been called we set up our perspective view for the
scene. glMatrixMode(GL_MODELVIEW) indicates that any new transformations
will affect the modelview matrix. The modelview matrix is where our
object information is stored. Lastly we reset the modelview matrix.
Don’t worry if you don’t understand this stuff, I will be explaining it
all in later tutorials. Just know that it HAS to be done if you want a
nice perspective scene.
– end of comments section –

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix

Lucas Clemente Vella
@Lucas_Clemente_Vella