commit 590f456efff5335f04560984da7d9936296e9859 Author: mattmcw Date: Sat Mar 30 15:43:05 2024 -0400 Add the OpenGL example CMake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6faec16 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.9) + +project(OpengGL_Example) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_VERBOSE_MAKEFILE ON) + +add_executable(opengl_example main.cpp) + +# Set executable dependency libraries +# Equivalent to pass flags -lGL, -lGLU and -lglut +target_link_libraries(opengl_example GL GLU glut) + +# Add target to run executable +add_custom_target(run-ex1 + COMMAND opengl_example + DEPENDS opengl_example + WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} +) \ No newline at end of file diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..d22d9b6 --- /dev/null +++ b/compile.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +#gcc -o opengl_example main.cpp -lGL -lGLU -lglut -lm + +rm -rf build +mkdir -p build +cd build +cmake .. +make -j4 \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d32fe61 --- /dev/null +++ b/main.cpp @@ -0,0 +1,28 @@ +// http://www.codebind.com/linux-tutorials/install-opengl-ubuntu-linux/ +#include +#include + +void displayMe(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glBegin(GL_POLYGON); + glVertex3f(0.5, 0.0, 0.5); + glVertex3f(0.5, 0.0, 0.0); + glVertex3f(0.0, 0.5, 0.0); + glVertex3f(0.0, 0.0, 0.5); + glEnd(); + glFlush(); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE); + glutInitWindowSize(1920, 1080); + glutInitWindowPosition(0, 0); + glutCreateWindow("Hello world!"); + glutFullScreen(); + glutDisplayFunc(displayMe); + glutMainLoop(); + return 0; +} \ No newline at end of file diff --git a/opengl_example b/opengl_example new file mode 100755 index 0000000..8e750cd Binary files /dev/null and b/opengl_example differ