opengl环境配置
工欲善其事,必先利其器。學習opengl必須要先搭建好開發(fā)環(huán)境,首先就從搭建環(huán)境開始。
查閱了不少資料,發(fā)現(xiàn)glfw是一個不錯的選擇,跨平臺,方便后續(xù)擴展,而且也支持原生的api。所以我們選用glfw庫來配置opengl開發(fā)環(huán)境。
?
下載地址:http://www.glfw.org/download.html
我下載的是?glfw-3.1.1。系統(tǒng)為mac osx 10.10. 如果在win下可以直接下載lib庫,vs中配置一下就可以了,在mac下需要自己下載源碼編譯安裝。
1.在glfw-3.1.1/src下找到glfw_config.h.in文件。打開后修改編譯參數(shù):
修改為:
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.a3.打開xcode創(chuàng)建一個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环境配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前天晚上的梦
- 下一篇: 向maven中央仓库提交jar