PDA

View Full Version : resizing window with glOrtho problem



clarenced
10-02-2016, 09:48 PM
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 : 2295

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 :) I've been stuck with this issue for quite a while now.

GClements
10-02-2016, 10:03 PM
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.

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



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.

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.

clarenced
10-03-2016, 08:58 AM
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)

Silence
10-04-2016, 01:11 AM
glOrtho(0, width, height, 0, -1000.0, 1000.0);



Are you sure about the values you are giving to glOrtho (https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml) ?