1. To prepare
1.1 Download GLFW library from GLFW official website
1.2 Glad library is generated online
2. The configuration
3. Run tests
4. Function list
glfwInit
glfwCrateWindow
glfwWindowShouldClose
glfwMakeContextCurrent
glfwSwapBuffers
glfwPollEvents
processInput
framebuffer_size_callback
I learn OpenGL, looking for multiple tutorials, clutter. Finally find a relatively complete English course, and find his Chinese translation version. (The author’s English is not very good, no way, alas ~)
Disclaimer: Although this article is original, it is indeed done according to the tutorial, the tutorial gives several methods, I chose the relatively simple, I believe everyone can learn, if you have questions can comment below.
Reference: LearnOpenGL
1. To prepare
1.1 Download GLFW library from GLFW official website
Download address: GLFW official website download page
Select the 32-bit binary version
1.2 Glad library is generated online
Generate address: Glad generates address online
Glad. Zip can be downloaded after generation.
2. The configuration
Unzip Glad. Zip and copy all files (Glad and KHR) to include folder under GLFW-3.2.1.bin. WIN32 after unzip.
Paste the glfw3.dll from lib-vc2015 under GLFW-3.2.1.bin. WIN32 into C:\ WindowsSYSWOW64. (The author’s version is VS2015, Windows is 64-bit, if the reader version is inconsistent, please change. C:\Window\System32: Windows \System32: Windows \System32: Windows \System32: Windows \System32: Windows \System32: Windows \System32
Create a new empty project under vs2015, paste the Glad. C file in the Glad folder into the source file and set up Main. CPP.
Right-click on the project and select Properties. In the VC++ directory, pull down and edit the include directory and library directory. Select the folder “include” and “lib-vc2015” under GLFW-3.2.1.bin. WIN32 respectively.
Linker – Input – Attach Dependencies – Edit Fill in the three filenames under lib-vc2015, note the line breaks.
To prevent readers from typing errors, paste the following:
glfw3.lib
glfw3dll.lib
opengl32.lib
At this point, the configuration is complete!
3. Run tests
Create a new empty project, place the glad.c file under the source file, and set main.cpp.
The code in the main.cpp file is 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);
}
Run the screenshot:
4. Function list
glfwInit
Parameters: no
Function: Initialize the GLFW library
glfwCrateWindow
Parameters: width, height, title, and the remaining two are NULL
Action: Create a form
glfwWindowShouldClose
Parameters: Forms
Action: Whether the form needs to be closed
glfwMakeContextCurrent
Parameters: Forms
Action: Create a form from the context
glfwSwapBuffers
Parameters: Forms
Function: Display the form
glfwPollEvents
Parameters: no
Function: Check the information returned by the operating system
processInput
Parameters: Forms
Function: keyboard key control, for example, press the Esc key to close the form
framebuffer_size_callback
Parameters: Forms
Action: A callback function that changes the form. The form changes accordingly.
More about OpenGL: Introduction to Modern OpenGL
Have a question please comment below, reprint please indicate the source, and attached to the original link, thank you! If there is infringement, please contact in time.
Read More:
- Vs2015 configuring OpenGL development environment: configuration of glfw library and glad Library
- Vs configuration of OpenGL development environment: configuration of glfw library and glad Library
- OpenGL, such as glad library and glfw library, is incompatible
- Vs2015 configuring OpenGL (glfw Library)
- Simple configuration of glfw + glad in vs2015 OpenGL development environment
- Configure OpenGL development environment (glfw3 + glad) once and for all with visual studio
- Configuration of OpenGL development environment under Windows environment, win10 + vs2019 + glfw + glad
- Vs2015 configuring OpenGL (glfw, glew)
- The solution of using OpenGL’s Glu Library in qt5.2 under win7
- |-OpenGL – | some small problems about the glut Library
- OpenGL class library and environment configuration under win10 and vs2015
- The tutorial and difference of glew, glfw, glad and freeglut
- Solve the problem of VC6.0 open crash and OpenGL glut32.lib library
- [learning opengl 22 step by step] – OpenGL importing 3D models with assimp Library
- Vs2013 + glfw + glew configure OpenGL development environment
- How to generate lib library with keil MDK and use lib Library
- Configuring OpenGL in VS
- The solution of configuring OpenGL in vs2017
- Error occurs when configuring nginx installation information. / configure: error: the HTTP rewrite module requires the PCRE library. You can
- Configuring OpenGL in Code:: blocks