码迷,mamicode.com
首页 > 系统相关 > 详细

Linux(Ubuntu 14.04) setting up OpenGL

时间:2015-05-19 18:55:27      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

1. Install c/c++ compilation package.

2. install openGL and freeGlut library

sudo apt-get install mesa-common-dev

sudo apt-get install freeglut3-dev

3. testing: run this code (comes from openGL red book) by save it as a cpp file. Then open the terminal and navigate to the directory containing this cpp file.

 g++ text.cpp -lglut -lGL
Then you will get an a.out. run it by

./a.out4. Done

 1 #include "GL/freeglut.h"
 2 #include "GL/gl.h"
 3 
 4 /* display function - code from:
 5      http://fly.cc.fer.hr/~unreal/theredbook/chapter01.html
 6 This is the actual usage of the OpenGL library. 
 7 The following code is the same for any platform */
 8 void renderFunction()
 9 {
10     glClearColor(0.0, 0.0, 0.0, 0.0);
11     glClear(GL_COLOR_BUFFER_BIT);
12     glColor3f(1.0, 1.0, 1.0);
13     glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
14     glBegin(GL_POLYGON);
15         glVertex2f(-0.5, -0.5);
16         glVertex2f(-0.5, 0.5);
17         glVertex2f(0.5, 0.5);
18         glVertex2f(0.5, -0.5);
19     glEnd();
20     glFlush();
21 }
22 
23 /* Main method - main entry point of application
24 the freeglut library does the window creation work for us, 
25 regardless of the platform. */
26 int main(int argc, char** argv)
27 {
28     glutInit(&argc, argv);
29     glutInitDisplayMode(GLUT_SINGLE);
30     glutInitWindowSize(500,500);
31     glutInitWindowPosition(100,100);
32     glutCreateWindow("OpenGL - First window demo");
33     glutDisplayFunc(renderFunction);
34     glutMainLoop();    
35     return 0;
36 }

Note: Fell free to context me.

 

Linux(Ubuntu 14.04) setting up OpenGL

标签:

原文地址:http://www.cnblogs.com/znbee/p/4515105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!