首页 > 代码库 > Mac Cmake OpenGL(Glut)
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
Mac Cmake OpenGL(Glut)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。