Reorganized some files to avoid directly including glad/gl and glfw

CreateImage method implemented
Gui_Panel_Refactor
Joeyrp 4 years ago
parent 9ad0276d3c
commit 8f3524ae4e

@ -19,7 +19,7 @@ set(LUNARIUM_SRC
"src/core/core.cpp" "src/core/core.cpp"
"src/core/state.cpp" "src/core/state.cpp"
"src/core/version.cpp" "src/core/version.cpp"
"src/core/window.cpp" "src/window/window.cpp"
"src/utils/types.cpp" "src/utils/types.cpp"
"src/utils/logger.cpp" "src/utils/logger.cpp"
"src/utils/highResTimer.cpp" "src/utils/highResTimer.cpp"

@ -6,16 +6,19 @@ Core:
☐ Add log settings to the state file ☐ Add log settings to the state file
Graphics: Graphics:
☐ Dear ImGui class with basic initialization
✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM) ✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM)
✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM) ✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM)
✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM) ✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM)
✔ Make the text renderer smarter about breaking up words on multiple lines @low @done (9/8/2021, 2:23:03 PM) ✔ Make the text renderer smarter about breaking up words on multiple lines @low @done (9/8/2021, 2:23:03 PM)
☐ Implement the Image creation methods ✔ Implement the Image creation methods @done (9/9/2021, 2:50:20 PM)
Dear ImGui:
☐ Dear ImGui class with basic initialization
Input: Input:
✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM) ✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM)
☐ Add the InputManager to the core ✔ Add the InputManager to the core @done (9/9/2021, 2:57:06 PM)
Audio: Audio:

@ -10,14 +10,14 @@
#include "version.h" #include "version.h"
// Sub Systems // Sub Systems
#include "window.h" #include <window/window.h>
#include <graphics/opengl/glGraphics.h> #include <graphics/opengl/glGraphics.h>
namespace lunarium namespace lunarium
{ {
Core* Core::mpInstance = nullptr; Core* Core::mpInstance = nullptr;
Core::Core() Core::Core()
: mbIsInit(false), mpArgs(nullptr), mpWindow(nullptr), mpGraphics(nullptr) : mbIsInit(false), mpArgs(nullptr), mpWindow(nullptr), mpGraphics(nullptr), mpInput(nullptr)
{ {
} }
@ -40,6 +40,10 @@ namespace lunarium
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!"); Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!");
// Shutdown subsystems // Shutdown subsystems
mpInstance->mpInput->Shutdown();
delete mpInstance->mpInput;
mpInstance->mpInput = nullptr;
mpInstance->mpGraphics->Shutdown(); mpInstance->mpGraphics->Shutdown();
delete mpInstance->mpGraphics; delete mpInstance->mpGraphics;
mpInstance->mpGraphics = nullptr; mpInstance->mpGraphics = nullptr;
@ -134,8 +138,11 @@ namespace lunarium
return; return;
} }
// DEBUG mpGraphics->SetClearColor(Color(0.5f, 0.5f, 0.75f, 1.0f));
mpGraphics->SetClearColor(Color(0.0f, 0.0f, 0.0f, 1.0f));
// INPUT
mpInput = new InputManager;
mpInput->Initialize(mpWindow);
mbIsInit = true; mbIsInit = true;
} }
@ -166,21 +173,22 @@ namespace lunarium
// Poll input // Poll input
Window::PollEvents(); Window::PollEvents();
mKeyEvents = mpInput->PollKeys();
// HACK: Temporary solution to close the program // HACK: Temporary solution to close the program
if (glfwGetKey(mpWindow->GetWindow(), GLFW_KEY_ESCAPE) == GLFW_PRESS) if (mpInput->IsKeyDown(KeyCode::ESCAPE))
{ {
mpWindow->SetShouldCloseFlag(true); mpWindow->SetShouldCloseFlag(true);
} }
// DEBUG: Graphics testing // DEBUG: Graphics testing
static int width = 500; static int width = 500;
if (glfwGetKey(mpWindow->GetWindow(), GLFW_KEY_LEFT) == GLFW_PRESS) if (mpInput->IsKeyDown(KeyCode::LEFT))
{ {
width -= 10; width -= 10;
} }
if (glfwGetKey(mpWindow->GetWindow(), GLFW_KEY_RIGHT) == GLFW_PRESS) if (mpInput->IsKeyDown(KeyCode::RIGHT))
{ {
width += 10; width += 10;
} }

@ -10,6 +10,7 @@
#define CORE_H_ #define CORE_H_
#include "state.h" #include "state.h"
#include <input/inputManager.h>
#include <utils/logger.h> #include <utils/logger.h>
#include <utils/args.h> #include <utils/args.h>
#include <utils/frameCounter.h> #include <utils/frameCounter.h>
@ -49,6 +50,9 @@ namespace lunarium
Window* mpWindow; Window* mpWindow;
IGraphics* mpGraphics; IGraphics* mpGraphics;
InputManager* mpInput;
InputManager::_KeyEvents mKeyEvents;
private: // HIDDEN METHODS private: // HIDDEN METHODS

