使用 glBitmap 不在屏幕上渲染任何内容
我正在尝试尝试渲染位图字体的简单实现,如红皮书中给出的那样。问题是我的视口始终是空白的,屏幕上没有任何内容。
这是代码:
#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;
}
I'm trying out a simple implementation of trying to render a bitmap font, as given in the Red book. The problem is that my viewport is blank throughout and nothing comes on the screen.
Here's the code:
#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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我有用:
FreeGLUT 在 Vista64(编译为 32 位)、Radeon HD 6570 上。VS 2008。
编辑:在 Linux 上还有:
Ubuntu 10.04 amd64、Intel HD Graphics 3000、
Mesa DRI Intel(R) Sandybridge Mobile GEM 20100330开发
编辑2:
尝试使用双缓冲
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
或glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
并将glutSwapBuffers()
添加到display() 的末尾
函数。和/或尝试禁用您的合成器 (
compiz
, < code>kwin、unity
、GNOME Shell
等)(如果您已启用)。可能是驱动程序错误。
Works for me:
FreeGLUT on Vista64 (compiled as 32-bit), Radeon HD 6570. VS 2008.
EDIT: On Linux too:
Ubuntu 10.04 amd64, Intel HD Graphics 3000,
Mesa DRI Intel(R) Sandybridge Mobile GEM 20100330 DEVELOPMENT
EDIT2:
Try using double-buffering via
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
orglutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
and addingglutSwapBuffers()
to the end of yourdisplay()
function.And/or try disabling your compositor (
compiz
,kwin
,unity
,GNOME Shell
, etc) if you have one enabled.Might be a driver bug.
GL_SINGLE
替换为GLUT_DOUBLE
glFlush()
替换为glutSwapBuffers()
glLoadIdentity()
> 之后glMatrixMode(GL_MODELVIEW)
那么它应该可以工作
GL_SINGLE
withGLUT_DOUBLE
glFlush()
withglutSwapBuffers()
glLoadIdentity()
afterglMatrixMode(GL_MODELVIEW)
Then it should work