linux下基于eclipse的opengl开发环境搭建

转自:http://www.cnblogs.com/lycheng/archive/2011/09/13/2174831.html

1. 安装OpenGL相关工具

  sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev

其中,
libgl1-mesa-de 对应 GL库;
libglu1-mesa-dev对应GLU库 TJe opengl utility library;
freeglut3-dev 对应glut库
mesa-common-de :This package includes the specifications for the Mesa-specific OpenGL extensions, the complete set of release release notes and the development header files common to all Mesa packages.

2. 设置Eclipse
安装eclipse cdt插件
8.0.0 下载地址: http://www.eclipse.org/cdt/downloads.php


  Project -> properties -> C / C++ Build / Settings -> Tool Setting

  然后选择Cross G++ Linker 选择 Libraries, 在Libraries 中插入: glut GL GLU

                      在Libraries Search Paths 中插入: /usr/include/GL

3. 测试代码 example.cpp

#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();
return 0;
}


  Run All 之后, 会显示旋转的方型, 如果不需要IDE, 则可用命令行编译。


4. 命令行编译

  gcc example.cpp -o example -lglut -lGL -lGLU

  -o 表示输出的文件名

  -l 表示链接的库
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值