0

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); 
}

Here is a simple image to illustrate the problem: enter image description here

Note : I have tried glViewPort(0,0, 665, 365) which are the initial height and weight of myBlueQuad, but that is not what i want since i want to be able to see the rest of the 3d universe to the right (for instance if i translate the quad to the right, i want to be able to see it)

Based on this thread: the difference between glOrtho and glViewPort in openGL I am pretty sure I need to use glOrtho but not sure how.. ive tried the following as @tkausl suggested:

glViewport(0, 0, width, height); 
glOrtho(0, width, height, 0, -1.0, 1.0); //width and height of window panel

But unfortunately, i get the same result as before. It seems that glOrtho is never applied, i've also tried calling glLoadIdentity() before my glOrtho call, it has no effect on the end result.

Community
  • 1
  • 1
Rose
  • 2,619
  • 4
  • 20
  • 27
  • You need to fix your projection matrix. – tkausl Oct 03 '16 at 00:46
  • @tkausl: thanks for answering :) could you be a little more specific please – Rose Oct 03 '16 at 00:50
  • 1
    You've already edited in the part you're missing. If you don't do vector-math yourself you need to use `glOrtho`. `glViewport` sets up your window-region OpenGL is allowed to draw in, `glOrtho` sets which virtual size this region has. Check the [Docs](https://www.khronos.org/opengles/sdk/1.1/docs/man/glOrtho.xml) on how to call the function, It'd probably the easiest to start with `left` and `top` as 0.0, `right` as your window-width, `bottom` as your window-height, `zNear` as `-1.0` and `zFar` as `1.0`. – tkausl Oct 03 '16 at 01:32
  • @tkausl: thanks very much for your help.. ive tried exactly what you've suggested and unfortuntately i still get the same problem (edited my first post with your suggestion in mind). also tried glOrtho(0, 675, 0, 365, -1.0,1.0); did not work as well. What am I doing wrong ? :( – Rose Oct 03 '16 at 03:02
  • 1
    You need to use the windows width and height, not the quads ones. So the same parameters you pass to `glViewport` – tkausl Oct 03 '16 at 03:25
  • @tkausl: Thanks I appreciate your help, ive tried both : glOrtho(0,width, height, 0,-1.0,1.0) //width and height of my window as youve just suggested and glOrtho(0,675, 365, 0, -1.0,1.0) //my quad dimension (the dimension that i want the quad to keep) Both are not working.. i am going crazy ! lol the quad keeps resizing almost as big as the window (as seen in the image posted) – Rose Oct 03 '16 at 03:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124757/discussion-between-rose-and-tkausl). – Rose Oct 03 '16 at 03:49

0 Answers0