First of all, sorry for my bad english, but I’m not an native-speaker.
I’m interessted in learning OpenGL, but have some problems with it.
Here is a small code from
http://glprogramming.com/red/chapter03.html
<code>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix /
/ viewing transformation /
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0); / modeling transformation */
glutWireCube (1.0);
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
</code>
There is a function called ‘init’. For what kind of stuff is it? Why can’t we write the first lines of ‘int main’ in these function?
The function ‘reshape’ is for dealing with windows, which changed their height and width. When a window is changing his height/width, will only ‘reshape’ execute or also ‘display’?
The second big problem is, understanding OpenGL’s Matrixmode GL_MODELVIEW and GL_PROJECTION.
With GL_MODELVIEW, I’m able to paint my GL_QUADS, GL_LINES etc.
GL_PROJECTION will be used for perspective.
So far.
In the example I gave, ‘Display’, is no matrixmode are given. I think, GL_MODELVIEW is working to set my objects in the coordinatesystem up.
Why GL_PROJECTION is used in ‘Reshape’?
I’m not able to understand. Sometimes, MODELVIEW stands before PROJECTION, sometimes the other way.
Can you help me please?