安装
apt-get install freeglut3-dev
它会装上依赖的包的。
测试代码
当然是写个程序测试了,我只是把“Computer Graphics Using OpenGL”的第一个完整程序稍微改了改。另外发现个blog的问题-把<GL/glut.h>给替换没了。
#include “GL/gl.h”编译运行// OpenGL itself. #include “GL/glut.h” // GLUT support library.
void DrawText(GLint x, GLint y, char* s, GLfloat r, GLfloat g, GLfloat b)
{
int lines;
char* p;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();glOrtho(0.0, glutGet(GLUT_WINDOW_WIDTH),
0.0, glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(r,g,b);
glRasterPos2i(x, y);
for(p = s, lines = 0; *p; p++) {
if (*p == '\n') {
lines++;
glRasterPos2i(x, y-(lines*24));
}
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *p);
}
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
DrawText(200, 420, "hello,OpenGL",1.0,0.0,0.0);
DrawText(100, 450, "www.herofit.com",0.0,1.0,0.0);
DrawText(300, 390, "wxWidgets",0.0,1.0,0.0);
DrawText(30, 390, "Code::Blocks",0.0,1.0,1.0);
glFlush();
}
int main( int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100,150);
glutCreateWindow("my first OpenGL app");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 1;
}
假设上面内容存为opengltest1.c
gcc opengltest1.c -o opengltest1 -lGL -lglut
./opengltest1运行结果
参考资料:
DrawText
没有评论:
发表评论