说明

基于glfw和glew进行开发配置。

下载安装库

下载32位glfw二进制包:https://www.glfw.org/download.html
下载glew二进制包:http://glew.sourceforge.net/
上面的两个包下载解压到一个固定目录。

VS2019配置

添加include目录

添加lib目录

添加附加依赖项

运行测试

生成一个窗口

#define GLEW_STATIC

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>

void processInput(GLFWwindow* window) {
    if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
        glfwSetWindowShouldClose(window, true);
    }
}

int main() {
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(800,600,"First Window",NULL,NULL);
    if (window == NULL)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    glewExperimental = true;
    if (glewInit() != GLEW_OK) {
        std::cout << "Failed" << std::endl;
        glfwTerminate();
        return -1;
    }
    glViewport(0, 0, 800, 600);

    while (!glfwWindowShouldClose(window)) {
        processInput(window);
        glClearColor(0, 0.5f, 0.5f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwTerminate();
    return 0;
}

参考

https://www.bilibili.com/video/BV11W411N7b9

Last modification:May 31st, 2020 at 11:24 pm