Problems reshaping window in Glut

I wrote the following function to reshape two subwindows (2 and 3) when the parent window is reshaped. What I wanted was to maintain the proportion of the second subwindow (3) but some how it’s not working! I checked and the viewport is O.K. at the end of this function, but when the screen is redisplayed it’s not what I’m expecting, for example if then main window has 200x600 pixels, the viewport of the subwindow should have 150X150, but it’s being displayed with 150x600. What’s wrong here?

SUBROUTINE resh(larg,alt)

USE opengl_gl
USE opengl_glu
USE opengl_glut

CALL glutSetWindow(2)
CALL glutPositionWindow(3*larg/4,0)
CALL glutReshapeWindow(larg/4,alt)
CALL glViewport (0, 0,larg/4,alt)

CALL glutSetWindow(3)
CALL glutPositionWindow(0,0)
CALL glutReshapeWindow(3*larg/4,alt)
IF ((3*larg/4)>alt) THEN
	CALL glViewport (0, 0,alt,alt)
	CALL glViewport (0, 0,3*larg/4,3*larg/4)

CALL glutPostRedisplay()



Try using gluOrtho2D or glOrtho instead using glViewport. Glviewport is to draw to a portion of a window, and I understood you want to do a reshaping of your object against the same portion of a window (subwindow in its case).

See ya!!

NO NO, forget it!!!

Is this a problem on the size of the window or how the objects appear in it?
Read the specs to understand better what each function does.
Usually when you change (reshape) the window, glViewport is placed in the reshape callback. I don’t think you do it that way. The callback should have the proper information regarding its own window and then you can call glViewport
(usually glViewport(0, 0, windowWidth, windowHeight); )

Sorry, I didn’t make it clear!

In my program I reshaped the sub window to the size that I waned, after that I tried to redefine the viewport, so the window (Glut) is working properly, what is not working is the viewport that a want to maintain in a square shape! When the program leaves the subroutine, the viewport is o.k., squared as I wanted, but when the program enters the display function, the viewport is changed!

Because when you call glutReshapeWindow, the reshape callback function (usually reshape) will be called, before display gets called. That’s what I’m telling you, you shouldn’t call glViewport outside the reshape callback. For example, this is a proper reshape callback routine:

void reshape(int w, int h)
  glViewport(0, 0, w, h);
  glOrtho(..) or whatever suits you

This piece of code will be called whenever you call glutReshapeWindow or whenever you resize the window with your mouse. Hope I made it clear (and I hope I understood you!)

Wooww, just had a better look :rolleyes:
Ok, I think you should create a reshape function callback for every subwindow you create. So when it is resized it gets the proper dimensions.

I just call glViewport when I create the window and when it’s reshaped! As I saw that the draw was wrong so I went to the display function and called glGetIntegerv(GL_VIEWPORT,aux) to see what was the viewport there.

I forgot to say: larg => window width
alt => window height

One thing that I saw in your reshape callback is that you reshape your viewing area with glOrtho(). I don’t want to do that, so I create the window, define the viewing area (gluOrtho2D() ) and after I don’t touch it, I just reshape my viewport!

P.S.: All right I’m going to start studding C !

I think it’s neccesary to change the view frustum in each reshape.

Maybe… I don’t have a clue of what frustum is! :confused: :frowning:

“The 3D world”. You define a volume. Anything in it is drawn (if the camera sees it), anything outside is clipped. Do a search in google.