Hallo,
I would like to get the size (width, height) of the window. I think I should use glutGet(GLUT_WINDOW_X), but this function it always return the same (wrong) values even when I resize the window. This is the code I am using:
#include <GL/glut.h>
#include <stdio.h>
// dimensions
float _flagW;
float _flagH;
int winW;
int winH;
void init (void)
{
// set default values
_flagW = 100.0;
_flagH = _flagW / 2;
}
void getWinDimensions()
{
winW = glutGet(GLUT_WINDOW_X);
winH = glutGet(GLUT_WINDOW_Y);
}
void draw()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
getWinDimensions();
printf("%d
",winW);
glOrtho(0.0, 200.0, 0.0, 200.0, -1.0, 1.0);
glEnable(GL_POLYGON_SMOOTH);
glColor3f(1.0,0.0,0.0);
// cross: vertical
glBegin(GL_POLYGON);
glVertex2i(0 , 0);
glVertex2i(_flagW , 0);
glVertex2i(_flagW, _flagH);
glVertex2i(0, _flagH);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
init();
glutInitWindowSize(500,500);
glutCreateWindow("GB flag");
glutDisplayFunc(draw);
glutMainLoop();
}