@ -60,6 +60,7 @@ namespace lunarium
// Takes raw image data and creates and Image class instance out of it. // Takes raw image data and creates and Image class instance out of it.
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel. // The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format) = 0; virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format) = 0;
virtual void DestroyImage(Image* i) = 0;
// Fonts // Fonts
virtual int DefaultFont() const = 0; virtual int DefaultFont() const = 0;

@ -8,7 +8,7 @@
#include "glGraphics.h" #include "glGraphics.h"
#include "defaultShaders.h" #include "defaultShaders.h"
#include <core/window.h> #include <window/window.h>
#include "../image.h" #include "../image.h"
#include "../internalFont.h" #include "../internalFont.h"
#include <utils/logger.h> #include <utils/logger.h>
@ -318,7 +318,34 @@ namespace lunarium
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel. // The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
Image* OglGraphics::CreateImage(const unsigned char* pData, int width, int height, ImageFormat format) Image* OglGraphics::CreateImage(const unsigned char* pData, int width, int height, ImageFormat format)
{ {
return nullptr; unsigned int glFormat[4] = { GL_RGB, GL_RGBA, GL_BGR, GL_BGRA };
unsigned int textureID = 0;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, glFormat[format], width, height, 0, glFormat[format], GL_UNSIGNED_BYTE, pData);
glGenerateMipmap(GL_TEXTURE_2D);
// TODO: Move this to a different function to allow for more user options
// Or make a version of the method that takes a struct for these options
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Image* image = new Image;
image->mWidth = width;
image->mHeight = height;
image->mGLTextureID = textureID;
return image;
}
void OglGraphics::DestroyImage(Image* i)
{
i->FreeRawData();
delete i;
} }
// Fonts // Fonts

@ -52,6 +52,7 @@ namespace lunarium
// Takes raw image data and creates and Image class instance out of it. // Takes raw image data and creates and Image class instance out of it.
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel. // The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format); virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format);
virtual void DestroyImage(Image* i);
// Fonts // Fonts
int DefaultFont() const; int DefaultFont() const;

@ -8,7 +8,7 @@
* *
******************************************************************************/ ******************************************************************************/
#include <core/window.h> #include <window/window.h>
#include "inputManager.h" #include "inputManager.h"
#include <utils/logger.h> #include <utils/logger.h>
@ -25,8 +25,19 @@ namespace lunarium
mpWindow = pWindow; mpWindow = pWindow;
} }
void InputManager::Shutdown()
{
mpWindow = nullptr;
}
const InputManager::_KeyEvents& InputManager::PollKeys() const InputManager::_KeyEvents& InputManager::PollKeys()
{ {
if (!mpWindow)
{
Logger::Log(LogCategory::CORE, LogLevel::WARNING, "InputManager::PollKeys called but InputManager is not initialized!");
return mKeyEvents;
}
mKeyEvents.KeysPressed.clear(); mKeyEvents.KeysPressed.clear();
mKeyEvents.KeysReleased.clear(); mKeyEvents.KeysReleased.clear();
@ -112,6 +123,19 @@ namespace lunarium
return (mKeyboardState[key] == KEY_DOWN); return (mKeyboardState[key] == KEY_DOWN);
} }
bool InputManager::IsKeyPressed(KeyCode key)
{
for (int i = 0; i < mKeyEvents.KeysPressed.size(); i++)
{
if (mKeyEvents.KeysPressed[i].Key.Code == key)
{
return true;
}
}
return false;
}
// TODO: FIX WINDOWS SPECIFIC CODE: // TODO: FIX WINDOWS SPECIFIC CODE:
glm::vec2 InputManager::GetMousePosition() glm::vec2 InputManager::GetMousePosition()
{ {

@ -58,6 +58,7 @@ namespace lunarium
private: // ENGINE ONLY METHODS private: // ENGINE ONLY METHODS
InputManager(); InputManager();
void Initialize(Window* pWindow); void Initialize(Window* pWindow);
void Shutdown();
// Returns an array of keys that were pressed // Returns an array of keys that were pressed
// Keys are only pressed if they were not held on the previous frame // Keys are only pressed if they were not held on the previous frame
@ -70,6 +71,10 @@ namespace lunarium
public: public:
// Returns true if a key is down and was NOT down last frame
bool IsKeyPressed(KeyCode key);
// Returns true if a key is down
bool IsKeyDown(KeyCode key); bool IsKeyDown(KeyCode key);
// Returns the mouse position in screen coordinates // Returns the mouse position in screen coordinates

@ -14,7 +14,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include "keyCodes.h" #include <window/keyCodes.h>
namespace lunarium namespace lunarium
{ {

@ -10,7 +10,7 @@
#ifndef KEY_CODES_H_ #ifndef KEY_CODES_H_
#define KEY_CODES_H_ #define KEY_CODES_H_
#include <GLFW/glfw3.h> #include "window.h"
namespace lunarium namespace lunarium
{ {
@ -129,7 +129,7 @@ namespace lunarium
CONTROL = GLFW_KEY_LEFT_CONTROL, CONTROL = GLFW_KEY_LEFT_CONTROL,
ALT = GLFW_KEY_LEFT_ALT, ALT = GLFW_KEY_LEFT_ALT,
KEY_UNKNOWN = 0xFF KEY_UNKNOWN = 0xFFFF
}; };
static int KeyCodeList[] = { static int KeyCodeList[] = {
Loading…
Cancel
Save