Tag Archives: OpenGL configuration

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.

0028opengl program running prompt glut32.dll missing one of the solutions

From: http://blog.csdn.net/liufeng520/article/details/8064170
My question is exactly the same as above, so make a note of it for later review and reference.
Today debug OpenGl source program, compiled through, but a running tips, computer lost glut32. DLL files, not depressed, search under the Internet provide most of the practice are more, copying the file to download this file to C: \ WINDOWS \ system in 32, but did so after found that still doesn’t work, after a long afternoon, suddenly realized that may be about my new WINDOWS 7 system, but also for loading is 64 – bit, then, Try to copy this glut32.dll to your SysWOW64 folder in C:\ Windows, and it will all be OK. Here’s a special note to remind everyone who installed Windows 7 and VC ++ 6.0 to pay attention to it.
PS: just started contact with OpenGl will inevitably encounter some problems, these problems may has nothing to do with program, just some compile environment Settings and header files installed, adjusted in particular, are as follows:
(1) Copy gult32.dll, Glut. DLL to Windows system system32(if Windows 7 is a 64-bit operating system, it is in C:\ Windows SysWOW64 file)
(2) Copy gult32.lib, Glut. lib to VC lib directory
(3) Copy ULT. H to include\GL of VC

CodeBlocks configuring OpenGL environment

(1) Copy gult32.dll, Glut. DLL to Windows system system32(if Windows 7 is a 64-bit operating system, it is in C:\ Windows SysWOW64 file)
(2) Copy gult32.lib, Glut. lib to CodeBlocks\ MinGW\lib
(3) Copy ULT. H to VC under CodeBlocks\ MinGW\include\GL
You can set up a GLUT project, you can set up an OpenGL project, and you need to configure the build option. It’s best to include the Windows.h header file at the top of your code.
The required GLUT file downloads GLUT
Build option configuration