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
", 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. ??