Skip to content

Window system

Merijn Hendriks edited this page Mar 18, 2019 · 14 revisions

About

A simple window system.

Information

You can have only 1 window.

Dependencies

  • glad (c/c++, opengl 3.3, core profile, generate loader)
  • glfw 3.2.1
  • automata_const.h
  • automata_input.h

OpenGL

The window system uses glad as OpenGL loader.

The window has an OpenGL context. The OpenGL version of this context is defined in automata_const.h:

#define AUTOMATA_OPENGL_VERSION_MAJOR 3
#define AUTOMATA_OPENGL_VERSION_MINOR 3

Definition

All window structs and functions are defined in automata_window.h.

Structures

struct AutomataWindow {
    GLFWwindow *window;
    unsigned int width;
    unsigned int height;
    const char *title;
    AutomataWindowMode mode;
};

Internal use only. The window structure. window: the GLFW window. width: the window width. height: the window height. title: the window title.

Functions

void automataWindowInit()

Initializes the window system.

void automataWindowCreate(unsigned int width, unsigned int height, const char *title)

Creates the window. width: the window width. height: the window height. title: the window title.

void automataWindowClose()

Closes the window.

void automataWindowTerminate();

Terminates the window system.

int automataWindowIsAlive()

Returns if the window is alive.

void automataWindowUpdate()

Updates the window.

unsigned int automataWindowGetWidth()

Returns the current window width.

unsigned int automataWindowGetHeight()

Returns the current window height.

const char *automataWindowGetTitle()

Returns the current window title.

AutomataWindowMode automataWindowGetMode()

Returns the window mode.

void automataWindowSetTitle(const char *title)

Changes the window title. title: the new window title

void automataWindowSetSize(unsigned int width, unsigned int height)

Resizes the window. width: the new window width. height: the new window height.

void automataWindowSetMode(AutomataWindowMode mode)

Sets the window mode. mode: the window mode. If it is an invalid value, it is set to AUTOMATA_WINDOW_MODE_UNKNOWN.

Callbacks

void automataWindowCallbackResize(GLFWwindow* glfwWindow, int width, int height)

Internal use only. Called when a window is resized.

Examples

#include <stdio.h>
#include <stdlib.h>
#include "automata_const.h"
#include "automata_window.h"

int main() {
	/* intialize application */
	automataWindowInit();
	automataWindowCreate(1280, 720, "Automata Engine");

	/* application loop */
	while (automataWindowIsAlive()) {
		automataWindowUpdate();
	}

	/* terminate application */
	automataWindowTerminate();
	return EXIT_SUCCESS;
}

Creates and updates the window until it needs to close.

Clone this wiki locally