Mac Cmake OpenGL(Glut)
Main.cpp
#include <GLUT/glut.h> #include <cstdlib> /* for exit */ using namespace std; static void display() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glFlush(); } static void init() { glClearColor(1.0, 0.9, 0.65, 0.0); glColor3f(0.5,0.1, 0.1); } static void keyboard(unsigned char key, int x, int y) { switch(key) { case 'q': case 'Q': case 27: // ESC key exit(0); break; } } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(0,0); glutCreateWindow("template"); glutDisplayFunc(display); glutKeyboardFunc(keyboard); init(); glutMainLoop(); return 0; }
CMakeLists.txt
cmake_minimum_required (VERSION 2.6) project(OpenGL) find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIR}) find_package(GLUT REQUIRED) include_directories(${GLUT_INCLUDE_DIR}) set(CMAKE_CXX_FLAGS "-g -Wall") add_executable(OpenGL Main.cpp) target_link_libraries(OpenGL ${GLUT_LIBRARY} ${OPENGL_LIBRARY})
在Main.cpp 和 CMakeLists.txt所在目录 打开终端 依次执行
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make
./OpenGL
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。