Entorno de aprendizaje OpenGL para construir Clion + glfw + glad + mingw

Prólogo

En el aprendizaje opengl, glfw + glad es actualmente una combinación relativamente grande.
Si necesita glew + freeglut, también puede echar un vistazo a mi otro entorno openGL. En
esencia, es lo mismo que
Clion + glew + freeglut + mingw.

1. Descargar Library

alegre

Puede descargar la biblioteca usted mismo o usar la configuración en línea.
Aquí está la configuración en línea
contenta con la configuración en línea.
Seleccione las siguientes opciones de configuración
para asegurarse de que la versión API de opengl sea ​​compatible con 3.3 o más. La expansión del núcleo de
selección de modo no se puede seleccionar

Inserte la descripción de la imagen aquí

A continuación, generate obtendrá una descarga de archivo zip y descomprimirá para obtener include y src
Inserte la descripción de la imagen aquí

descargar glfw

Clfke
puede compilar glfw
o descargar la versión precompilada.
Descargamos la versión precompilada
Inserte la descripción de la imagen aquí

2. Configuración

1. Puede copiar el contenido de la carpeta de inclusión de glad en la carpeta de inclusión de glfw

Esto se puede incluir juntos

2. También puede volver a conectarse a una carpeta de inclusión

Agregue la ruta del archivo glad.c al proyecto a voluntad


cmake_minimum_required(VERSION 3.15)
project(C__test)

set(CMAKE_CXX_STANDARD 14)
link_directories("D:/computerGraph/glfw/lib-mingw-w64")
#1. glad的include和glfw的include文件夹合并了
include_directories("D:/computerGraph/glfw/include")
#2.glad的include文件夹另外设置 inlcude_directories("D:/computerGraph/glad/include")
# 添加 glad.c为可执行
add_executable(C__test main.cpp src/glad.c)
# 衔接库
target_link_libraries(C__test libglfw3.a)

3. Prueba

dirección de origen de learnopenGL

# 源码来源https://learnopengl.com/ 
#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <iostream>

void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);

// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;

int main()
{
    // glfw: initialize and configure
    // ------------------------------
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // glfw window creation
    // --------------------
    GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
    if (window == NULL)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

    // glad: load all OpenGL function pointers
    // ---------------------------------------
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;
    }    

    // render loop
    // -----------
    while (!glfwWindowShouldClose(window))
    {
        // input
        // -----
        processInput(window);

        // render
        // ------
        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
        // -------------------------------------------------------------------------------
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    // glfw: terminate, clearing all previously allocated GLFW resources.
    // ------------------------------------------------------------------
    glfwTerminate();
    return 0;
}

// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow *window)
{
    if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
        glfwSetWindowShouldClose(window, true);
}

// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
    // make sure the viewport matches the new window dimensions; note that width and 
    // height will be significantly larger than specified on retina displays.
    glViewport(0, 0, width, height);
}

4. Cuadro de prueba

Ligeramente

Referencias LearnOpenGL.com

22 artículos originales publicados · Me gusta2 · Visitas 881

Supongo que te gusta

Origin blog.csdn.net/weixin_41685373/article/details/104576808
Recomendado
Clasificación