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>

int main(int argc, char** argv)
{
glutInit(&amp;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?

V-man

12-20-2011, 08:51 AM

Use square brackets for your code tags as explained in the Forum posting guidelines.

Yes, you can put the first lines in the init function. Your programming style will not necessarily match someone else's style.

When a window is changing his height/width, will only 'reshape' execute or also 'display'?
I think it will not. That is why it should call glutPostRedisplay or whatever that GLUT function was called.

GL_PROJECTION will be used for perspective.
In this case yes, it uses glFrustum which gives a perspective view.

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.
The 2 matrices are setup by reshape (int w, int h).

Why GL_PROJECTION is used in 'Reshape'?
Because setting it once is enough. If you want to move it to display(), go ahead.

I'm not able to understand. Sometimes, MODELVIEW stands *before* PROJECTION, sometimes the other way.
The 2 don't have anything to do with each other.

Does it matter if the drive way is in front of your house or behind your house? Which do you prefer?
Whatever you prefer, you still will have 1 modelview matrix and 1 projection matrix.

golden_gun

12-21-2011, 08:41 AM

Thanks for your answer.

Now, I want to create a own cube in the center of my system.
I added a view, what I want to do.
My code so far