resizing window with glOrtho problem

Hi, I am new to openGL and wondering how to redimension a window in opengl without resizing objects in it (for example a quad drawn in opengl). I currently have a simple C++ function such as :

void ProjectionOrtho::redimensionWindow(int width, int height)
{
glViewport(0, 0, width, height);
glOrtho(0, width, height, 0, -1.0, 1.0);
}

Here is an image illustrating the problem : [ATTACH=CONFIG]1406[/ATTACH]

I would like that if i redimension my window, the quad keeps its initial position and doesnt redimension, and what we would see on the expanded window is the rest of the universe. For instance if i translate my quad to the right i want to be able to see it on the right.

What i have right now : the quad keeps redimensionnig with the window, so if the window gets to ex: 1000*1000 the quad will still occupy lets say 95% of the space… the quad resizes with the window resize, which is not the intended result.

Thank you very much for your insights :slight_smile: I’ve been stuck with this issue for quite a while now.

Your existing function does exactly that (assuming that width and height are the window dimensions).

In that case, either the settings made in your redimensionWindow() function aren’t being used (e.g. they’re being overridden elsewhere), or you’re changing the object-space space coordinates of the quad’s vertices.

I note that you don’t call glMatrixMode(GL_PROJECTION). That isn’t necessarily a problem; if you aren’t using lighting, it’s reasonable to use only a single matrix (projection or model-view) and leave the other as the identity matrix. But I’m wondering if you’re overriding the glOrtho() call with e.g. a glLoadIdentity() call elsewhere.

Ok I’ve tried the following :

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glOrtho(0, width, height, 0, -1000.0, 1000.0);
//glMatrixMode(GL_MODELVIEW); *when i uncomment that line the quad disapears…

However, it seems that glOrtho is just not applied, no matter what parameters i pass in. What could be the cause?

I can also validate that height and width are ok.

Also,

My four quads are drawn with the following code :
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f);

glVertex3f(0, 0, 0); //pointCenter
glVertex3f(0.9, 0, 0); //pointCenterRight
glVertex3f(0.9, 0.9, 0); //pointUpRight
glVertex3f(0, 0.9, 0); //pointUpCenter
																 //quad en bas a gauche
glVertex3f(0, 0, 0); //pointCentre
glVertex3f(-0.9,0,0); //pointCenterLeft
glVertex3f(-0.9, -0.9, 0); //pointBottomLeft
glVertex3f(0, -0.9, 0); //pointBottomCenter
																
glVertex3f(0, 0, 0); //pointCenter
glVertex3f(0, 0.9, 0); //pointUpCenter
glVertex3f(...)
glVertex3f(...)
																	 
glVertex3f(0,0,0);
glVertex3f(...); 
glVertex3f(...); 
glVertex3f(...); 

glEnd();

Also, I have 3d objects (loaded from .obj files) sitting on top of the quad, which redimension as well as the multiple quads.

I dont use any lighting or any special effects.

I have also tried glLoadIdentity before the glOrtho call, and it doesnt seem to work either. (i see no change, quad and other objects still take about 95% of the space instead of just keeping their initial size)

glOrtho(0, width, height, 0, -1000.0, 1000.0);

Are you sure about the values you are giving to glOrtho ?