一、安装JDK以及Eclipse,我这里就不多介绍了,请自行参考网上资料。
二、安装CDT:
1.可以在Eclipse update中输入以下地址来安装:
2.也可以下载CDT Master update :
然后也是在Eclipse Update中选用本地路径来安装CDT。具体路径为:Help-->Software updates-->Available Software,选择Add site-->local,然后把刚才下载好的CDT Master导入。最后在左边列表选项中选择CDT,右键选择安装就可以了。
三、接下来准备OpenGL开发的条件:安装freeGlut,Gcc等。命令行如下:
1.sudo apt-get install mesa-common-dev mesademos libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev
2. sudo aptitude install build-essential
四、打开Eclipse,新建C++ Project.并且新增一个c++ source file。代码如下:
#include <GL/glut.h> #define window_width 640 #define window_height 480 // Main loop
void main_loop_function() { // Z angle
static float angle; // Clear color (screen)
// And depth (used internally to block obstructed objects)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load identity matrix
glLoadIdentity(); // Multiply in translation matrix
glTranslatef(0,0, -10); // Multiply in rotation matrix
glRotatef(angle, 0, 0, 1); // Render colored quad
glBegin(GL_QUADS); glColor3ub(255, 000, 000); glVertex2f(-1, 1); glColor3ub(000, 255, 000); glVertex2f( 1, 1); glColor3ub(000, 000, 255); glVertex2f( 1, -1); glColor3ub(255, 255, 000); glVertex2f(-1, -1); glEnd(); // Swap buffers (color buffers, makes previous render visible)
glutSwapBuffers(); // Increase angle to rotate
angle+=0.25; } // Initialze OpenGL perspective matrix
void GL_Setup(int width, int height) { glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glEnable( GL_DEPTH_TEST ); gluPerspective( 45, (float)width/height, .1, 100 ); glMatrixMode( GL_MODELVIEW ); } // Initialize GLUT and start main loop
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(window_width, window_height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("GLUT Example!!!"); glutIdleFunc(main_loop_function); GL_Setup(window_width, window_height); glutMainLoop(); }
|
五、在开始编译之前,我们还需要连接Glut库。选择你新建的C++ Project-->properties-->C/C++ Build-->settings,然后在右边GCC C++ Linker中找到Libraries,在libraries增加一项取名为GLUT,
然后在libraries search path添加路径为:/usr/include/GL。(默认gult等安装目录)
这样之后就可以开始project->build All。最后run的效果如下:
该教程PDF格式下载:
阅读(3989) | 评论(0) | 转发(0) |