A tutorial learning OpenGL reference is https://learnopengl-cn.github.io
this tutorial is based on GLFW (window) + glad (cross-platform), the following VS2015 a simple method of environment configuration:
1. New projects
Simply create an empty project and add a blank CPP file.
2. Add the Nupengl Core library
Add method: VS->; Tools – & gt; NUGET Package Manager -> Package management console
and then in the bottom of the Package management console input Install – Package nupengl. Enter the core instruction can
at this point, your this project has been configured glut GLFW glew
3. The configuration is glad
If you don’t need glad, you can skip this step, but glad is used in the tutorial above, so it should also be configured incidentally:
Open the Glad online service, set the Language to C/C++ and, from the API options, select OpenGL version 3.3 and above (we will use version 3.3 for this tutorial, but newer versions will work just fine). Generate
a
ader is selected. Generate
loader is selected. Generate
a
loader is selected. Ignore the Extensions for now (for now). When you have selected everything, click the Generate button to Generate the library files.
: Packages \nupengl. Core.0.1.0.1\build\native\include
: Packages \nupengl. Core.0.1.0.1\build\native\include
After these previous steps, the environment is actually configured
4. Test
#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);
}
If the configuration is successful, a window like
Read More:
- Configuration of OpenGL development environment under Windows environment, win10 + vs2019 + glfw + glad
- Vs configuration of OpenGL development environment: configuration of glfw library and glad Library
- Vs2015 configuring OpenGL development environment: configuration of glfw library and glad Library
- Configure OpenGL development environment (glfw3 + glad) once and for all with visual studio
- Vs2013 + glfw + glew configure OpenGL development environment
- Vs2015 OpenGL environment configuration
- Configuring glfw library and glad Library in opengl-vs2015
- Clion MinGW super fast configuration OpenGL development environment
- (64 bit) OpenGL configuration + vs2017 + glew + glfw
- OpenGL development environment configuration [vs2017] + common problems
- Configuring OpenGL development environment in win10 + vs2015 (including the method of installing 32-bit and 64 bit libraries)
- Problems encountered in configuring OpenGL development environment in vs2015
- A series of problems in configuring OpenGL development environment in vs2015
- Construction of vs2015 OpenGL configuration environment
- Configure OpenGL development environment (vs2015)
- On the configuration of OpenGL Red Book eighth edition environment in vs2013
- Problems encountered in vs2015 configuration using OpenGL environment
- The simplest way to configure OpenGL development environment with vs2015
- Vs2015 configuring OpenGL (glfw, glew)
- Vs2015 + OpenGL environment configuration