zoukankan      html  css  js  c++  java
  • Eclipse 使用OpenGL

    主要参考:http://blog.csdn.net/sdlgxxy/article/details/6225267 

    一,下载openGL的相关文件,下载地址为http://download.csdn.net/source/3063599

    OpenGL库配置用到的文件分为下面三类:

    ■ 动态链接库文件(.dll)

    glaux.dll、glu32.dll、glut32.dll、opengl32。

    ■ 头文件(.h)

    GL.H、GLAUX.H、GLU.H、glut.h。

    ■ 库文件(.lib)

    GLAux.Lib、Glu32.lib、glut32.lib、OpenGL32.Lib。

    3、配置上述文件

    1)将dll文件拷贝到c:/windows/System32下面【如果自己的机子是64位的系统,需要把.dl文件放到c:?windows/SysWOW64下】

    2)h文件放到${minGW}/include/GL文件加下,如果没有GL文件夹,新建一个。[此处的mingw是eclipse所使用的编译器目录]

    3)库文件放在MinGW的lib

    4、打开Eclipse,新建一个C或C++项目,选择的编译器选项应该为MinGW,而不是Goorss,如下:

    ,首先可以先写个HelloWorld验证Eclipse环境是否正常。

    5)如果可以的话,将下来可以新建一个C++项目来进行OpenGL测试,代码如下:

    #include <windows.h>
    #include <GL/gl.h>
    #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!!!");
        glutDisplayFunc(main_loop_function);
        GL_Setup(window_width, window_height);
        glutMainLoop();
    }

    此时还不能直接运行,因为编译时不能找到我们添加的库,需要静态添加

    在项目上,右键点击选择Properties,进如下图配置页面,按如下所示配置,注意不要改动,

    配置到这一步之后,重新编译项目,如果你按照我上面的步骤操作的话应该能编译成功了。

  • 相关阅读:
    Android之SQLite分页读取
    android 对sqlite数据库的增删改查
    Android如何导入已有的外部数据库(在raw下自己导入db文件)
    Android自定义对话框(Dialog)位置,大小
    android UI进阶之实现listview中checkbox的多选与记录
    Android开发教程 数据存储 SQLite
    Android 中的ORM框架
    android错误信息大整理
    C#中导出Execl
    关于用户退出,点击浏览器后退仍可回到原来页面解决二
  • 原文地址:https://www.cnblogs.com/kinthon/p/4841348.html
Copyright © 2011-2022 走看看