我写了几行代码来绘制一个旋转的矩形:
#include "glut.h"
static GLfloat spin = 0.0; /* current angle */
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0); /* rotate Oxyz (OZ) */
glColor3f(1.0, 1.0, 1.0); /* bgr-color: white; */
glRectf(-25.0, -25.0, 25.0, 25.0); /* Rectangle */
glPopMatrix();
glutSwapBuffers(); /* Swap 2 buffer */
}
void spinDisplay(void)
{
spin = spin + 2.0; /* Add 2 degrees for every loop action */
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay(); /* Alert: Redraw */
}
/* Change window mode */
void reshape(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h); /* change viewport */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* Mouse interaction */
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON: /* left mouse */
if (state == GLUT_DOWN)
glutIdleFunc(spinDisplay); /* idle mode switch to spinDisplay */
break;
//case GLUT_MIDDLE_BUTTON: /* middle mouse button */
//if (state == GLUT_DOWN)
//glutIdleFunc(NULL);
//break;
default:
break;
}
}
/* main */
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); /* double buffer */
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("spinning rectangle");
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape); /* reshape func (redraw) when window size changed */
glutMouseFunc(mouse); /* mouse func */
glutMainLoop();
return 0;
}
我想将帧缓冲区保存到图像(JPEG、BMP、TIFF)或文件中。你能告诉我怎么做吗?我需要使用一些像 jpeglib、libtiff 这样的库吗?