Add the OpenGL example CMake

This commit is contained in:
Matt McWilliams 2024-03-30 15:43:05 -04:00
commit 590f456eff
5 changed files with 57 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build

19
CMakeLists.txt Normal file
View File

@ -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}
)

9
compile.sh Normal file
View File

@ -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

28
main.cpp Normal file
View File

@ -0,0 +1,28 @@
// http://www.codebind.com/linux-tutorials/install-opengl-ubuntu-linux/
#include <GL/glew.h>
#include <GL/glut.h>
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;
}

BIN
opengl_example Executable file

Binary file not shown.