Dear OpenGl developers,
I am new to this forum and to OpenGL, so hello everyone and thanks in advance for your help,
and please accept my sincerest apologies in advance for the stupid questions I will ask here,
and that will bother you more than anything.
I am learning (self education) OpenGL and I have a problem when resizing my window scene,
thus I found many tutorials on line with the following lines (roughly):
void reshape (int width, int height)
{
double aspect;
glViewport (0, 0, width, height);
aspect = (double) width / (double) height;
double fos = 10.0;
double near = 1.0;
double far = 10.0;
double top, bottom, right, left;
top = tan (fos * pi / 360.0) * near;
right = top * aspect;
left = - right;
bottom = - top;
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (fos, aspect, near, far);
/* or alternatively with glFrustum
glFrustum (left, right, bottom, top, near, far); */
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
}
First I hope that this code is ok, otherwise any help to correct it will be highly appreciated.
At this point I face some troubles:
(1) the first being the use of the instruction:
glLoadMatrix (GL_MODELVIEW)
if I use this instruction then I have an empty screen after resize
(or at least I can not see what should be displayed … 2 spheres drawn using gluSphere in my case) …
in order to use that instruction I have to insert before that a new instruction:
glLoadIdentity ();
any idea why ? … is there anything wrong ?
(2) after resize I want to keep an aspect ratio that will not stretch my 2 spheres,
but no matter what I am trying the image always appears to be stretched …
… any idea of what I am doing wrong here ?
Again thanks in advance for your help.
S.