VS2015 + GLFW + HAPPY

OpenGL environment configuration of VS2015

A thousand miles begins with a single step. OpenGL learning environment built from the first start, environment configuration, first find out some basic concepts of OpenGL environment configuration. Implementation of OpenGL configuration environment only glfw, glad both to properly run the code, the latter need to re-add other libraries.

GLFW

Generation window, support oepngl context (windows, linux, mac), here mainly refers to cross-platform. Before the first is GLUT, after freeglut replace, the latest GLFW.

In other words, you do not have to install GLFW before installing an older version of glut, freeglut and so on. I point at GLFW , point me into GLFW official website document . GLFW get the source code, you need to configure cmake, point me into the cmake download .

cmake download code configuration into the installation process. FIG arranged as follows:
Here Insert Picture DescriptionCMake this note two things:

  • Browse Source put this source, the following Browse Buid this need for new build in the source directory folder, specify the path to build the project to generate, in order to avoid contamination source
  • After the first click configure button, Visual Studio configuration interface, choose to configure their own version of VS
  • The following Configure need to click twice, the first is the configuration, after the default configuration is red, click once in the default configuration is selected.

Click Generate to generate after the completion of the project, build file in the folder path to the source to find the corresponding project, this time with VS2015 open project, is already configured, click on build to build. Built, under the build src corresponding \ \ Debug directory to see the corresponding glfw3.lib library. At the same time there needs to be saved in the outer layer of the source include folder.

GLAD

GLAD is the second GL3W, GLEW, most current OpenGL specification interface used to access third-party libraries. Point I downloaded GLAD , GLAD configuration process is as follows:
Here Insert Picture Description
the next step to GLAD 's downloaded here need to choose their desired configuration, as there are versions of OpenGL, GLSL version, the core library or compatibility library, if it is, then the compatibility library , also need to select the features you need.
After selection, click Generate normal download, the source code can be saved.

There are two folders After the configurations: a include file folders, storage GLFW and GLAD header files, a lib folder, stored glfw.lib , glad there is a source file, you need to add to the next corresponding project directory.

Visual Studio 2015

Then on to VS2015 configuration section of the:

  • The first step, create a win32 console application
  • Next, click Empty Project, and take the next step
  • Create your own cpp a file in the source tree

This configuration work started

  • First, find the corresponding attribute test manager view, added.
    Here Insert Picture Description
  • Then right-click on the corresponding own project, for example, I was in this engineers Debug mode x64, so I'm in the corresponding Debug | x64 mouse right click, add the attribute list. The reason here to add rather than add in the project properties, is easy to facilitate post code portability.Here Insert Picture Description
  • Double-click to open the property sheet you just created, find VC ++ directory, in order to set include path and lib path for the earlier generation include and lib path.
    Here Insert Picture Description
  • Down General Properties -> Linker -> Input -> Additional Dependencies specified just generated glfw3.lib file.

Configuration property pages work has been completed.
Down the final step, the source added glad to sources directory of the current project.
Here Insert Picture Description
At this point, configuration and complete environment can be followed OpenGL code development work in LearnOpenGL file created.
Environmental test code as follows

#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);

#ifdef __APPLE__
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X
#endif

    // 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);
}

Guess you like

Origin www.cnblogs.com/gpu-insight/p/12112504.html