opengl中gpu与cpu交互_OpenGL 环境配置与教程推荐
我們先了解一下 OpenGL 是什么:
摘自 Wikipedia:
Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.總的來說,OpenGL 就是一個應用程序接口(API),用來幫助我們與GPU交互,來使用硬件加速渲染圖形。OpenGL只是一個規范,不同的顯卡廠商有不同的實現,但這無關緊要,只要用起來相同就行了。值得一提的是,OpenGL 是無需下載的,系統里已經有這個庫了(opengl32.lib, opengl64.lib for Windows)。如果你已經很久沒更新顯卡驅動,我建議你去更新至最新的穩定版。
In all three major desktop platforms (Linux, macOS, and Windows), OpenGL more or less comes with the system.但是,只有 OpenGL 是不夠的,原因大致有二:
GLFW 就是我們所需要的所謂的“更高層次的封裝”,下面將介紹其配置。
GLFW (Graphics Library Framework)
摘自 Wikipedia:
GLFW is a lightweight utility library for use with OpenGL. GLFW stands for Graphics Library Framework. It provides programmers with the ability to create and manage windows and OpenGL contexts, as well as handle joystick, keyboard and mouse input.如你所見,GLFW 是一個圖形庫框架。當然我們也有其他選擇,但這個教程多一些,遇到問題好解決 O(∩_∩)O。
廢話不多說,我們去官網下載當前的最新穩定版 3.3 https://www.glfw.org/download.html ,選擇 32-bit Windows binaries,我們這里就直接下別人編譯好的,不再自行從源碼編譯了。如果你選擇了64-bit 的二進制包,請注意你將來的程序將不能在 32 位的系統上運行。
運行 OpenGL 程序
3. 打開Project的屬性頁面,注意不是Solution的屬性頁面
注意,這里有一個坑,我們需要先在項目中添加一個C++文件,空的就行,不然下圖中你是找不到C/C++選項的。
添加 include 文件夾;注意選擇 All Configuration 和 All Platforms添加 lib 文件夾4. 測試是否成功,將以下代碼復制進你的項目:
#include <GLFW/glfw3.h>int main(void) {GLFWwindow* window;/* Initialize the library */if (!glfwInit())return -1;/* Create a windowed mode window and its OpenGL context */window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);if (!window){glfwTerminate();return -1;}/* Make the window's context current */glfwMakeContextCurrent(window);/* Loop until the user closes the window */while (!glfwWindowShouldClose(window)){/* Render here */glClear(GL_COLOR_BUFFER_BIT);/* Swap front and back buffers */glfwSwapBuffers(window);/* Poll for and process events */glfwPollEvents();}glfwTerminate();return 0; } 程序成功運行的界面教程推薦:
注意:
參考:
PS. Visual Studio 2019 + Glut 3.7 極簡配置教程
2. 將glut.h文件復制進Visual Studio的include目錄下的gl文件夾內,注意需要自己創建gl文件夾。參考路徑:
D:OthersMicrosoft Visual Studio2019CommunityVCToolsMSVC14.22.27905include3. 將glut.lib 和glut32.lib 文件復制進Visual Studio的lib目錄下的x86文件夾內。參考路徑:
D:OthersMicrosoft Visual Studio2019CommunityVCToolsMSVC14.22.27905libx864. 將glut32.dll 文件復制進以下目錄:
C:WindowsSysWOW645. 打開 Visual Studio,創建一個空項目,在 Solution Explorer中 對項目名右鍵,選擇 Manage NuGet Packages,點擊瀏覽搜索 nupengl,下載以下兩個包即可:
6. 使用以下代碼檢驗你的配置是否成功:
#include <Windows.h> #include <stdio.h> #include <GL/glut.h>int main(int argc, char** argv) {glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(300, 300);glutCreateWindow("OpenGL");printf("OpenGL version: %sn", glGetString(GL_VERSION));return 0; }7. 參考 / :
- https://www.cnblogs.com/flylinmu/p/7823019.html
- https://en.wikipedia.org/wiki/NuGet
- https://docs.microsoft.com/en-us/nuget/what-is-nuget
教程推薦
JustSong:【譯】OpenGL 教程:二維圖形繪制?zhuanlan.zhihu.com總結
以上是生活随笔為你收集整理的opengl中gpu与cpu交互_OpenGL 环境配置与教程推荐的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: debian编译mysql_MySQL数
- 下一篇: sqlsourcesafe mysql_