anulax1225 ago%!(EXTRA string=7 months)
parent b17c794999
commit 650e4584bd
  1. 6
      examples/test_imgui.cpp
  2. 8
      examples/test_layer.cpp
  3. 30
      manual/index.md
  4. 48
      src/bakara/core/application.cpp
  5. 43
      src/bakara/core/application.h
  6. 10
      src/bakara/core/entry.cpp
  7. 12
      src/bakara/core/layer.h
  8. 18
      src/bakara/core/layer_stack.cpp
  9. 14
      src/bakara/core/layer_stack.h
  10. 48
      src/bakara/core/window.h
  11. 6
      src/bakara/events/event.h
  12. 4
      src/bakara/events/window_event.h
  13. 16
      src/bakara/imgui/imgui_layer.cpp
  14. 8
      src/bakara/imgui/imgui_layer.h
  15. 39
      src/bakara/io/keyboard.cpp
  16. 25
      src/bakara/io/keyboard.h
  17. 22
      src/bakara/io/mouse.cpp
  18. 22
      src/bakara/io/mouse.h
  19. 4
      src/bakara/renderer/graphics_context.h
  20. 56
      src/platforms/glfw/glfw_window.cpp
  21. 34
      src/platforms/glfw/glfw_window.h
  22. 4
      src/platforms/opengl/opengl_context.cpp
  23. 4
      src/platforms/opengl/opengl_context.h

