1. Download the required library (e.g. glad, glew, GLFW) and compile the binary file.
(1) Glad: https://glad.dav1d.de/. After entering, the Settings are as follows:
Language: c/c + +
Gl: version3.3
profile:core
Generate can be downloaded.
(2) glfw:https://www.glfw.org/download.html
The choice of 32-bit or 64-bit binaries depends on the system. I downloaded the 64-bit version and can also be used when debugging x86 (32) programs.
(3) the glew:http://glew.sourceforge.net/
Download the binaries.
My current configuration only uses Glad and GLFW, it should be similar for GLEW configuration.
2. Configure the environment
(1) Header file configuration
VC/Include: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
Glew /Include: VC/Include
There are two directories in the Glad folder Include: Glad and KHR, which are respectively copied under VC/Include;
Same thing with GLFW.
(2) lib file configuration
The glew lib Release folder contains two directories: Win32 and x64
Win32 lib files in VC/lib directory, x64 files in VC/lib/amd64 files.
This actually tells us that the compilation environment of glew is under Release, so if we use this library in the future, it is better to use Release debugging.
In addition, there is a bin file under glew. For VC, the bin directory is also divided into 32 bits and 64 bits. The default is 32 bits.
Put the Win32 files under bin into VC/bin, x64 into amd64.
Select the corresponding VS version lib file in the GLFW folder, I used VS2015, corresponding to lib-vc2015.
VC/bin/amd64: VC/bin/amd64: VC/bin/amd64: VC/bin/amd64 , glfw3.lib and glfw3dll.lib are placed under VC/lib and VC/lib/ AMD respectively.
3. The debugging
Create a new empty project and configure the lib file based on the project properties (32-bit/64-bit). (glfw3. Lib
Opengl32. Lib).
Change code generation to a multithreaded DLL (/MD).
Then, add the source file in the glad directory to the project, create a new source file, and write the following code:
#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 & lt; < “Failed to create GLFW window” < < std::endl;
GlfwTerminate ();
The return – 1;
}
GlfwMakeContextCurrent (Windows);
GlfwSetFramebufferSizeCallback (window, framebuffer_size_callback);
// Glad: Load all OpenGL function Pointers
// —————————————
If (! gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
STD: : cout & lt; < “Failed to initialize GLAD” < < std::endl;
The return – 1;
}
//render loop
// ———–
While (! glfwWindowShouldClose(window))
{
//input
// —–
ProcessInput (Windows);
//render
// ——
GlClearColor (0.2 f, f, 0.3 0.3 f, 1.0 f);
GlClear (GL_COLOR_BUFFER_BIT);
// GLFW: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// ——————————————————————————-
GlfwSwapBuffers (Windows);
GlfwPollEvents ();
}
// GLFW: terminate, clearing all 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 (Windows, 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
// The height will be significantly larger than specified on Retina displays.
GlViewport (0, 0, width, height);
}
4. The pit
If you are creating an x86 or x64 project, add glfw3.lib and opengl32.lib to the attached dependencies.
Second, for x86 projects, the VC library directory is VC/lib, so put the lib files in that directory. For x64 programs, the VC default library directory is VC/lib/ AMD, so if you want to debug under x64, also need to put the lib file in this directory, otherwise will appear can not find glfw3.lib file.
In particular, for debugging under X64 Debug, change the code generation for project properties to multithreaded DLLs (/MD).
In the process of configuration, I encountered a lot of problems, according to the above operation configuration, should avoid these chos.
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
- Simple configuration of glfw + glad in vs2015 OpenGL development environment
- Construction of vs2015 OpenGL configuration environment
- OpenGL environment configuration under VS2010 / vs2012 / vs2015
- OpenGL class library and environment configuration under win10 and vs2015
- Vs2015 + OpenGL environment configuration
- Problems encountered in vs2015 configuration using OpenGL environment
- On the configuration of OpenGL Red Book eighth edition environment in vs2013
- Vs2015 configuring OpenGL development environment: configuration of glfw library and glad Library
- OpenGL + vs2015 environment configuration problem solving
- Vs2013 + glfw + glew configure OpenGL development environment
- OpenGL environment configuration
- (64 bit) OpenGL configuration + vs2017 + glew + glfw
- Configure OpenGL development environment (vs2015)
- Clion MinGW super fast configuration OpenGL development environment
- OpenGL development environment configuration [vs2017] + common problems
- Visual studio 2019 + OpenGL environment configuration
- Configuring OpenGL development environment in win10 + vs2015 (including the method of installing 32-bit and 64 bit libraries)
- The simplest way to configure OpenGL development environment with vs2015