Brunot
Loading...
Searching...
No Matches
opengl.h
Go to the documentation of this file.
1// File: opengl.h
2// Description: header file for opengl, public interface for functions, only init is used as ow now
3// Author(s): Aidan Hartman (aidan.hartman@digipen.edu) Base Implementation
4// Marcelo Escamilla (marcelo.escamilla@digipen.edu) Audio initialization and some playback
5// 2025 / 09 / 17
6// (C) Digipen 2025
7// opengl.h
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15#pragma once
16
17// windows.h must be included otherwise we have opengl errors
18#include <windows.h>
19#include <glad/glad.h>
20// #include <GLFW/glfw3.h>
21
22#include "Framework/System.h"
24
25
26struct Message;
27class Keys;
28struct GLFWwindow;
29struct GLFWmonitor;
30struct GLFWvidmode;
31struct GLFWimage;
32
33
34namespace sys
35{
37auto constexpr default_window_width = 1920;
39auto constexpr default_window_height = 1080;
40
41
42class OpenGL : public System
43{
44protected:
45 auto systemShowMenu() -> void override;
46
47public:
49
53 static auto getEnum() -> Type
54 {
55 return Type::OpenGL;
56 }
57
58
59 OpenGL();
60 ~OpenGL() override;
61
63 auto clone() const -> std::unique_ptr<GameObject> override;
64
65private:
66 auto onUpdate(float dt) -> void override;
67 auto onRender() -> void override;
68public:
69
70 auto endWindow() -> void override
71 {
72 }; // for debug ImGUI
73
74 auto onEnterEngine() -> void override;
75 auto load(const Stream& stream) -> void override;
76 auto save(Stream& stream) const -> void override;
77
79 auto getWindow() const -> GLFWwindow*;
80 auto getTextureID() const -> GLuint;
82 auto bindFrameBuffer() -> void;
84 auto unbindFrameBuffer() -> void;
86 auto createFrameBuffer() -> void;
88 auto rescaleFrameBuffer() -> void;
89 auto finishFrame() const -> void;
90
91 [[nodiscard]] auto getWidth() const -> int;
92 [[nodiscard]] auto getHeight() const -> int;
93
94 auto setWidth(int width) -> void;
95 auto setHeight(int height) -> void;
96
98 auto enableCursor() const -> void;
99
101 auto disableCursor() const -> void;
102
103private:
104
106 GLFWmonitor* monitorHandle{nullptr};
107 const GLFWvidmode* videoMode;
108 GLFWwindow* windowHandle{nullptr};
109
110#if NDEBUG
111 bool currentlyFullscreen = true;
112#else
114#endif
115
118
121
124
125 std::unique_ptr<GLFWimage> windowIcon;
126
133
134 float backgroundRedVal = 0.1f;
135 float backgroundGreenVal = 0.1f;
136 float backgroundBlueVal = 0.1f;
137
139 auto setShaderUniforms() const -> void;
141 auto linkMessages() -> void;
143 auto receiveToggleWindowedFullScreen(const Message* message) -> Message;
144};
145}
sys::Json Stream
Definition AudioObject.h:20
unsigned int GLuint
Definition IndexBuffer.h:17
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
Class that can interact with the keyboard.
Definition Keys.h:33
Type
Definition System.h:20
@ OpenGL
Definition System.h:23
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition opengl.cpp:293
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition opengl.cpp:364
auto rescaleFrameBuffer() -> void
rescale framebuffer for ImGui Viewport based on sys::opengl width and height
Definition opengl.cpp:462
int screenWidth
Definition opengl.h:122
auto finishFrame() const -> void
Definition opengl.cpp:315
GLFWwindow * windowHandle
Definition opengl.h:108
GLuint textureID
ID for the texture for custom frameBuffer for game viewport in imgui.
Definition opengl.h:128
int screenHeight
Definition opengl.h:123
std::unique_ptr< GLFWimage > windowIcon
Definition opengl.h:125
int height
Definition opengl.h:117
OpenGL()
Definition opengl.cpp:172
int windowedHeight
Definition opengl.h:120
auto setHeight(int height) -> void
Definition opengl.cpp:340
auto getTextureID() const -> GLuint
Definition opengl.cpp:479
float backgroundGreenVal
Definition opengl.h:135
auto unbindFrameBuffer() -> void
unbind framebuffer for ImGui Viewport
Definition opengl.cpp:430
auto setWidth(int width) -> void
Definition opengl.cpp:331
auto disableCursor() const -> void
Hides the mouse cursor from the screen.
Definition opengl.cpp:354
auto onUpdate(float dt) -> void override
called once every frame.
Definition opengl.cpp:271
GLuint renderBuffer
ID for the custom renderBuffer for the game viewport in imgui.
Definition opengl.h:132
const GLFWvidmode * videoMode
Definition opengl.h:107
auto getWidth() const -> int
Definition opengl.cpp:321
GLuint frameBuffer
ID for the custom framebuffer for the game viewport in imgui.
Definition opengl.h:130
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition opengl.cpp:376
int windowedWidth
Definition opengl.h:119
auto bindFrameBuffer() -> void
bind framebuffer for ImGui Viewport
Definition opengl.cpp:421
auto setShaderUniforms() const -> void
auto getHeight() const -> int
Definition opengl.cpp:326
auto linkMessages() -> void
linking message
Definition opengl.cpp:410
auto receiveToggleWindowedFullScreen(const Message *message) -> Message
message for toggling fullscreen
Definition opengl.cpp:384
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition opengl.h:70
auto getWindow() const -> GLFWwindow *
Definition opengl.cpp:310
~OpenGL() override
Definition opengl.cpp:298
bool currentlyFullscreen
Definition opengl.h:113
GLFWmonitor * monitorHandle
monitor handle if it is in null its in windowed mode and if its not it will go into fullscreen its ju...
Definition opengl.h:106
static auto getEnum() -> Type
function required by all systems
Definition opengl.h:53
auto createFrameBuffer() -> void
create framebuffer for ImGui Viewport
Definition opengl.cpp:435
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition opengl.cpp:380
auto onRender() -> void override
called every frame after update has been called for every object.
Definition opengl.cpp:288
auto enableCursor() const -> void
Shows the mouse cursor on the screen.
Definition opengl.cpp:349
float backgroundRedVal
Definition opengl.h:134
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition opengl.cpp:359
int width
Definition opengl.h:116
float backgroundBlueVal
Definition opengl.h:136
the type of elements in a basic_json container
Definition GameObject.h:37
auto constexpr default_window_height
default window height when the engine started
Definition opengl.h:39
auto constexpr default_window_width
default window height when the engine started
Definition opengl.h:37
Definition Message.h:35