Tag Archives: GLAD to configure

Configuring glfw library and glad Library in opengl-vs2015

directory
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

GLFW library download

 
1.2 Glad library is generated online
Generate address: Glad generates address online

Glad online generation

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.
    

The copied include folder

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

Under the SysWOW64 glfw3. DLL

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.

Source files under the HelloIndow project

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.

HelloIndow project property Settings

Linker – Input – Attach Dependencies – Edit Fill in the three filenames under lib-vc2015, note the line breaks.

Additional dependencies

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:

Opengl form

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.