Skip to content
TechnologicalTurtle edited this page Jul 15, 2026 · 15 revisions

LibGui::Window

LibGui::Window is a wrapper for GLFWwindow*, there are two ways to initialize it:

Initialization

Initilization window

This is the first window you create using the Init() method, it's also default window for all Objects (and other classes).

//                                 initialize library| name of window   | size of window
LibGui::Window MyInitializationWindow(LibGui::Init(), "My Initialization window",{600, 400});

but why?!

Normal window

All windows after creation of Initialization window should be made this way.

//                              name of window  |  size of window
LibGui::Window MyNormalWindow("My normal window", {600, 400});

Properties

Property Description
MouseCursor cursor handles mouse input for this window
KeyTracker key_tracker tracks key states for some keys; more here/KeyTracker
Color background_color specifies background color of this window
float transparency transparency of whole window (including rendered content)
bool CanAutoClose can window automatically close once user pressed [X]?
Vec2i size [READ-ONLY] ...current size of this window

Methods

bool GetKeyPressed(...)

Quick way to know is given key is pressed. (for more click and release properties see KeyTracker)
Examples

MyWindow.GetKeyPressed('w'); // is key W pressed?
MyWindow.GetKeyPressed(FunctionalKey_RightShift); // is right shift pressed?

void Draw()

Tells program to now render on this window, it also updates the window (input handling, window movement).
Example

while (true)
{
   // start rendering here
   MyWindow.Draw();

   // render our beloved square [reference to Getting started]
   MySquare.Render();

   // now he has friend
   MyAnotherSquare.Render(); 

   // push render to screen (for another rendering you have to call MyWindow.Draw(); again)
   MyWindow.PushDraw(); 
}

void PushDraw()

Tells program to send our since-last-Draw() rendered stuff to screen.
For example see Draw() example. (I don't want to just copy the code)

bool ShouldClose()

If user pressed [X] button (or on other events such as Close() call), returns true, else it returns false.
Example

while (!MyWindow.ShouldClose())
{
   std::cout << "I'm alive!\n";
}
std::cout << "I... was sadly closed :(  \n";
std::cin.get();

void Close()

Closes the window, next ShouldClose() call will return true. Example

MyWindow.Close(int flags);

void Reflag()

Updates init flags to new flags. See more here

void SetIcon(LibGui::Image img, bool clamp = true)

Set window icon to LibGui::Image 'img'; 'clamp' the icon must be square, so should cut or squeeze 'img' to fit.

LibGui::Image MyTurtleImage("square_turtle_logo.png");
MyWindow.SetIcon(MyTurtleImage);

LibGui::Image Screenshot(bool transparent = false)

Returns literal screenshot of last render. transparent means if transparent parts of that render will remain transparent (this includes final image not having window background).
Example

LibGui::Image MyScreenshot = MyWindow.Screenshot();

void Bind()

Binds current window. You probably won't need this. It's wrapper for glfwMakeContextCurrent

Init flags

At window creation, you can tell it how to behave by setting WIF (window init flags). To create them you just or together stuff from WindowInitFlag_ enum.

LibGui::MyUnresizableWindow("window", {200, 100}, LibGui::WindowInitFlag_CantBeResized);

Why has first window to be initialized so weirdly?

The Init() function must (along other stuff), initialize two OpenGL libraries, one of them is called glad. But to initialize glad you have to already have created a window, I solve this by making this window, initializing glad and then passing this GLFWwindow* to user, who has to, to have access to this window, create it with this dumb syntax:

LibGui::Window MyInitializationWindow(LibGui::Init(), "My Initialization window",{600, 400});

Clone this wiki locally