PDA

View Full Version : Problems reshaping window in Glut



VinŪcius Reis
03-28-2005, 11:38 AM
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
IMPLICIT NONE
INTEGER(kind=GLsizei)::larg,alt

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)
ELSE
CALL glViewport (0, 0,3*larg/4,3*larg/4)
END IF

CALL glutPostRedisplay()

END SUBROUTINE

pedrodx
03-30-2005, 02:44 AM
Hi!!

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!!

pedrodx
03-30-2005, 02:57 AM
NO NO,,,, forget it!!!

dvm
03-30-2005, 07:42 AM
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); )

VinŪcius Reis
03-30-2005, 07:54 AM
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!

dvm
03-30-2005, 08:00 AM
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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(..) or whatever suits you
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}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.

VinŪcius Reis
03-30-2005, 08:25 AM
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 !

dvm
03-30-2005, 09:13 AM
I think it's neccesary to change the view frustum in each reshape.

VinŪcius Reis
03-30-2005, 09:39 AM
Maybe... I donít have a clue of what frustum is! :confused: :(

dvm
03-30-2005, 10:29 AM
"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.