GLEW + GLFW 配置 OpenGL 開發環境

1、GLEW
2、GLFW
3、GLFW初體驗
4、GLEW+VS2010配置
5、GLEW | GLFW | OPENGL | MESA 3D

配置步驟

1、下載GLEW1.13.0和GLFW3.1.1
2、解壓,在其build的目錄下有v12等工程文件,打開,編譯,Debug版本可以得到glew32d.lib,如果是動態鏈接庫同時可以得到glew32d.dll。


3、解壓,使用CMake生成VS工程文件,打開,編譯項目,編譯靜態庫,得到glfw3.lib

4、測試GLFW環境,新建一個VS項目,命名爲glfwTtest,配置頭文件目錄,庫目錄,添加依賴庫glfw3.lib,opengl32.lib,測試代碼GLFW初體驗.

#include "glfw3.h"

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(480, 320, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Draw a triangle */
        glBegin(GL_TRIANGLES);

        glColor3f(1.0, 0.0, 0.0);    // Red
        glVertex3f(0.0, 1.0, 0.0);

        glColor3f(0.0, 1.0, 0.0);    // Green
        glVertex3f(-1.0, -1.0, 0.0);

        glColor3f(0.0, 0.0, 1.0);    // Blue
        glVertex3f(1.0, -1.0, 0.0);

        glEnd();

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

5、測試GLEW環境,新建項目glewTest,同樣配置頭文件目錄、庫目錄,添加庫glew32d.lib,項目使用glfw,所以添加庫glfw3.lib,測試代碼.


#include <stdio.h>
#include "glew.h"
#include "glfw3.h"

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(480, 320, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    if (glewInit() == GLEW_OK)
    {
        printf("glew init ok!\n");
    }

    printf("opengl version: %s\n", glGetString(GL_VERSION));

    while (!glfwWindowShouldClose(window))
    {

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();

    return 0;
}

6、完成.

附註

1、開發環境
軟件:Win7 + VS2013
硬件:Intel E3-1230 + Nivdia GeForece GTX 660
支持OpenGL4.5.0

2、GLEW和GLFW關係
GLEW和GLFW兩者之間並沒有什麼關係,在一些論壇上面也會有一些網友在問類似的問題,比如gamedev就有網友在詢問。
GLEW是爲了保證開發者能夠使用到更高級的OpenGL API而開發的類庫(3.2或者更高版本的)。
GLFW是一個窗口、鍵盤、事件管理的類庫,類似GLUT(GLUT比較舊了)。

備註:更加詳細的OpenGL相關工具組件和API

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章