raylib is a minimalist open-source library that is designed to be easy to use. It's written in C with support for multiple platforms, any platform that supports C and OpenGL graphics can run raylib. It's primarily used for game programming, but it's possible to use it in other applications. raylib language binding support over sixty programming languages. In the example below we will use C++ to create a simple window.
Create a main file called main.cpp
.
#include "raylib.h"int main() {InitWindow(800, 600, "My window");SetTargetFPS(60);while (!WindowShouldClose()){ClearBackground(BLACK);EndDrawing();}CloseWindow();return 0;}
Line 1: To create a window we need to include the raylib
library.
Line 3: The main
function is called at program startup and is the designated entry point to C++ programs. The int
denotes that the function will return an integer to the system.
Line 4: The Initwindow
function creates a window and takes as parameters the width, height, and title of the window.
Line 5: SetTargetFPS()
sets the maximum frame rate per second. Each system has different processing power so what we are doing here is stating the maximum frame rate we want for our program.
Line 6: This line starts an infinite loop that will continue to run until the user closes the window. The function WindowShouldClose()
lets you make use of the Windows close button or it listens out for the ESC key press.
Line 8: The ClearBackground
function clears the background of the window, and we set the window to black.
Line 9: This function EndDrawing()
is called to end the canvas drawing.
Line 11: CloseWindow()
— This closes the window safely. In the background, it turns off all the services that supported the game running
Line 12: We return 0
satisfying the int main
function.
Free Resources