Compilation
This table sums up which libraries you have to link against on Windows and Linux :
Linking options | Libraries to link against |
| On Windows | On Linux |
Static linking | libmygl.a | libmygl.a |
Dynamic linking | mygl.lib | libmygl.so |
In both | glfw3.lib, freetype.lib, opengl32.lib, gdi32.lib, user32.lib, shell32.lib, winmm.lib | libglfw3, libfreetype, libdl, libpthread |
Windows
TODO
Linux
The compilation process for a simple program should look something like this :
$ g++ -c prog.cpp
$ g++ prog.o -o prog -lmygl -lglfw3 -lfreetype -ldl -lpthread
This is assuming that the library was installed in a standard location, otherwise it would be :
$ g++ -c prog.cpp -I/path/to/include/folder/ -I/path/to/freetype/include/folder/ -I/path/to/glfw/include/folder/
$ g++ prog.o -o prog -lmygl -lglfw3 -lfreetype -ldl -lpthread -L/path/to/lib/folder/
- Note
- If you wish to link with the static version of the library, you should define the
MYGL_STATIC
macro when compiling, like this: g++ -c prog.cpp -DMYGL_STATIC
-
Usage
This library provides some abstraction over openGL to draw shapes and text, it also provides a way to create windows and an event system.
The following example program displays a magenta rectangle on a light green background
#include <MyGL/mygl.hpp>
int main() {
window.setFramerate(60);
rect.setColor(155, 32, 104);
while(window.isRunning()) {
while(window.pollEvent(e)){
switch(e.type)
{
window.close();
break;
if(e.keyCode == my::Key::escape) {
window.close();
}
break;
default:
break;
}
}
window.clear(clear_color);
window.draw(rect);
window.display();
}
return 0;
}
Class for storing color objects.
Class for creating rectangles.
Class for creating a window.
@ keyPressed
Event triggered when a key is pressed.
@ windowShouldClose
Event triggered when the user tries to close the window.
Struct for representing events and informations associated with them.
We first include the library
Then we create a 800 x 600 window with the title "my window!" and limit its framerate at 60 fps
- Warning
- You should create a window before using any of the library functions, as the library initialization happens in the window constructor
We create a rectangle using the Rectangle class, and set its color
rect.setColor(155, 32, 104);
Then comes the main loop, while the window is opened:
- We check if there are events that need to be processed :
while (window.pollEvent(e)) {
switch (e.type)
{
window.close();
break;
if (e.keyCode == my::Key::escape) {
window.close();
}
break;
default:
break;
}
}
Here we process the windowShouldClose
and keyPressed
events.
- The
windowShouldClose
event is triggered when the user tries to close the window, in our example if the user tries to close the window we effectively close it with a call to window.close()
.
- The
keyPressed
event is triggered when a keyboard key is pressed, here we close the window if the user presses the escape key.
- Then we clear the window with a background color and draw our rectangle :
window.clear(clear_color);
window.draw(rect);
- Finally we display everything that has been drawn with :