我正在尝试尝试渲染位图字体的简单实现,如红皮书中所述。问题是我的视口始终是空白的,屏幕上没有任何内容。
以下是代码:
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
GLubyte A[14] = {
0xc0,0x00,
0x60,0xc0,
0x3f,0x80,
0x11,0x00,
0x0a,0x00,
0x0a,0x00,
0x04,0x00,
};
void init(void)
{
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClearColor(0,0,0,0);
}
void display(void)
{
float c[4];
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,1);
glGetFloatv(GL_CURRENT_RASTER_POSITION, c);
printf("%f %f %f %f\n", c[0],c[1],c[2],c[3]);
printf("%x\n",A[0]);
glRasterPos2f(20,20);
glGetFloatv(GL_CURRENT_RASTER_POSITION_VALID, c);
printf("%f\n", c[0]);
glBitmap(12,7,0,0,11,0,A);
//glBitmap(12,7,0,0,11,0,A);
//glBitmap(12,7,0,0,11,0,A);
glGetFloatv(GL_CURRENT_RASTER_POSITION, c);
printf("%f %f %f %f\n", c[0],c[1],c[2],c[3]);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0, h, -1.0, 1.0);
//gluOrtho2D(0,1,0,1);
glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("FOnt");
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
答案 0 :(得分:3)
适合我:
在Vista64上编译FreeGLUT(编译为32位),Radeon HD 6570. VS 2008。
编辑:在Linux上也是如此:
Ubuntu 10.04 amd64,Intel HD Graphics 3000,Mesa DRI Intel(R) Sandybridge Mobile GEM 20100330 DEVELOPMENT
<强> EDIT2:强>
尝试通过glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
或glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
使用双缓冲,并将glutSwapBuffers()
添加到display()
功能的末尾。
和/或尝试停用compositor(compiz
,kwin
,unity
,GNOME Shell
等),如果您启用了一个。
答案 1 :(得分:2)
GL_SINGLE
替换为GLUT_DOUBLE
glFlush()
替换为glutSwapBuffers()
glLoadIdentity()
glMatrixMode(GL_MODELVIEW)
醇>
然后它应该工作