Simple configuration of openGL library

It is mainly for some preliminary learning of openGL, because openCV mainly processes images and videos, and obtains data from existing ones, while openGL seems to draw from data, so learn about it. In the book "Computer Graphics Programming", it defines graphics programming as shader programming. Compared with C/C++, it can be said to be two kinds of bright lines. C/C++ needs to be tuned by the compiler in the later stage. It is estimated that The same is true for graphics programming, which needs to be targeted at shaders, but for now, learn its use first.

The openGL (Open Graphics Library, Open Graphics Library) here is said to be a platform-independent graphics programming library. Many people now refer to it as a standard, a specification, and I am not sure.

Window management, GLFW

In openGL, images are rendered to a framebuffer, and the machine is responsible for drawing the contents of the framebuffer. There are GLUT libraries, CPW libraries, GLOW libraries, and GLUI libraries that can do this kind of work, but GLUT is too old and has evolved into freeglut. The GLFW window management library is selected here, which needs to be compiled and installed. Because glfw is compiled and installed, it is better to install cmake first, and download msi directly from the official website to install it.

cmake download path

Because the installer can help you add environment variables, so I don’t bother to restart the computer, and now I can restart without restarting. After the installation is complete, test to see if the environment variables have been configured, cmake --versionand if it can respond successfully, it is ok.

Then download the compilation and installation package of glfw:

GLFW official website

From the information I found, many openGL libraries are relatively old, so this is also used for learning. I don’t know when this link will become invalid, so use it and cherish it. After downloading, decompress normally, and then enter the corresponding glfw folder to compile and install.

After opening the cmake GUI, drag the cmake list of GLFW to it, and then configure it. After setting the custom parameters, if the highlight is configured, it will start to generate; the work of cmake is up to this step, and the next step is vs. It’s working, go to the compiled file, open the GLFW.sln file with vs, and then check the debug and release options of ALL BUILD and INSTALL under batch generation, one is the debug mode and the other is the release mode. After the two compilation modes are selected, it will be Start generating. At this point, there are two corresponding libs under src. Then the GLFW environment is configured here.

Extension library, GLEW

In openGL, there are basic functions and extension mechanisms, and the extension mechanism belongs to a custom content to support new functions. In fact, this is aimed at modern commands in openGL. The execution of these commands requires a certain amount of code, and it has become a standard practice to use extension libraries to handle these details. GLEW (OpenGL Extension Wrangler), openGL extension wrangler, but there are alternatives, such as GL3W and GLAD, which can be updated automatically, but need python support. Back to the topic, GLEW needs to download the compressed package from sourceforge to get the corresponding glew32.lib and glew32.dll and the corresponding header files. The link is as follows:

GLEWDOWNLOAD

In fact, it is the official website, and there is a link to jump to sourceforge on it, and the auto select is also very fast. However, the update of this version is also absolutely perfect, in 2007, huh, huh.

Math library, GLM

3D graphics programming requires extensive use of vector and matrix algebra (it seems to be reviewed), and a function library and class package for common mathematical calculation tasks is very important. The common ones are Eigen and vmath, but the math library GLM (OpenGL Mathematics) is used here. Install Baidu GLM directly, and then it jumps to the sourceforge page, so let’s get it done here, okay, get the compressed package. After opening, it is actually a cmakelist package, but there is also a corresponding hpp file under glm, so I still don’t do it for the time being.

Texture Image Loading Library, SOIL2

SOIL2 is an updated and forked version of the image loading library SOIL. The things here are really too old, and I don’t seem to want to use it if I am not learning. Let's make a detailed record here.

The first is to download and install the premake4 of the installation software

premake4 download page

After the download is complete, download the SOIL2 project file. Originally, the habit of github is to publish the file and release it. It’s good, there is nothing directly linked, okay, git clone.

After cloning, unzip the premake5.exe executable file to this folder, then right-click to open the command line, and enter ./premake5.exe vs2022, because I have not configured environment variables for premake, so I proceed in this way, and my vs version is 2022, after finishing You can see the following:

