Got it compiling on macOS
This commit is contained in:
parent
0989efa30f
commit
1ee93ff0f0
|
@ -5,6 +5,9 @@ project(OpengGL_Example)
|
|||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT REQUIRED)
|
||||
|
||||
set( NAME_SRC
|
||||
main.cpp
|
||||
)
|
||||
|
@ -12,6 +15,10 @@ set( NAME_SRC
|
|||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
add_executable( opengl_example ${NAME_SRC} ${NAME_HEADERS} )
|
||||
|
||||
# Set executable dependency libraries
|
||||
# Equivalent to pass flags -lGL, -lGLU and -lglut
|
||||
target_link_libraries(opengl_example GL GLU glut)
|
||||
if (APPLE)
|
||||
# Equivalent to pass flags -framework OpenGL
|
||||
target_link_libraries(opengl_example OpenGL::GL GLUT::GLUT)
|
||||
else()
|
||||
# Equivalent to pass flags -lGL, -lGLU and -lglut
|
||||
target_link_libraries(opengl_example GL GLU glut )
|
||||
endif()
|
10
main.cpp
10
main.cpp
|
@ -1,6 +1,12 @@
|
|||
// http://www.codebind.com/linux-tutorials/install-opengl-ubuntu-linux/
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glut.h>
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/gl3.h>
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
void displayMe(void)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
// A simple introductory program; its main window contains a static picture
|
||||
// of a triangle, whose three vertices are red, green and blue. The program
|
||||
// illustrates viewing with default viewing parameters only.
|
||||
|
||||
#ifdef __APPLE_CC__
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
// Clears the current window and draws a triangle.
|
||||
void display() {
|
||||
|
||||
// Set every pixel in the frame buffer to the current clear color.
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Drawing is done by specifying a sequence of vertices. The way these
|
||||
// vertices are connected (or not connected) depends on the argument to
|
||||
// glBegin. GL_POLYGON constructs a filled polygon.
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1, 0, 0); glVertex3f(-0.6, -0.75, 0.5);
|
||||
glColor3f(0, 1, 0); glVertex3f(0.6, -0.75, 0);
|
||||
glColor3f(0, 0, 1); glVertex3f(0, 0.75, 0);
|
||||
glEnd();
|
||||
|
||||
// Flush drawing command buffer to make drawing happen as soon as possible.
|
||||
glFlush();
|
||||
}
|
||||
|
||||
// Initializes GLUT, the display mode, and main window; registers callbacks;
|
||||
// enters the main event loop.
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// Use a single buffered window in RGB mode (as opposed to a double-buffered
|
||||
// window or color-index mode).
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
|
||||
|
||||
// Position window at (80,80)-(480,380) and give it a title.
|
||||
glutInitWindowPosition(80, 80);
|
||||
glutInitWindowSize(400, 300);
|
||||
glutCreateWindow("A Simple Triangle");
|
||||
|
||||
// Tell GLUT that whenever the main window needs to be repainted that it
|
||||
// should call the function display().
|
||||
glutDisplayFunc(display);
|
||||
|
||||
// Tell GLUT to start reading and processing events. This function
|
||||
// never returns; the program only exits when the user closes the main
|
||||
// window or kills the process.
|
||||
glutMainLoop();
|
||||
}
|
Loading…
Reference in New Issue