PDA

View Full Version : Can't reshape subwindow



wmelgaard
09-29-2015, 12:04 PM
I am running Debian Stable (Jessie), with GLU1.3, and am trying to reshape a subwindow.
The following program writes a subwindow in the top, left corner of the main window. If you left-click on that area, it is supposed to toggle the size of the subwind// subwindow.c

Why does not line 46
glutReshapeWindow(500, swindowheight);
reshape my subwindow?



// compile as gcc subwindow.c -lm -lglut -lGL

#include <stdio.h>
#include <GL/glut.h>

int WindowWidth = 750, WindowHeight = 500, iwindow[2];

void init(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0.75, 0.75, 0.75, 1.0);
glOrtho(0, WindowWidth, 0, WindowHeight, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(.75, .75, .75);
glVertex2i(0, 0);
glVertex2i(WindowWidth, 0);
glVertex2i(WindowWidth, WindowHeight);
glVertex2i(0, WindowHeight);
glEnd();
glutSwapBuffers();
}

void display(){ // display main window
// not interested in main window
}

void subwindow(int x, int y){ // display subwindow on command; x, y not used
static int condition = 0, swindowheight;
if(condition == 1){ // toggle between condition 1 & condition 0
condition = 0;
swindowheight = 100;
}
else{
condition = 1;
swindowheight = 150;
}
printf("condition = %d; swindowheight = %d\n", condition, swindowheight);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
glutReshapeWindow(500, swindowheight);
glViewport(0, 0, (GLsizei) 500, (GLsizei) swindowheight);
glOrtho(0, 500, 0, swindowheight, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(10, swindowheight -10);
glVertex2i(490, swindowheight -10);
glVertex2i(490, swindowheight -40);
glVertex2i(10, swindowheight -40);
glColor3f(0.0, 1.0, 0.0);
glVertex2i(10, swindowheight -50);
glVertex2i(490, swindowheight -50);
glVertex2i(490, swindowheight -90);
glVertex2i(10, swindowheight -90);
glEnd();
glutSwapBuffers();
}


void mouse(int btn, int state, int x, int y){
if(btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ } // not used
else if(btn == GLUT_LEFT_BUTTON && state == GLUT_UP){
subwindow(x, y);
}
}

int main(int argc, char* argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(WindowWidth, WindowHeight);
glutInitWindowPosition(100, 100);
iwindow[0] = glutCreateWindow("Resizing Subwindow");
init();

iwindow[1] = glutCreateSubWindow(iwindow[0], 10, 10, 500, 100);
glutMouseFunc(mouse);;
// glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMainLoop();
}

Incidentally, line 13 should give me a gray screen without recourse to lines 17 - 23. However, without the GL_QUADS, I get a black screen. ??

GClements
09-30-2015, 06:59 AM
The glutReshapeWindow() call shouldn't be in the middle of your drawing code. The mouse callback should just reshape the window then leave it to the display function registered with glutDisplayFunc() to actually perform drawing.

wmelgaard
09-30-2015, 11:21 AM
Your answer sounds like a style issue. Within my project, "windowheight" is a computed number. For the test problem, I merely toggled between two heights. In practice, "windowheight" can be any one of several heights.


The glutReshapeWindow() call shouldn't be in the middle of your drawing code. The mouse callback should just reshape the window then leave it to the display function registered with glutDisplayFunc() to actually perform drawing.