PS D:\source code\SOIL2-master> ./premake5.exe vs2022
Building configurations...
Running action 'vs2022'...
Generated make/windows/SOIL2.sln...
Generated make/windows/soil2-static-lib.vcxproj...
Generated make/windows/soil2-shared-lib.vcxproj...
Generated make/windows/soil2-test.vcxproj...
Generated make/windows/soil2-test.vcxproj.filters...
Generated make/windows/soil2-perf-test.vcxproj...
Generated make/windows/soil2-perf-test.vcxproj.filters...
Done (74ms).
PS D:\source code\SOIL2-master>

Then it's time for vs again, open the sln file in vs in the path below
insert image description here

Then right-click to select the soil2-static-lib option, right-click to generate, and you can get the lib file.
insert image description here

At present, the main use is the header file in the SOIL2 folder under src and the newly generated soil2-debug.lib library file (you can find it in the newly generated lib folder).

Configure the openGL library folder

In fact, for the convenience of vs, the above header files and library files are specially gathered together, and a special directory is customized to create a new include and lib folder. Then copy the corresponding header folder above, and copy the library files.
include folder: GLFW folder, GL folder, glm folder, SOIL2 folder;
lib folder: glfw3.lib, glew32.lib, soil2-debug.lib
You can also put the glew.dll file of GLFW in the above two Paths at the same level, and then make up a basic openGL library structure.
insert image description here
But I seem to have made a mistake. When I actually operated vs for a small experiment, I found that even if the above header file was introduced, vs could not recognize it. It was a strange circle, so rubbish. There is no way, but based on the experience of the predecessors, put it in the include and lib directories corresponding to vs.

Because even if vs customizes the installation directory, it still puts a lot of things on the c drive. There is no way to do this, it is linked to your user directory. The way I find the built-in include of vs is to directly enter #include, then follow the software prompts to enter the header file, and then right-click to open the folder of the header file, the path is there, and it is easy to handle.

Then copy all the folders (GL, GLFW, glm, SOIL2) under my previous include folder, as well as those under lib, and you can find it with a good path relationship. It is relatively simple. My vs2022 here The corresponding two built-in paths are:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64

Well, there is still a dynamic library to be configured, so just put it directly in the project folder, just a glew.dll.

simple test

#include <GL/glew.h>
#include <glfw/glfw3.h>
#include <iostream>
#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "glfw3.lib")
//作为标准提供在windows SDK中,但需要引入
#pragma comment(lib, "opengl32.lib")

using namespace std;

//绘制window窗体内容
void display(GLFWwindow *window, double currentTime) {
    
    
	//绘制红色背景
	glClearColor(1.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);
}

int main() {
    
    

	//初始化GLFW库
	if (!glfwInit())
		exit(EXIT_FAILURE);

	//创建GLFW窗口和相关openGL上下文,并指定机器主次版本兼容openGL4.3
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);

	//创建一个宽高都为600像素的标题为none的、后面两个参数设置全屏显示和资源共享,暂时用NULL参数替代
	GLFWwindow *window = glfwCreateWindow(600, 600, "none", NULL, NULL);
	//把windows对象和当前openGL上下文相关联
	glfwMakeContextCurrent(window);

	//初始化GLEW库
	if (glewInit() != GLEW_OK)
		exit(EXIT_FAILURE);
	//开启垂直同步
	glfwSwapInterval(1);

	//简单的渲染循环
	while (!glfwWindowShouldClose(window)) {
    
    
		display(window, glfwGetTime());
		//绘制屏幕
		glfwSwapBuffers(window);
		//等待事件的处理,比如按键点击退出
		glfwPollEvents();
	}

	//逐一操作以释放窗口对象
	glfwDestroyWindow(window);
	glfwTerminate();
	exit(EXIT_SUCCESS);
}
//openGL上下文,openGL实例及状态信息等,包括颜色缓冲区等

Because glew.dll has been placed in the project path in advance, there is basically no problem, and a red window will appear after running.

small broken station

Guess you like

Origin blog.csdn.net/weixin_44948269/article/details/127844899