@ -8,7 +8,7 @@ class TestLayer : public Bk::Layer
public:
TestLayer()
: Layer("Test") {}
void imgui_render() override
void ImguiRender() override
{
static bool show = true;
ImGui::ShowDemoWindow(&show);
@ -21,12 +21,12 @@ class Sandbox : public Bk::Application
public:
Sandbox()
{
push_layer(new TestLayer());
PushLayer(new TestLayer());
}
};
std::unique_ptr<Bk::Application> Bk::create_app() {
std::unique_ptr<Bk::Application> Bk::CreateApp() {
return std::unique_ptr<Bk::Application>(new Sandbox());
}

@ -19,12 +19,12 @@ class TestLayer : public Bk::Layer
BK_INFO("Layer {} detached", name);
}
void on_event(Bk::Event& e) override
void OnEvent(Bk::Event& e) override
{
BK_INFO("Layer {} event", name);
}
void on_update() override
void OnUpdate() override
{
BK_INFO("Layer {} updated", name);
}
@ -35,10 +35,10 @@ class Sandbox : public Bk::Application
public:
Sandbox()
{
push_layer(new TestLayer());
PushLayer(new TestLayer());
}
};
std::unique_ptr<Bk::Application> Bk::create_app() {
std::unique_ptr<Bk::Application> Bk::CreateApp() {
return std::unique_ptr<Bk::Application>(new Sandbox());
}

@ -1,32 +1,2 @@
\mainpage Bakara Manual
## Build
### Windows
On windows, write commands :
```batch
git clone https://github.com/anulax/bakara
git submodule init
git submodule update
.\vendor\premake5 vs2022
dotnet build
dotnet run
```
Or use visual studio 2022 to build your project.
### Linux
On linux (if you don't have premake5, install it with your distro's packet manager). You have two env variable to change build proccess :
| Name | Value |
| ----------- | ----------- |
| autoexec | 0/1 |
| clearbin | 0/1 |
Then write commands :
```bash
git clone https://github.com/anulax/bakara
git submodule init
git submodule update
(export clearbin=1 autoexec=1)
./build.sh config=release
```

@ -7,64 +7,66 @@ namespace Bk {
{
BK_CORE_MSG_ASSERT(p_instance == nullptr, "Application already exists, can not create two application.")
Application::p_instance = this;
h_window = std::unique_ptr<Window>(Window::create_window());
h_window = std::unique_ptr<Window>(Window::CreateWindow());
imgui_layer = new ImguiLayer();
push_overlay(imgui_layer);
h_window->set_event_callback(BK_BIND_EVENT_FN(on_event));
PushOverlay(imgui_layer);
h_window->SetEventCallback(BK_BIND_EVENT_FN(OnEvent));
p_running = true;
}
Application::~Application() { }
void Application::on_event(Event& e)
void Application::OnEvent(Event& e)
{
EventDispatcher dispatcher(e);
dispatcher.dispatch<MouseButtonPressEvent>(BK_BIND_DISPACHER_FN(MouseButtonPressEvent, Mouse::button_callback));
dispatcher.dispatch<MouseButtonReleaseEvent>(BK_BIND_DISPACHER_FN(MouseButtonReleaseEvent, Mouse::button_callback));
dispatcher.dispatch<MouseScrollEvent>(BK_BIND_DISPACHER_FN(MouseScrollEvent, Mouse::wheel_callback));
dispatcher.dispatch<MouseMoveEvent>(BK_BIND_DISPACHER_FN(MouseMoveEvent, Mouse::cursor_callback));
if (!(dispatcher.dispatch<WindowCloseEvent>(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close))
|| dispatcher.dispatch<WindowResizeEvent>(BK_BIND_DISPACHER_FN(WindowResizeEvent, on_window_resize))))
dispatcher.dispatch<MouseButtonPressEvent>(BK_BIND_DISPACHER_FN(MouseButtonPressEvent, Mouse::ButtonCallback));
dispatcher.dispatch<MouseButtonReleaseEvent>(BK_BIND_DISPACHER_FN(MouseButtonReleaseEvent, Mouse::ButtonCallback));
dispatcher.dispatch<MouseScrollEvent>(BK_BIND_DISPACHER_FN(MouseScrollEvent, Mouse::WheelCallback));
dispatcher.dispatch<MouseMoveEvent>(BK_BIND_DISPACHER_FN(MouseMoveEvent, Mouse::CursorCallback));
dispatcher.dispatch<KeyPressEvent>(BK_BIND_DISPACHER_FN(KeyPressEvent, Keyboard::KeyCallback));
dispatcher.dispatch<KeyReleaseEvent>(BK_BIND_DISPACHER_FN(KeyReleaseEvent, Keyboard::KeyCallback));
if (!(dispatcher.dispatch<WindowCloseEvent>(BK_BIND_DISPACHER_FN(WindowCloseEvent, OnWindowClose))
|| dispatcher.dispatch<WindowResizeEvent>(BK_BIND_DISPACHER_FN(WindowResizeEvent, OnWindowResize))))
{
for(auto it = p_layer_stack.rbegin(); it != p_layer_stack.rend(); it++)
for(auto it = p_layer_stack.ReverseBegin(); it != p_layer_stack.ReverseEnd(); it++)
{
(*it)->on_event(e);
(*it)->OnEvent(e);
}
}
}
void Application::close()
void Application::Close()
{
h_window->close();
h_window->Close();
p_running = false;
}
bool Application::on_window_close(WindowCloseEvent& e)
bool Application::OnWindowClose(WindowCloseEvent& e)
{
close();
Close();
return true;
}
bool Application::on_window_resize(WindowResizeEvent& e)
bool Application::OnWindowResize(WindowResizeEvent& e)
{
return true;
}
void Application::run()
void Application::Run()
{
while (p_running)
{
for (Layer* layer : p_layer_stack)
layer->on_update();
layer->OnUpdate();
imgui_layer->begin();
imgui_layer->Begin();
for (Layer* layer : p_layer_stack)
layer->imgui_render();
imgui_layer->end();
layer->ImguiRender();
imgui_layer->End();
h_window->on_update();
h_window->OnUpdate();
}
}
}

