OpenGL Development Environment Setup with GLEW and FreeGLUT in CLion with Linux Nov 4th 2020 Words: 134

Install GLEW and FreeGLUT library

Debian/Ubuntu:

1
sudo apt install libglew-dev freeglut3-dev

Example project

Create a new project in CLion.

CMakeList.txt
1
2
3
4
5
6
7
8
9
10
cmake_minimum_required(VERSION 3.17)
project(test_app)

set(CMAKE_CXX_STANDARD 14)

set(OpenGlLinkers -lGLEW -lglut -lGLU -lGL)

add_executable(test_app main.cpp)

target_link_libraries(test_app ${OpenGlLinkers})
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <GL/glew.h>
#include <GL/glut.h>

void helloWorld();

int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(320, 320);
glutCreateWindow("Hello World");
glutDisplayFunc(helloWorld);
glutMainLoop();
return 0;
}

void helloWorld() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glVertex3f(-0.5, -0.5, 0.0);
glVertex3f(0.5, -0.5, 0.0);
glVertex3f(0.0, 0.5, 0.0);
glEnd();
glutSwapBuffers();
}

The above app should draw a triangle on the app screen.