过去一直不理解diplay和reshape回调函数的调用看完下面这个例子会明白,每次reshape其实都会调用display。reshape主要负责重置坐标系统和投影矩阵
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#include <GL/glu.h>
using namespace std;
void init()
{
printf("use init\n");
glClearColor(0, 0, 0, 0);
glShadeModel(GL_FLAT);
}
void display()
{
printf("use display\n");
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 1, 1);
glLoadIdentity();
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
//glScalef(1, 2, 1);
glutWireCube(1);
glFlush();
}
void reshape(int w, int h)
{
//glViewport(0, 0, (GLsizei)w, (GLsizei)h);
printf("width:%d,heigth:%d\n",w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 1.5, 20);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowP