我正在尝试遵循红皮书第8章中的glDrawPixels示例 (这是不完整的)但看不到任何东西(我只是看到黑屏 我运行代码时没有pixmap。我有什么想法吗?
#include <GL/glut.h>
#define CHECK_IMAGE_WIDTH 64
#define CHECK_IMAGE_HEIGHT 64
static GLubyte checkImage[CHECK_IMAGE_WIDTH][CHECK_IMAGE_HEIGHT][3];
void makeCheckImage(void) {
int i, j, c;
for (i = 0; i < CHECK_IMAGE_HEIGHT; i++)
for (j = 0; j < CHECK_IMAGE_WIDTH; j++) {
checkImage[i][j][0] = (GLubyte) 255;
checkImage[i][j][1] = (GLubyte) i == j ? 255 : 0;
checkImage[i][j][2] = (GLubyte) 255;
}
}
void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0, 0);
glDrawPixels(CHECK_IMAGE_WIDTH, CHECK_IMAGE_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, checkImage);
glFlush();
}
void reshape(int w, int h) {
gluOrtho2D(-10.0f, 10.0f, -10.0f, 10.0f);
glViewport(0, 0, w, h);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
答案 0 :(得分:4)
您的代码错过了init调用,该调用使用内容初始化棋盘图像。在init();
glutMainLoop();