当前位置:首页 > linux教程 > 列表

Linux操作系统设置OpenGL编程环境的方法

发布:smiling 来源: PHP粉丝网  添加日期:2014-03-06 17:22:12 浏览: 评论:0 

先装个freeglut或者mesa。

以freeglut举例,装好后会在/usr/include/GL中出现glut.h,在/usr/lib下出现libglut.so,如果没有就自己拷一下。

然后写个测试程序,如test.c,用以下命令编译:

gcc -lglut test.c -o test

生成可执行文件test,然后:

./test

看到方框说明安装成功:)

如手上没有现成的测试例子,附件是openGL红宝书的第一个例子hello.c

  1. #include <GL/glut.h> 
  2. void display(void) 
  3. { 
  4. /* clear all pixels */ 
  5. glClear (GL_COLOR_BUFFER_BIT); 
  6. /* draw white polygon (rectangle) with corners at 
  7. * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)  
  8. */ 
  9. glColor3f (1.0, 1.0, 1.0); 
  10. glBegin(GL_POLYGON); 
  11. glVertex3f (0.25, 0.25, 0.0); 
  12. glVertex3f (0.75, 0.25, 0.0); 
  13. glVertex3f (0.75, 0.75, 0.0); 
  14. glVertex3f (0.25, 0.75, 0.0); 
  15. glEnd(); 
  16. /* don't wait!  
  17. * start processing buffered OpenGL routines  
  18. */ 
  19. glFlush (); 
  20. } 
  21. void init (void)  
  22. { 
  23. /* select clearing color     */ 
  24. glClearColor (0.0, 0.0, 0.0, 0.0); 
  25. /* initialize viewing values */ 
  26. glMatrixMode(GL_PROJECTION); 
  27. glLoadIdentity(); 
  28. glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); 
  29. } 
  30. /*  
  31. * Declare initial window size, position, and display mode 
  32. * (single buffer and RGBA). Open window with "hello" 
  33. * in its title bar. Call initialization routines. 
  34. * Register callback function to display graphics. 
  35. * Enter main loop and process events. 
  36. */ 
  37. int main(int argc, char** argv) 
  38. { 
  39. glutInit(&argc, argv); 
  40. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 
  41. glutInitWindowSize (250, 250);  
  42. glutInitWindowPosition (100, 100); 
  43. glutCreateWindow ("hello"); 
  44. init (); 
  45. glutDisplayFunc(display);  
  46. glutMainLoop(); 
  47. return 0; /* ANSI C requires main to return int. */ 
  48. } 

Tags: Linux操作系统 OpenGL 编程环境

分享到: