日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opengl环境配置

發布時間:2025/3/14 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opengl环境配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

工欲善其事,必先利其器。學習opengl必須要先搭建好開發環境,首先就從搭建環境開始。  

查閱了不少資料,發現glfw是一個不錯的選擇,跨平臺,方便后續擴展,而且也支持原生的api。所以我們選用glfw庫來配置opengl開發環境。

?

下載地址:http://www.glfw.org/download.html

我下載的是?glfw-3.1.1。系統為mac osx 10.10. 如果在win下可以直接下載lib庫,vs中配置一下就可以了,在mac下需要自己下載源碼編譯安裝。

1.在glfw-3.1.1/src下找到glfw_config.h.in文件。打開后修改編譯參數:

修改為:

  

1 // Define this to 1 if building GLFW for X11 2 #cmakedefine _GLFW_X11 3 // Define this to 1 if building GLFW for Win32 4 #cmakedefine _GLFW_WIN32 5 // Define this to 1 if building GLFW for Cocoa 6 #cmakedefine _GLFW_COCOA 1 7 // Define this to 1 if building GLFW for Wayland 8 #cmakedefine _GLFW_WAYLAND 9 // Define this to 1 if building GLFW for Mir 10 #cmakedefine _GLFW_MIR 11 12 // Define this to 1 if building GLFW for EGL 13 #cmakedefine _GLFW_EGL 1 14 // Define this to 1 if building GLFW for GLX 15 #cmakedefine _GLFW_GLX 16 // Define this to 1 if building GLFW for WGL 17 #cmakedefine _GLFW_WGL 18 // Define this to 1 if building GLFW for NSGL 19 #cmakedefine _GLFW_NSGL 20 21 // Define this to 1 if building as a shared library / dynamic library / DLL 22 #cmakedefine _GLFW_BUILD_DLL 23 24 // Define this to 1 if glfwSwapInterval should ignore DWM compositing status 25 #cmakedefine _GLFW_USE_DWM_SWAP_INTERVAL 26 // Define this to 1 to force use of high-performance GPU on Optimus systems 27 #cmakedefine _GLFW_USE_OPTIMUS_HPG 28 29 // Define this to 1 if the XInput X11 extension is available 30 #cmakedefine _GLFW_HAS_XINPUT 31 // Define this to 1 if the Xxf86vm X11 extension is available 32 #cmakedefine _GLFW_HAS_XF86VM 33 // Define this to 1 if glXGetProcAddress is available 34 #cmakedefine _GLFW_HAS_GLXGETPROCADDRESS 35 // Define this to 1 if glXGetProcAddressARB is available 36 #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSARB 37 // Define this to 1 if glXGetProcAddressEXT is available 38 #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT 39 // Define this to 1 if dlopen is available 40 #cmakedefine _GLFW_HAS_DLOPEN 41 42 // Define this to 1 if glfwInit should change the current directory 43 #cmakedefine _GLFW_USE_CHDIR 44 // Define this to 1 if glfwCreateWindow should populate the menu bar 45 #cmakedefine _GLFW_USE_MENUBAR 46 // Define this to 1 if windows should use full resolution on Retina displays 47 #cmakedefine _GLFW_USE_RETINA 48 49 // Define this to 1 if using OpenGL as the client library 50 #cmakedefine _GLFW_USE_OPENGL 51 // Define this to 1 if using OpenGL ES 1.1 as the client library 52 #cmakedefine _GLFW_USE_GLESV1 53 // Define this to 1 if using OpenGL ES 2.0 as the client library 54 #cmakedefine _GLFW_USE_GLESV2 1

2.打開終端 cd 到?glfw-3.1.1 到目錄,依次輸入:

cmake .sudo make install

安裝過程中可能需要輸入密碼,安裝完畢后顯示:

-- Installing: /usr/local/include/GLFW -- Installing: /usr/local/include/GLFW/glfw3.h -- Installing: /usr/local/include/GLFW/glfw3native.h -- Installing: /usr/local/lib/cmake/glfw/glfwConfig.cmake -- Installing: /usr/local/lib/cmake/glfw/glfwConfigVersion.cmake -- Installing: /usr/local/lib/cmake/glfw/glfwTargets.cmake -- Installing: /usr/local/lib/cmake/glfw/glfwTargets-noconfig.cmake -- Installing: /usr/local/lib/pkgconfig/glfw3.pc -- Installing: /usr/local/lib/libglfw3.a

3.打開xcode創建一個osx命令行項目,在Build Settings中設置好剛編譯好的libglfw的安裝目錄/usr/local/lib/;然后在Build Phases中添加

  IOKit.framework,Cocoa.framework,OpenGL.framework,libglfw3.a

4.修改main.cpp為:

// // main.cpp // hello_glfw // // Created by lukey.liu on 15/3/21. // Copyright (c) 2015年 cn.wing. All rights reserved. // #include <GLFW/glfw3.h>int main(int argc, const char * argv[]) {if (!glfwInit()) {return -1;}GLFWwindow* window = glfwCreateWindow(640, 480, "Hello opengl for GLFW", NULL, NULL);if (!window) {glfwTerminate();return -1;}glfwMakeContextCurrent(window);while (!glfwWindowShouldClose(window)) {glBegin(GL_TRIANGLES);glColor3f(1.0, 0.0, 0.0); // RedglVertex3f(0.0, 1.0, 0.0);glColor3f(0.0, 1.0, 0.0); // GreenglVertex3f(-1.0, -1.0, 0.0);glColor3f(0.0, 0.0, 1.0); // BlueglVertex3f(1.0, -1.0, 0.0);glEnd();glfwSwapBuffers(window);glfwPollEvents();}glfwTerminate();return 0; }

運行就能看到一個名為Hello opengl for GLFW的窗口,顯示一個三角形

?

轉載于:https://www.cnblogs.com/Slukey/p/4357060.html

總結

以上是生活随笔為你收集整理的opengl环境配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。