@ -8,6 +8,7 @@ This file contains the main app abstraction.
#include "bakara/core/window.h"
#include "bakara/events/events.h"
#include "bakara/io/mouse.h"
#include "bakara/io/keyboard.h"
#include "bakara/core/layer_stack.h"
#include "bakara/imgui/imgui_layer.h"
@ -28,69 +29,69 @@ namespace Bk {
*/
virtual ~Application();
/*! \fn Bk::Application::on_event
/*! \fn Bk::Application::OnEvent
Function bound to the window to get all event from it
@param e : Event to be processed
*/
void on_event(Event& e);
void OnEvent(Event& e);
/*! \fn Bk::Application::on_window_close
/*! \fn Bk::Application::OnWindowClose
Handler of Bk::WindowCloseEvent and will be bind to a event dispacher
@param e : event to handled
*/
virtual bool on_window_close(WindowCloseEvent& e);
/*! \fn Bk::Application::on_window_resize
virtual bool OnWindowClose(WindowCloseEvent& e);
/*! \fn Bk::Application::OnWindowResize
Handler of Bk::WindowResizeEvent and will be bind to a event dispacher
@param e : event to handled
*/
virtual bool on_window_resize(WindowResizeEvent& e);
virtual bool OnWindowResize(WindowResizeEvent& e);
/*! \fn Bk::Application::push_overlay
/*! \fn Bk::Application::PushOverlay
Push's the layer on top of the layer stack
@param layer : Layer pointer to push
*/
inline void push_overlay(Layer* layer) { p_layer_stack.push_overlay(layer); }
/*! \fn Bk::Application::pop_overlay
inline void PushOverlay(Layer* layer) { p_layer_stack.PushOverlay(layer); }
/*! \fn Bk::Application::PopOverlay
Pop's the layer on top of the layer stack
*/
inline void pop_overlay(Layer* layer) { p_layer_stack.pop_overlay(layer); }
/*! \fn Bk::Application::push_overlay
inline void PopOverlay(Layer* layer) { p_layer_stack.PopOverlay(layer); }
/*! \fn Bk::Application::PushOverlay
Push's the layer at the bottom of the layer stack
@param layer : Layer pointer to push
*/
inline void push_layer(Layer* layer) { p_layer_stack.push_layer(layer); }
/*! \fn Bk::Application::push_overlay
inline void PushLayer(Layer* layer) { p_layer_stack.PushLayer(layer); }
/*! \fn Bk::Application::PushOverlay
Pop's the layer at the bottom of the layer stack
*/
inline void pop_layer(Layer* layer) { p_layer_stack.pop_layer(layer); }
inline void PopLayer(Layer* layer) { p_layer_stack.PopLayer(layer); }
/*! \fn Bk::Application::run
Starts the application and the update loop.
*/
void run();
void Run();
Window& get_window() { return *h_window; }
Window& GetWindow() { return *h_window; }
static Application& get() { return *p_instance; }
static Application& Get() { return *p_instance; }
protected:
std::unique_ptr<Window> h_window; //!< Pointer to the main window
ImguiLayer* imgui_layer;
/*! \fn Bk::Application::close
/*! \fn Bk::Application::Close
Stops the application and the update loop without creating an event.
*/
void close();
void Close();
private:
LayerStack p_layer_stack; //!< Layer stack of the application
bool p_running; //!< Flag that indicates if the update loop should stop or not
static Application* p_instance;
};
/*! \fn std::unique_ptr<Application> Bk::create_app()
/*! \fn std::unique_ptr<Application> Bk::CreateApp()
Is used to retrive the user app class instance, made from inheritance.
Must be defined in the user program
@return User defined application
*/
std::unique_ptr<Application> create_app();
std::unique_ptr<Application> CreateApp();
}

@ -5,17 +5,17 @@
This file contains the entry point of the program.
*/
/*! \fn std::unique_ptr<Bk::Application> Bk::create_app()
/*! \fn std::unique_ptr<Bk::Application> Bk::CreateApp()
External function implemented client side.
*/
extern std::unique_ptr<Bk::Application> Bk::create_app();
extern std::unique_ptr<Bk::Application> Bk::CreateApp();
/*! \fn int main(int argc, char** argv)
Entry of the program.
*/
int main(int argc, char** argv) {
Bk::Log::init("Bakara");
std::unique_ptr<Bk::Application> app = Bk::create_app();
app->run();
Bk::Log::Init("Bakara");
std::unique_ptr<Bk::Application> app = Bk::CreateApp();
app->Run();
return 0;
}

