Reputation: 1
I need my main window and subwindow to be resized when I make the window larger or smaller. For the subwindow, it should resize automatically when the main window is resized. Meanwhile, I also need to protect the aspect ratio of both of my windows. I achieved this for my main window, but I can't resize or protect the aspect ratio of the subwindow using FreeGLUT. What is the proper way of doing this in FreeGLUT?
I tried using glutReshapeFunc()
for the subwindow, however it still does not resize the subwindow. Indeed, when I applied the same steps for my main window it protected the ratio perfectly. This is the code and what I tried:
#include <GL/glut.h>
using namespace std;
void display(void);
void reshape(int width, int height);
void drawGrid(void);
const float gridSize = 20;
void drawGrid()
{
//vertical grid lines
glColor3f(1, 1, 0);
glLineStipple(1, 0xAAAA);
glEnable(GL_LINE_STIPPLE);
glBegin(GL_LINES);
for (int i = 0; i <= 100; i += gridSize) {
glVertex2f(i, -100);
glVertex2f(i, 100);
}
//horizontal grid lines
for (int i = -100; i <= 100; i += gridSize) {
glVertex2f(0, i);
glVertex2f(100, i);
}
glEnd();
glDisable(GL_LINE_STIPPLE);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
drawGrid();
glutSwapBuffers();
}
void reshape(int width, int height) {
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float aspectRatio = static_cast<float>(width) / static_cast<float>(height);
if (aspectRatio > 1.0) {
gluOrtho2D(-10 * aspectRatio, 110 * aspectRatio, -110, 110);
}
else {
gluOrtho2D(-10, 110, -110 / aspectRatio, 110 / aspectRatio);
}
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowSize(512, 512);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
int mainWindow = glutCreateWindow("Main Window");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
int subWindow = glutCreateSubWindow(mainWindow, 50, 50, 412, 412);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
Upvotes: 0
Views: 77