GGe Documentation

A Good Game Engine



Constructor

Window(const char* name, int width, int height, bool fullScreen = false);
Example code:
  • Define Resolution
  • Window* window = CreateWindow("My Game", 1920, 1080);
  • Full Screen
  • Window* window = CreateWindow("My Game", 1920, 1080, true);

    Methods

    IsClosed

    Returns a boolean depending on the state of the window. Example: returns false if the Window has closed.

    bool IsClosed();
    Example code:
    Window* window = CreateWindow("GG Engine", 1920, 1080);
    while (!window->IsClosed()) {
    // Do Something
    }

    WindowClear

    Clears the window ready for the next update.

    void WindowClear();
    Example code:
    Window* window = CreateWindow("GG Engine", 1920, 1080);
    while (!window->IsClosed()) {
    window->WindowClear();
    }

    Window Update

    Updates the window with any new draw calls.

    void WindowUpdate();
    Example code:
    Window* window = CreateWindow("GG Engine", 1920, 1080);
    while (!window->IsClosed()) {
    window->WindowClear();
    window->WindowUpdate();
    }

    Window Destroy

    Destroys the window appropriately after use.

    void WindowDestroy();
    Example code:
    Window* window = CreateWindow("GG Engine", 1920, 1080);
    while (!window->IsClosed()) {
    window->WindowClear();
    window->WindowUpdate();
    }
    window.WindowDestroy();

    Is Key Held Down

    Checks if the key is held down.

    bool IsKeyHeldDown(unsigned int keycode);
    Example code:
    if (window->IsKeyHeldDown(GLFW_KEY_SPACE)) {
    std::cout << "Space Bar Pressed" << std::endl;
    }

    Is Key Down

    Checks if the key is pressed, only returns once per key down action.

    bool IsKeyDown(unsigned int keycode);
    Example code:
    if (window->IsKeyDown(GLFW_KEY_SPACE)) {
    std::cout << "Space Bar Pressed" << std::endl;
    }

    Is Mouse Button Held Down

    Checks if the mouse button is held down.

    bool IsMouseButtonHeldDown(unsigned int button);
    Example code:
    if (window->IsMouseButtonHeldDown(GLFW_MOUSE_BUTTON_1)) {
    std::cout << "Left mouse button down" << std::endl;
    }

    Is Mouse Button Down

    Checks if the mouse button is held down, only returns once per mouse button down action.

    bool IsMouseButtonDown(unsigned int button);
    Example code:
    if (window->IsMouseButtonDown(GLFW_MOUSE_BUTTON_1)) {
    std::cout << "Left mouse button down" << std::endl;
    }

    Get Mouse Position

    Updates X and Y values passed in argument, with the current mouse position.

    void GetMousePos(double& xpos, double& ypos);
    Example code:
    double mouse_X, mouse_Y;
    window->GetMousePos(mouse_X, mouse_Y);
    std::cout << "X Pos: " << mouse_X << " Y Pos: " << mouse_Y << std::endl;

    Constructor

    Shader();
    Shader(const char* vertexPath, const char* fragmentPath);
    Example code:
  • Default shaders allocated
  • Shader* s = new Shader();
  • Defined shaders allocated
  • Shader* s = new Shader(GGE_SHADER_BASIC_VERT, GGE_SHADER_BASIC_FRAG);

    Methods

    Set Uniform Values

    Choose appropriate method, depending on the uniform data type, that requires to be set.

    Float
    void SetUniform1f(const GLchar* name, float value);
    void SetUniform2f(const GLchar* name, const maths::Vector2& vec2);
    void SetUniform3f(const GLchar* name, const maths::Vector3& vec3);
    void SetUniform4f(const GLchar* name, const maths::Vector4& vec4);
    Float Array
    void SetUniform1fv(const GLchar* name, int count, float* value);
    Integer
    void SetUniform1i(const GLchar* name, int value);
    Integer Array
    void SetUniform1iv(const GLchar* name, int count, int* value);
    Matrix
    void SetUniformMatrix(const GLchar* name, const maths::Matrix& matrix);
    Example code:
    shader.SetUniform2f(GGE_SHADER_LIGHT_POS, Vector2(5.0f, 3.5f));

    Enable and Disable

    The shader needs to be enabled, before setting a new uniform value and should be disabled afterwards.

    void Enable() const; void Disable() const;

    Constructor

    Texture(const std::string filepath);
    Example code:
    Texture* image = new Texture("img/test.png");

    Constructor

    Sprite(float x, float y, float width, float height, unsigned int colour);
    Sprite(float x, float y, float width, float height, Texture* texture);
    Example code:
  • Assign with colour
  • Sprite* sprite = new Sprite(0, 0, 2, 2, 0xffffffff);
  • Assign with texture
  • Texture* image = new Texture("img/test.png");
    Sprite* sprite = new Sprite(0, 0, 2, 2, image);

    Constructor

    Container(Shader* shader);
    Container(Shader* shader, maths::Matrix projectionMatrix);
    Container(Renderer* renderer, Shader* shader, maths::Matrix projectionMatrix);
    Example code:
  • Default renderer and projection matrix allocated.
  • Shader* shader = new Shader();
    Container* bucket = new Container(shader);
  • Default renderer allocated.
  • Shader* shader = new Shader();
    Container* bucket = new Container(shader, Matrix::orthographic(-16.0f, 16.0f, -9.0f, 9.0f, -1.0f, 1.0f));
  • Defined renderer and projection matrix.
  • Shader* shader = new Shader();
    Container* bucket = new Container(new BatchRenderer(), shader, Matrix::orthographic(-16.0f, 16.0f, -9.0f, 9.0f, -1.0f, 1.0f));

    Methods

    Add to this Container

    Add a renderable object to the container array.

    virtual void AddToContainer(Renderable* renderable);
    Example code:
    Shader* shader = new Shader();
    Container* bucket = new Container(shader);
    Texture* image = new Texture("img/test.png");
    Sprite* sprite = new Sprite(0, 0, 2, 2, image);
    bucket->AddToContainer(sprite);

    Render this Container

    Each container that rendered, should call this method in the Render loop.

    virtual void AddToContainer(Renderable* renderable);
    Example code:
    void Example::Render() {
    bucket->RenderThisContainer();
    }