@ -9,12 +9,12 @@ namespace Bk {
Layer(const std::string& name = "Layer");
~Layer() {}
virtual void on_attach() {}
virtual void on_detach() {}
virtual void on_event(Event& e) {}
virtual void on_update() {}
virtual void imgui_render() {}
const std::string to_string() const { return name; }
virtual void OnAttach() {}
virtual void OnDetach() {}
virtual void OnEvent(Event& e) {}
virtual void OnUpdate() {}
virtual void ImguiRender() {}
const std::string ToString() const { return name; }
protected:
std::string name;
};

@ -3,35 +3,35 @@
namespace Bk {
LayerStack::~LayerStack() { clear(); }
void LayerStack::push_overlay(Layer* layer)
void LayerStack::PushOverlay(Layer* layer)
{
layer->on_attach();
layer->OnAttach();
p_layers.emplace_back(layer);
}
void LayerStack::pop_overlay(Layer* layer)
void LayerStack::PopOverlay(Layer* layer)
{
auto it = std::find(p_layers.begin() + p_layer_index, p_layers.end(), layer);
if (it != p_layers.end())
{
layer->on_detach();
layer->OnDetach();
p_layers.erase(it);
}
}
void LayerStack::push_layer(Layer* layer)
void LayerStack::PushLayer(Layer* layer)
{
layer->on_attach();
layer->OnAttach();
p_layers.emplace(p_layers.begin() + p_layer_index, layer);
p_layer_index++;
}
void LayerStack::pop_layer(Layer* layer)
void LayerStack::PopLayer(Layer* layer)
{
auto it = std::find(p_layers.begin(), p_layers.begin() + p_layer_index, layer);
if (it != p_layers.begin() + p_layer_index)
{
layer->on_detach();
layer->OnDetach();
p_layers.erase(it);
p_layer_index--;
}
@ -41,7 +41,7 @@ namespace Bk {
{
std::for_each(p_layers.begin(), p_layers.end(), [](Layer* layer)
{
layer->on_detach();
layer->OnDetach();
delete layer;
});
p_layers.clear();

@ -10,17 +10,19 @@ namespace Bk {
LayerStack() = default;
~LayerStack();
void push_overlay(Layer* layer);
void pop_overlay(Layer* layer);
void push_layer(Layer* layer);
void pop_layer(Layer* layer);
void PushOverlay(Layer* layer);
void PopOverlay(Layer* layer);
void PushLayer(Layer* layer);
void PopLayer(Layer* layer);
void clear();
std::vector<Layer*>::iterator begin() { return p_layers.begin(); }
std::vector<Layer*>::iterator end() { return p_layers.end(); }
std::vector<Layer*>::iterator Begin() { return p_layers.begin(); }
std::vector<Layer*>::iterator End() { return p_layers.end(); }
std::vector<Layer*>::reverse_iterator rbegin() { return p_layers.rbegin(); }
std::vector<Layer*>::reverse_iterator rend() { return p_layers.rend(); }
std::vector<Layer*>::reverse_iterator ReverseBegin() { return p_layers.rbegin(); }
std::vector<Layer*>::reverse_iterator ReverseEnd() { return p_layers.rend(); }
private:
std::vector<Layer*> p_layers;

@ -20,7 +20,7 @@ namespace Bk {
uint height; //!< Height of the window
/*! \fn Bk::WindowProps::WindowProps
Default window is initialized with a width of 1000 and a height 800
Default window is Initialized with a width of 1000 and a height 800
@param title : Title of the window
@param width : Width of the window
@param height : Height of the window
@ -47,57 +47,57 @@ namespace Bk {
*/
virtual ~Window() {}
/*! \fn Bk::Window::get_width
/*! \fn Bk::Window::GetWidth
@return The width of the window
*/
virtual uint get_width() const = 0;
/*! \fn Bk::Window::get_height
virtual uint GetWidth() const = 0;
/*! \fn Bk::Window::GetHeight
@return The height of the window
*/
virtual uint get_height() const = 0;
virtual uint GetHeight() const = 0;
/*! \fn Bk::Window::on_update
/*! \fn Bk::Window::OnUpdate
Updates the frame of the window
*/
virtual void on_update() = 0;
/*! \fn Bk::Window::set_event_callback
virtual void OnUpdate() = 0;
/*! \fn Bk::Window::SetEventCallback
Sets the function pointer for events of the window
@param callback : function called when a new event occures
*/
virtual void set_event_callback(const EventCallback callback) = 0;
virtual void SetEventCallback(const EventCallback callback) = 0;
/*! \fn Bk::Window::set_vsync
/*! \fn Bk::Window::SetVsync
Sets the window buffer swap interval. Is enabled by default.
If set to false the frame rate should be more constant, but more slow.
*/
virtual void set_vsync(bool enable) = 0;
/*! \fn Bk::Window::is_vsync
virtual void SetVsync(bool enable) = 0;
/*! \fn Bk::Window::IsVsync
Indicates if window is vsync
@return Vsync flag
*/
virtual bool is_vsync() const = 0;
virtual bool IsVsync() const = 0;
/*! \fn Bk::Window::close
/*! \fn Bk::Window::Close
Closes the window
*/
virtual void close() = 0;
/*! \fn Bk::Window::open
Opens and initializes the window
virtual void Close() = 0;
/*! \fn Bk::Window::Open
Opens and Initializes the window
*/
virtual void open() = 0;
/*! \fn Bk::Window::is_open
Indicates if the window is opened
virtual void Open() = 0;
/*! \fn Bk::Window::IsOpen
Indicates if the window is Opened
@return Open flag
*/
virtual bool is_open() = 0;
virtual bool IsOpen() = 0;
virtual void* get_native_window() = 0;
virtual void* GetNativeWindow() = 0;
/*! \fn Bk::Window::create_window()
/*! \fn Bk::Window::CreateWindow()
Static function implemented in the api window class to get a window specifique api.
If no parameter is specified, creates the window with the default settings.
@param props : Window information
*/
static Window* create_window(const WindowProps& props = WindowProps());
static Window* CreateWindow(const WindowProps& props = WindowProps());
};
}

@ -43,9 +43,9 @@ namespace Bk {
#define EVENT_CLASS_CATEGORY(category) virtual int get_category_flags() const override { return category; }
#ifdef BK_DEBUG
#define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return Tools::string_format(str, __VA_ARGS__); }
#define EVENT_STRINGIFY(str, ...) std::string ToString() const override { return Tools::string_format(str, __VA_ARGS__); }
#define GET_EVENT_STRING(event) event.to_string()
#define GET_EVENT_STRING(event) event.ToString()
#else
#define EVENT_STRINGIFY(str, ...)
@ -63,7 +63,7 @@ namespace Bk {
virtual const char* get_name() const = 0;
virtual int get_category_flags() const = 0;
#ifdef BK_DEBUG
virtual std::string to_string() const { return get_name(); }
virtual std::string ToString() const { return get_name(); }
#endif
bool is_in_category(EventCategory category) { return get_category_flags() & category; }
};

@ -9,8 +9,8 @@ namespace Bk {
WindowResizeEvent(uint width, uint height)
: p_width(width), p_height(height) {};
uint get_width() const { return p_width; }
uint get_height() const { return p_height; }
uint GetWidth() const { return p_width; }
uint GetHeight() const { return p_height; }
EVENT_STRINGIFY("WindowResizeEvent : %d %d", p_width, p_height)

@ -14,7 +14,7 @@
#include <glad/glad.h>
namespace Bk {
void ImguiLayer::on_attach()
void ImguiLayer::OnAttach()
{
IMGUI_CHECKVERSION();
ImGui::CreateContext();
@ -40,32 +40,32 @@ namespace Bk {
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
Application& app = Application::get();
GLFWwindow* window = static_cast<GLFWwindow*>(app.get_window().get_native_window());
Application& app = Application::Get();
GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow());
// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 420");
}
void ImguiLayer::on_detach()
void ImguiLayer::OnDetach()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void ImguiLayer::begin()
void ImguiLayer::Begin()
{
ImGuiIO& io = ImGui::GetIO();
Application& app = Application::get();
io.DisplaySize = ImVec2((float)app.get_window().get_width(), (float)app.get_window().get_height());
Application& app = Application::Get();
io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight());
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
void ImguiLayer::end()
void ImguiLayer::End()
{
// Rendering
ImGui::Render();

@ -10,9 +10,9 @@ namespace Bk {
ImguiLayer()
: Layer("Imgui") {}
void on_attach() override;
void on_detach() override;
void begin();
void end();
void OnAttach() override;
void OnDetach() override;
void Begin();
void End();
};
}

@ -0,0 +1,39 @@
#include "keyboard.h"
namespace Bk
{
std::vector<bool> Keyboard::keys;
std::vector<bool> Keyboard::keysChanged;
bool Keyboard::KeyCallback(KeyEvent& e)
{
//If the button is pressed or down then key is true
if (e.get_name() == "KeyPress" || e.get_name() == "KeyRelease") keys[e.get_key()] = !keys[e.get_key()];
else keys[e.get_key()] = false;
//If the button is not down then keyChanged is true
keysChanged[e.get_key()] = e.get_name() == "KeyPress" || e.get_name() == "KeyRelease";
return false;
}
bool Keyboard::KeyDown(KeyCode key)
{
return keys[key];
}
bool Keyboard::KeyWentUp(KeyCode key)
{
return !keys[key] && keyChanged(key);
}
bool Keyboard::KeyWentDown(KeyCode key)
{
return keys[key] && keyChanged(key);
}
bool Keyboard::keyChanged(KeyCode key)
{
bool ret = keysChanged[key];
keysChanged[key] = false;
return ret;
}
}

@ -0,0 +1,25 @@
#pragma once
#include "bakara.pch"
#include "key_codes.h"
#include "bakara/events/key_event.h"
namespace Bk
{
class Keyboard {
public:
static bool KeyCallback(KeyEvent& e);
//Assesors
static bool KeyDown(KeyCode key);
static bool KeyWentUp(KeyCode key);
static bool KeyWentDown(KeyCode key);
private:
//Keys state
static std::vector<bool> keys;
static std::vector<bool> keysChanged;
//Assesor
static bool keyChanged(KeyCode key);
};
}

@ -18,7 +18,7 @@ namespace Bk
std::vector<bool> Mouse::buttons = { 0 };
std::vector<bool> Mouse::buttonsChanged = { 0 };
bool Mouse::cursor_callback(MouseMoveEvent& e) {
bool Mouse::CursorCallback(MouseMoveEvent& e) {
x = e.get_x();
y = e.get_y();
@ -34,7 +34,7 @@ namespace Bk
return false;
}
bool Mouse::button_callback(MouseButtonEvent& e) {
bool Mouse::ButtonCallback(MouseButtonEvent& e) {
if (e.get_name() != "MouseButtonRelease") {
if(!buttons[e.get_btn()]) {
buttons[e.get_btn()] = true;
@ -47,49 +47,49 @@ namespace Bk
return false;
}
bool Mouse::wheel_callback(MouseScrollEvent& e) {
bool Mouse::WheelCallback(MouseScrollEvent& e) {
scrollDX = e.get_dx();
scrollDY = e.get_dy();
return false;
}
Vec2 Mouse::get_position() {
Vec2 Mouse::GetPosition() {
return Vec2(x, y);
}
double Mouse::get_dx() {
double Mouse::GetDX() {
double _dX = dX;
dX = 0;
return _dX;
}
double Mouse::get_dy() {
double Mouse::GetDY() {
double _dY = dY;
dY = 0;
return _dY;
}
double Mouse::get_scroll_dx() {
double Mouse::GetScrollDX() {
double _scrollDX = scrollDX;
scrollDX = 0;
return _scrollDX;
}
double Mouse::get_scroll_dy() {
double Mouse::GetScrollDY() {
double _scrollDY = scrollDY;
scrollDY = 0;
return _scrollDY;
}
bool Mouse::button(MouseCode button) {
bool Mouse::Button(MouseCode button) {
return buttons[button];
}
bool Mouse::button_up(MouseCode button) {
bool Mouse::ButtonUp(MouseCode button) {
return !buttons[button] && buttonChanged(button);
}
bool Mouse::button_down(MouseCode button) {
bool Mouse::ButtonDown(MouseCode button) {
return buttons[button] && buttonChanged(button);
}

@ -8,23 +8,23 @@ namespace Bk
class Mouse {
public:
//GLFW callback function
static bool cursor_callback(MouseMoveEvent& e);
static bool button_callback(MouseButtonEvent& e);
static bool wheel_callback(MouseScrollEvent& e);
static bool CursorCallback(MouseMoveEvent& e);
static bool ButtonCallback(MouseButtonEvent& e);
static bool WheelCallback(MouseScrollEvent& e);
//Mouse position assesors
static Vec2 get_position();
static Vec2 GetPosition();
//Mouse scroll assesors
static double get_dx();
static double get_dy();
static double get_scroll_dx();
static double get_scroll_dy();
static double GetDX();
static double GetDY();
static double GetScrollDX();
static double GetScrollDY();
//Mouse buttons assesors
static bool button(MouseCode button);
static bool button_up(MouseCode button);
static bool button_down(MouseCode button);
static bool Button(MouseCode button);
static bool ButtonUp(MouseCode button);
static bool ButtonDown(MouseCode button);
private:
static double x;

@ -5,7 +5,7 @@ namespace Bk
class GraphicsContext
{
public:
virtual void init() = 0;
virtual void swap_buffers() = 0;
virtual void Init() = 0;
virtual void SwapBuffers() = 0;
};
}

@ -5,13 +5,13 @@
#include <string.h>
namespace Bk {
Window* Window::create_window(const WindowProps& props)
Window* Window::CreateWindow(const WindowProps& props)
{
return new Platform::WinGLFW(props);
}
namespace Platform {
static uint p_glfw_initialized = 0;
static uint p_glfw_Initialized = 0;
static void glfw_error_callback(int error, const char* description)
{
@ -23,35 +23,35 @@ namespace Bk {
p_data.title = props.title;
p_data.width = props.width;
p_data.height = props.height;
init();
Init();
}
WinGLFW::~WinGLFW()
{
delete context;
close();
Close();
}
void WinGLFW::init()
void WinGLFW::Init()
{
h_is_open = true;
h_IsOpen = true;
BK_CORE_INFO("Creating window : {0} ({1}, {2})", p_data.title, p_data.width, p_data.height);
if (!p_glfw_initialized++)
if (!p_glfw_Initialized++)
{
int success = glfwInit();
BK_CORE_MSG_ASSERT(success, "Couldn't initialize glfw!")
BK_CORE_MSG_ASSERT(success, "Couldn't Initialize glfw!")
glfwSetErrorCallback(glfw_error_callback);
}
p_window = glfwCreateWindow((int)p_data.width, (int)p_data.height, p_data.title.c_str(), nullptr, nullptr);
context = new OpenglContext(p_window);
context->init();
context->Init();
glfwSetWindowUserPointer(p_window, &p_data);
set_vsync(true);
SetVsync(true);
init_event_callbacks();
InitEventCallbacks();
}
void WinGLFW::init_event_callbacks()
void WinGLFW::InitEventCallbacks()
{
glfwSetFramebufferSizeCallback(p_window, [](GLFWwindow* window, int width, int height)
{
@ -125,24 +125,24 @@ namespace Bk {
});
}
void WinGLFW::on_update()
void WinGLFW::OnUpdate()
{
glfwPollEvents();
context->swap_buffers();
if (h_is_open)
context->SwapBuffers();
if (h_IsOpen)
{
if (p_shutdown && h_is_open) { shutdown(); }
if (p_Shutdown && h_IsOpen) { Shutdown(); }
}
}
void WinGLFW::set_event_callback(const EventCallback callback)
void WinGLFW::SetEventCallback(const EventCallback callback)
{
p_data.callback = callback;
}
void WinGLFW::set_vsync(bool enable)
void WinGLFW::SetVsync(bool enable)
{
if (h_is_open)
if (h_IsOpen)
{
if (enable) { glfwSwapInterval(1); }
else { glfwSwapInterval(0); }
@ -150,28 +150,28 @@ namespace Bk {
}
}
bool WinGLFW::is_vsync() const
bool WinGLFW::IsVsync() const
{
return p_data.vsync;
}
void WinGLFW::shutdown()
void WinGLFW::Shutdown()
{
h_is_open = false;
p_shutdown = false;
h_IsOpen = false;
p_Shutdown = false;
glfwDestroyWindow(p_window);
}
void WinGLFW::close()
void WinGLFW::Close()
{
p_shutdown = true;
p_Shutdown = true;
}
void WinGLFW::open()
void WinGLFW::Open()
{
if (!h_is_open)
if (!h_IsOpen)
{
init();
Init();
}
}

@ -13,27 +13,27 @@ namespace Bk::Platform {
WinGLFW(const WindowProps& props);
virtual ~WinGLFW();
inline uint get_width() const override { return p_data.width; }
inline uint get_height() const override { return p_data.height; }
inline uint GetWidth() const override { return p_data.width; }
inline uint GetHeight() const override { return p_data.height; }
void on_update() override;
void set_event_callback(const EventCallback callback) override;
void OnUpdate() override;
void SetEventCallback(const EventCallback callback) override;
void set_vsync(bool enable) override;
bool is_vsync() const override;
void SetVsync(bool enable) override;
bool IsVsync() const override;
void close() override;
void open() override;
void Close() override;
void Open() override;
void* get_native_window() override { return p_window; }
/*! \fn Bk::Window::is_open
Indicates if the window is opened
void* GetNativeWindow() override { return p_window; }
/*! \fn Bk::Window::IsOpen
Indicates if the window is Opened
@return Open flag
*/
bool is_open() override { return h_is_open; }
bool IsOpen() override { return h_IsOpen; }
private:
bool h_is_open; //!< indicaste if the window is opened or not
bool p_shutdown;
bool h_IsOpen; //!< indicaste if the window is Opened or not
bool p_Shutdown;
GLFWwindow* p_window;
OpenglContext* context;
@ -47,8 +47,8 @@ namespace Bk::Platform {
};
WindowData p_data;
void init_event_callbacks();
void init();
void shutdown();
void InitEventCallbacks();
void Init();
void Shutdown();
};
}

@ -7,7 +7,7 @@ namespace Bk::Platform
OpenglContext::OpenglContext(GLFWwindow* window_handle)
: window_handle(window_handle) {}
void OpenglContext::init()
void OpenglContext::Init()
{
glfwMakeContextCurrent(window_handle);
int success = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
@ -19,7 +19,7 @@ namespace Bk::Platform
BK_CORE_INFO("Opengl Version : {0}.{1}", majVers, minVers);
}
void OpenglContext::swap_buffers()
void OpenglContext::SwapBuffers()
{
glfwSwapBuffers(window_handle);
}

@ -11,8 +11,8 @@ namespace Bk::Platform
{
public:
OpenglContext(GLFWwindow* window_handle);
void init() override;
void swap_buffers() override;
void Init() override;
void SwapBuffers() override;
private:
GLFWwindow* window_handle;
};

Loading…
Cancel
Save