码迷,mamicode.com
首页 > 系统相关 > 详细

Mac Cmake OpenGL(Glut)

时间:2014-11-02 13:52:48      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:blog   io   color   ar   os   for   sp   on   2014   

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)

标签:blog   io   color   ar   os   for   sp   on   2014   

原文地址:http://blog.csdn.net/pyang1989/article/details/40708885

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!