答案 0 :(得分:0)
您需要捕获resize事件。在过剩时,您必须使用函数glutReshapeFunc注册回调。在此功能中,您可以更改投影参数和视口。
以下是程序中的一个小变化,显示了如何执行此操作:
(...)
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, width, 0.0, height);
glMatrixMode(GL_MODELVIEW);
}
(...)
int main(int argc, char** argv)
{
(...)
glutDisplayFunc(display);
glutReshapeFunc(reshape); /* <--- */
myinit();
(...)
}
答案 1 :(得分:0)
切换到双缓冲(GLUT_DOUBLE
&amp; glutSwapBuffers()
)会将其修复到我的系统上:
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
void display( void )
{
typedef GLfloat point2[2];
point2 vertices[3]={{0.0,0.0},{250.0,500.0},{500.0,0.0}};
int i, j, k;
int rand();
point2 p ={75.0,50.0};
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_POINTS);
glColor3f(1.0, 0.0, 0.0);
for( k=0; k<5000; k++)
{
j=rand()%3;
p[0] = (p[0]+vertices[j][0])/2.0;
p[1] = (p[1]+vertices[j][1])/2.0;
glVertex2fv(p);
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Sierpinski Gasket");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}