glDrawPixels:看不到程序输出
我正在尝试遵循红皮书第 8 章中的 glDrawPixels 示例 (这是不完整的)但看不到任何东西(我只看到黑屏 当我运行代码时没有像素图。有什么想法我做错了吗?
#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;
}
I am trying to follow the glDrawPixels example from Chapter 8 of the red book
(which is incomplete) but cannot see anything (I just see a black screen with
no pixmapwhen I run the code. Any ideas what I am doing wrong?
#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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码错过了 init 调用,该调用用内容初始化棋盘图像。在
glutMainLoop();
之前添加一个init();
Your code misses the init call, which initializes the checkerboard image with content. Add a
init();
right beforeglutMainLoop();