我在調整GLUT窗口大小時遇到問題。我想打印一個矩形,但是當我使用調整大小功能,我似乎無法在窗口中繪製和形狀。我有下面的代碼,我想改變廣場的寬度,當我調整窗口大小,但如果高度被調整大小,我不希望它的高度改變。在OpenGL中更改投影
#include <GLUT/glut.h>
#include <stdio.h>
#include <stdlib.h>
/* globals */
GLsizei wh = 500, ww = 500;
/* initial window size */
GLfloat size = 3.0;
/* half side length of square */
void myinit(void)
{
glClearColor(0.0,0.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,1,0,1.0,-1.0,1.0);
glViewport(0,0,ww,wh);
}
/* display callback -- required by GLUT 3.0 */
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,.5,.7);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush();
}
void mouse(int button, int state, int x, int y) {
if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,500,0.0,500,0.0,1.0);
}
}
/*app quits if q is pressed*/
void keyboard(unsigned char key, int x, int y) {
if(key == 'Q' | key == 'q')
exit(0);
}
/* The main program -- note that there is no "flow of control" -- the program merely calls functions to handle interactions */
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(ww,wh);
glutInitWindowPosition(100,100);
glutCreateWindow("Square");
myinit();
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutDisplayFunc(renderScene);
//glutReshapeFunc(changeSize);
glutMainLoop();
return 0;
}
我做了一個試驗changeSize功能,當我用它只會顯示一個空的藍色窗口,而不矩形在那裏