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
26class Keys;
27struct GLFWwindow;
28struct GLFWmonitor;
29struct GLFWvidmode;
30struct GLFWimage;
31
32
33namespace sys
34{
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
65 auto onUpdate(float dt) -> void override;
66
67 auto endWindow() -> void override
68 {
69 }; // for debug ImGUI
70
71 auto onRender() -> void override;
72 auto onEnterEngine() -> void override;
73 auto load(Stream& stream) -> void override;
74 auto save(Stream& stream) const -> void override;
75
77 auto getWindow() const -> GLFWwindow*;
78 auto getTextureID() const -> GLuint;
80 auto bindFrameBuffer() -> void;
82 auto unbindFrameBuffer() -> void;
84 auto createFrameBuffer() -> void;
86 auto rescaleFrameBuffer() -> void;
87 auto finishFrame() const -> void;
88
89 [[nodiscard]] auto getWidth() const -> int;
90 [[nodiscard]] auto getHeight() const -> int;
91
92 auto setWidth(int width) -> void;
93 auto setHeight(int height) -> void;
94
95private:
96 GLFWwindow* windowHandle;
98 GLFWmonitor* monitorHandle{nullptr};
99 const GLFWvidmode* videoMode;
102
103 std::unique_ptr<GLFWimage> windowIcon;
104
105
123
124 Eigen::Vector4f cardPosition{150.f, -20.f, 0.f, 1.f};
125
126 const char* ColorShaderFile = "source/Shaders/Frag/color.frag";
127 const char* TextureShaderFile = "source/Shaders/Frag/texture.frag";
128 const char* VertexShaderFile = "source/Shaders/Vert/default.vert";
129 const char* cardFile = "Assets/cards/40x60_card.png";
130 float backgroundRedVal = 0.1f;
131 float backgroundGreenVal = 0.1f;
132 float backgroundBlueVal = 0.1f;
133
135 auto createMesh() -> void;
136 auto setShaderUniforms() const -> void;
138 auto linkMessages() -> void;
140 auto receiveToggleWindowedFullScreen(const Message* message) -> Message;
141
142
143 static auto lookAt(const Eigen::Vector3f& eye, Eigen::Vector3f center, Eigen::Vector3f up) -> Eigen::Matrix4f;
144 static auto draw(GLuint shader, float scale, float rotation, Eigen::Vector4f position, GLuint mesh, int vertexCount,
145 GLuint texture);
146};
147}
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:77
Definition Input.h:57
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:719
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition opengl.cpp:806
auto rescaleFrameBuffer() -> void
rescale framebuffer for ImGui Viewport based on sys::opengl width and height
Definition opengl.cpp:898
GLuint textureShader
ID for the shader which handleds textures.
Definition opengl.h:110
const char * cardFile
Definition opengl.h:129
auto finishFrame() const -> void
Definition opengl.cpp:759
GLFWwindow * windowHandle
Definition opengl.h:96
GLuint meshVertexBufferID
ID for the vertex buffer associated with the mesh.
Definition opengl.h:114
GLuint textureID
ID for the texture for custom frameBuffer.
Definition opengl.h:118
GLuint colorShader
The following are test variables for test opengl.
Definition opengl.h:108
std::unique_ptr< GLFWimage > windowIcon
Definition opengl.h:103
int height
Definition opengl.h:101
const char * ColorShaderFile
Definition opengl.h:126
OpenGL()
Definition opengl.cpp:587
auto setHeight(int height) -> void
Definition opengl.cpp:792
auto getTextureID() const -> GLuint
Definition opengl.cpp:915
float backgroundGreenVal
Definition opengl.h:131
Eigen::Vector4f cardPosition
Definition opengl.h:124
auto unbindFrameBuffer() -> void
unbind framebuffer for ImGui Viewport
Definition opengl.cpp:866
auto setWidth(int width) -> void
Definition opengl.cpp:783
auto onUpdate(float dt) -> void override
called once every frame.
Definition opengl.cpp:680
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition opengl.cpp:812
const char * VertexShaderFile
Definition opengl.h:128
GLuint renderBuffer
ID for the custom renderBuffer.
Definition opengl.h:122
const GLFWvidmode * videoMode
Definition opengl.h:99
auto getWidth() const -> int
Definition opengl.cpp:765
GLuint frameBuffer
ID for the custom framebuffer.
Definition opengl.h:120
const char * TextureShaderFile
Definition opengl.h:127
auto bindFrameBuffer() -> void
bind framebuffer for ImGui Viewport
Definition opengl.cpp:857
GLuint meshID
ID for the mesh.
Definition opengl.h:112
auto setShaderUniforms() const -> void
Definition opengl.cpp:395
auto getHeight() const -> int
Definition opengl.cpp:774
auto linkMessages() -> void
linking message
Definition opengl.cpp:846
auto receiveToggleWindowedFullScreen(const Message *message) -> Message
message for toggling fullscreen
Definition opengl.cpp:820
static auto draw(GLuint shader, float scale, float rotation, Eigen::Vector4f position, GLuint mesh, int vertexCount, GLuint texture)
Definition opengl.cpp:431
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition opengl.h:67
auto getWindow() const -> GLFWwindow *
Definition opengl.cpp:754
~OpenGL() override
Definition opengl.cpp:726
static auto lookAt(const Eigen::Vector3f &eye, Eigen::Vector3f center, Eigen::Vector3f up) -> Eigen::Matrix4f
Definition opengl.cpp:285
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:98
static auto getEnum() -> Type
function required by all systems
Definition opengl.h:53
int meshVertexCount
number of vertices in the mesh
Definition opengl.h:116
auto createFrameBuffer() -> void
create framebuffer for ImGui Viewport
Definition opengl.cpp:871
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition opengl.cpp:816
auto onRender() -> void override
called every frame after update has been called for every object.
Definition opengl.cpp:703
float backgroundRedVal
Definition opengl.h:130
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition opengl.cpp:801
int width
Definition opengl.h:100
float backgroundBlueVal
Definition opengl.h:132
auto createMesh() -> void
Definition opengl.cpp:222
the type of elements in a basic_json container
Definition GameObject.h:32
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:34