最近,計算機圖形學老師向咱們佈置了任務,配置本身的opengl。百度以後我發現不少教程和方法嘗試以後,我發現一種簡單的方法來分享給你們。php
首先個人軟件配置是w10專業版系統+Visual Stdio 2019社區版,通過實際測試vs2017社區版也能正經常使用。oop
第一種方法,vs2019默認安裝就行測試
-
VS2019建立C++控制檯程序,最好選擇空項目
spa
-
建立好了項目,點擊菜單欄的「項目」下的「管理Nuget程序包」
code
-
「瀏覽」下輸入
NupenGL
,兩個都點擊安裝orm
-
新建一個C++源文件
blog
-
輸入下面的代碼,運行F5。教程
-
#include <GL/glut.h> void Show() { glClear(GL_COLOR_BUFFER_BIT); glRectf(-0.1f, -0.1f, 0.5f, 0.5f); glFlush(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(800, 600); glutCreateWindow("OpenGL-ONE"); glutDisplayFunc(Show); glutMainLoop(); return 0; }
- 步驟正確,會出現以下圖案。
第二種方法。ip
- 下載OpenGL
- 打開網址:https://www.opengl.org/resources/libraries/glut/glut_downloads.php
- 找到標題爲 GLUT for Microsoft Windows 9X, ME, 2000, NT & XP users,下面有:
- If you want just the GLUT header file, the .LIB, and .DLL files all pre-compiled for Intel platforms, you can simply download the glutdlls37beta.zip file (149 kilobytes)。
- 點擊 glutdlls37beta.zip 便可下載。
- 配置OpenGL
- 將下載的 glutdlls37beta.zip 解壓可發現裏面包含 glut.dll glut32.dll glut.lib glut32.lib glut.h 5個文件。
- 而後找到vs2017安裝的目錄,路徑爲 (D:\Program)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include ,建立一個名爲gl的文件夾,並將解壓到的glut.h文件複製其中。
- 再找到路徑爲 (D:\Program)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\lib\x86 ,將解壓到的glut.lib,glut32.lib複製其中。
- 最後把解壓到的glut.dll和glut32.dll複製到C:\Windows\System32文件夾內(32位系統)或C:\Windows\SysWOW64(64位系統)。
- 測試和上面一種相同。