Gros boulo dans son cul

main
anulax1225 ago%!(EXTRA string=7 months)
parent 0ef47947fb
commit b17c794999
  1. 4
      premake5.lua
  2. 0
      src/bakara.pch
  3. 10
      src/bakara/core/application.cpp
  4. 11
      src/bakara/core/application.h
  5. 2
      src/bakara/core/entry.cpp
  6. 2
      src/bakara/core/layer.h
  7. 2
      src/bakara/core/layer_stack.h
  8. 2
      src/bakara/core/window.h
  9. 29
      src/bakara/events/dispacher.h
  10. 2
      src/bakara/events/event.h
  11. 29
      src/bakara/imgui/imgui_layer.cpp
  12. 20
      src/bakara/io/input.h
  13. 0
      src/bakara/io/joystick.h
  14. 0
      src/bakara/io/keyboard.cpp
  15. 0
      src/bakara/io/keyboard.h
  16. 101
      src/bakara/io/mouse.cpp
  17. 49
      src/bakara/io/mouse.h
  18. 11
      src/bakara/renderer/graphics_context.h
  19. 1
      src/bakarapch.cpp
  20. 0
      src/platforms/glfw/glfw_joystick.h
  21. 0
      src/platforms/glfw/glfw_joystock.cpp
  22. 27
      src/platforms/glfw/glfw_window.cpp
  23. 15
      src/platforms/glfw/glfw_window.h
  24. 27
      src/platforms/opengl/opengl_context.cpp
  25. 19
      src/platforms/opengl/opengl_context.h

@ -14,14 +14,12 @@ project "bakara"
"src/bakara/**.cpp", "src/bakara/**.cpp",
"src/platforms/**.h", "src/platforms/**.h",
"src/platforms/**.cpp", "src/platforms/**.cpp",
"src/*pch.*",
} }
defines defines
{ {
"_CRT_SECURE_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS",
"GLFW_INCLUDE_NONE", "GLFW_INCLUDE_NONE",
"BKMOD_ALL"
} }
includedirs includedirs
@ -40,7 +38,7 @@ project "bakara"
"bakatools", "bakatools",
"GLFW", "GLFW",
"GLAD", "GLAD",
"ImGuiDocking" "ImGui"
} }
filter "configurations:Debug" filter "configurations:Debug"

@ -19,8 +19,12 @@ namespace Bk {
void Application::on_event(Event& e) void Application::on_event(Event& e)
{ {
EventDispatcher dispatcher(e); EventDispatcher dispatcher(e);
if (!(dispatcher.dispatch<WindowCloseEvent>(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close)) || dispatcher.dispatch<MouseButtonPressEvent>(BK_BIND_DISPACHER_FN(MouseButtonPressEvent, Mouse::button_callback));
dispatcher.dispatch<WindowResizeEvent>(BK_BIND_DISPACHER_FN(WindowResizeEvent, on_window_resize)))) 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))))
{ {
for(auto it = p_layer_stack.rbegin(); it != p_layer_stack.rend(); it++) for(auto it = p_layer_stack.rbegin(); it != p_layer_stack.rend(); it++)
{ {
@ -58,6 +62,8 @@ namespace Bk {
layer->imgui_render(); layer->imgui_render();
imgui_layer->end(); imgui_layer->end();
h_window->on_update(); h_window->on_update();
} }
} }

@ -4,11 +4,12 @@
This file contains the main app abstraction. This file contains the main app abstraction.
*/ */
#include <bakarapch.h> #include "bakara.pch"
#include <bakara/core/window.h> #include "bakara/core/window.h"
#include <bakara/events/events.h> #include "bakara/events/events.h"
#include <bakara/core/layer_stack.h> #include "bakara/io/mouse.h"
#include <bakara/imgui/imgui_layer.h> #include "bakara/core/layer_stack.h"
#include "bakara/imgui/imgui_layer.h"
namespace Bk { namespace Bk {
/*! \class Bk::Application /*! \class Bk::Application

@ -1,4 +1,4 @@
#include <bakarapch.h> #include "bakara.pch"
#include "application.h" #include "application.h"
/*! \file entry.cpp /*! \file entry.cpp

@ -1,5 +1,5 @@
#pragma once #pragma once
#include <bakarapch.h> #include "bakara.pch"
#include <bakara/events/events.h> #include <bakara/events/events.h>
namespace Bk { namespace Bk {

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <bakarapch.h> #include "bakara.pch"
#include "layer.h" #include "layer.h"
namespace Bk { namespace Bk {

@ -5,7 +5,7 @@ This file contiens all the interfaces to create a window.
Implementation possible with GLFW, Win32, etc. Implementation possible with GLFW, Win32, etc.
*/ */
#include <bakarapch.h> #include "bakara.pch"
#include <bakara/events/event.h> #include <bakara/events/event.h>
namespace Bk { namespace Bk {

@ -0,0 +1,29 @@
#pragma once
#include "bakara.pch"
#include "event.h"
namespace Bk {
class EventDispatcher
{
public:
EventDispatcher(Event& event)
: p_event(event) {}
// F will be deduced by the compiler
template<typename T, typename F>
bool dispatch(const F& func)
{
if (p_event.get_event_type() == T::get_static_type())
{
p_event.handled |= func(static_cast<T&>(p_event));
return true;
}
return false;
}
inline Event& get_event() { return p_event; }
private:
Event& p_event;
};
}

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <bakarapch.h> #include "bakara.pch"
#define BK_BIND_EVENT_FN(fn) [this](Event& e) { fn(e); } #define BK_BIND_EVENT_FN(fn) [this](Event& e) { fn(e); }
#define BK_BIND_DISPACHER_FN(event, fn) [this](event& e) -> bool{ return fn(e); } #define BK_BIND_DISPACHER_FN(event, fn) [this](event& e) -> bool{ return fn(e); }

@ -1,6 +1,6 @@
#include "imgui_layer.h" #include "imgui_layer.h"
#include "bakarapch.h" #include "bakara.pch"
#include "bakara/core/application.h" #include "bakara/core/application.h"
@ -21,16 +21,12 @@ namespace Bk {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.IniFilename = NULL; io.IniFilename = NULL;
#if defined(BK_IMGUI_DOCKING)
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
//io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
io.ConfigViewportsNoAutoMerge = true; io.ConfigViewportsNoAutoMerge = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
@ -38,6 +34,11 @@ namespace Bk {
style.WindowRounding = 0.0f; style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f; style.Colors[ImGuiCol_WindowBg].w = 1.0f;
} }
#endif
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
Application& app = Application::get(); Application& app = Application::get();
GLFWwindow* window = static_cast<GLFWwindow*>(app.get_window().get_native_window()); GLFWwindow* window = static_cast<GLFWwindow*>(app.get_window().get_native_window());
@ -56,6 +57,9 @@ namespace Bk {
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());
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
@ -63,14 +67,10 @@ namespace Bk {
void ImguiLayer::end() void ImguiLayer::end()
{ {
ImGuiIO& io = ImGui::GetIO();
Application& app = Application::get();
io.DisplaySize = ImVec2((float)app.get_window().get_width(), (float)app.get_window().get_height());
// Rendering // Rendering
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
#if defined(BK_IMGUI_DOCKING)
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{ {
GLFWwindow* backup_current_context = glfwGetCurrentContext(); GLFWwindow* backup_current_context = glfwGetCurrentContext();
@ -78,5 +78,6 @@ namespace Bk {
ImGui::RenderPlatformWindowsDefault(); ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context); glfwMakeContextCurrent(backup_current_context);
} }
#endif
} }
} }

@ -1,20 +0,0 @@
#pragma once
#include "bakarapch.h"
#include "io_codes.h"
namespace Bk
{
class Input
{
static bool key_down(KeyCode key);
static bool key_released(KeyCode key);
static bool key_pressed(KeyCode key);
static bool mouse_button_down(MouseCode btn);
static bool mouse_button_released(MouseCode btn);
static bool mouse_button_pressed(MouseCode btn);
static Vec2 mouse_position();
};
}

@ -0,0 +1,101 @@
#include "mouse.h"
namespace Bk
{
double Mouse::x = 0;
double Mouse::y = 0;
double Mouse::lastX = 0;
double Mouse::lastY = 0;
double Mouse::dX = 0;
double Mouse::dY = 0;
double Mouse::scrollDX = 0;
double Mouse::scrollDY = 0;
bool Mouse::firstMouse;
std::vector<bool> Mouse::buttons = { 0 };
std::vector<bool> Mouse::buttonsChanged = { 0 };
bool Mouse::cursor_callback(MouseMoveEvent& e) {
x = e.get_x();
y = e.get_y();
if(firstMouse) {
lastX = x;
lastY = y;
firstMouse = false;
}
dX = x - lastX;
dY = y -lastY;
lastX = x;
lastY = y;
return false;
}
bool Mouse::button_callback(MouseButtonEvent& e) {
if (e.get_name() != "MouseButtonRelease") {
if(!buttons[e.get_btn()]) {
buttons[e.get_btn()] = true;
}
} else {
buttons[e.get_btn()] = false;
}
buttonsChanged[e.get_btn()] = true;
return false;
}
bool Mouse::wheel_callback(MouseScrollEvent& e) {
scrollDX = e.get_dx();
scrollDY = e.get_dy();
return false;
}
Vec2 Mouse::get_position() {
return Vec2(x, y);
}
double Mouse::get_dx() {
double _dX = dX;
dX = 0;
return _dX;
}
double Mouse::get_dy() {
double _dY = dY;
dY = 0;
return _dY;
}
double Mouse::get_scroll_dx() {
double _scrollDX = scrollDX;
scrollDX = 0;
return _scrollDX;
}
double Mouse::get_scroll_dy() {
double _scrollDY = scrollDY;
scrollDY = 0;
return _scrollDY;
}
bool Mouse::button(MouseCode button) {
return buttons[button];
}
bool Mouse::button_up(MouseCode button) {
return !buttons[button] && buttonChanged(button);
}
bool Mouse::button_down(MouseCode button) {
return buttons[button] && buttonChanged(button);
}
bool Mouse::buttonChanged(MouseCode button) {
bool ret = buttonsChanged[button];
buttons[button] = false;
return ret;
}
}

@ -0,0 +1,49 @@
#pragma once
#include "bakara.pch"
#include "mouse_codes.h"
#include "bakara/events/mouse_event.h"
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);
//Mouse position assesors
static Vec2 get_position();
//Mouse scroll assesors
static double get_dx();
static double get_dy();
static double get_scroll_dx();
static double get_scroll_dy();
//Mouse buttons assesors
static bool button(MouseCode button);
static bool button_up(MouseCode button);
static bool button_down(MouseCode button);
private:
static double x;
static double y;
static double lastX;
static double lastY;
static double dX;
static double dY;
static double scrollDX;
static double scrollDY;
static bool firstMouse;
static std::vector<bool> buttons;
static std::vector<bool> buttonsChanged;
static bool buttonChanged(MouseCode button);
};
}

@ -0,0 +1,11 @@
#pragma once
namespace Bk
{
class GraphicsContext
{
public:
virtual void init() = 0;
virtual void swap_buffers() = 0;
};
}

@ -1 +0,0 @@
#include "bakarapch.h"

@ -1,14 +1,16 @@
#include "glfw_window.h"
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <string.h> #include <string.h>
#include "glfw_window.h"
namespace Bk { namespace Bk {
Window* Window::create_window(const WindowProps& props) Window* Window::create_window(const WindowProps& props)
{ {
return new Plaform::WinGLFW(props); return new Platform::WinGLFW(props);
} }
namespace Plaform { namespace Platform {
static uint p_glfw_initialized = 0; static uint p_glfw_initialized = 0;
static void glfw_error_callback(int error, const char* description) static void glfw_error_callback(int error, const char* description)
@ -26,6 +28,7 @@ namespace Bk {
WinGLFW::~WinGLFW() WinGLFW::~WinGLFW()
{ {
delete context;
close(); close();
} }
@ -40,16 +43,8 @@ namespace Bk {
glfwSetErrorCallback(glfw_error_callback); glfwSetErrorCallback(glfw_error_callback);
} }
p_window = glfwCreateWindow((int)p_data.width, (int)p_data.height, p_data.title.c_str(), nullptr, nullptr); p_window = glfwCreateWindow((int)p_data.width, (int)p_data.height, p_data.title.c_str(), nullptr, nullptr);
glfwMakeContextCurrent(p_window); context = new OpenglContext(p_window);
context->init();
int success = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
BK_CORE_MSG_ASSERT(success, "Couldn't load glad!")
GLint majVers = 0, minVers = 0;
glGetIntegerv(GL_MAJOR_VERSION, &majVers);
glGetIntegerv(GL_MINOR_VERSION, &minVers);
BK_CORE_INFO("Opengl Version : {0}.{1}", majVers, minVers);
glfwSetWindowUserPointer(p_window, &p_data); glfwSetWindowUserPointer(p_window, &p_data);
set_vsync(true); set_vsync(true);
@ -132,12 +127,10 @@ namespace Bk {
void WinGLFW::on_update() void WinGLFW::on_update()
{ {
glfwPollEvents();
context->swap_buffers();
if (h_is_open) if (h_is_open)
{ {
glClearColor(1,0,0.5,1);
glClear(GL_COLOR_BUFFER_BIT);
glfwPollEvents();
glfwSwapBuffers(p_window);
if (p_shutdown && h_is_open) { shutdown(); } if (p_shutdown && h_is_open) { shutdown(); }
} }
} }

@ -1,10 +1,12 @@
#pragma once #pragma once
#include <bakarapch.h> #include "bakara.pch"
#include <bakara/core/window.h> #include "bakara/core/window.h"
#include <bakara/events/events.h> #include "bakara/events/events.h"
#include <GLFW/glfw3.h> #include "platforms/opengl/opengl_context.h"
namespace Bk::Plaform { struct GLFWwindow;
namespace Bk::Platform {
class WinGLFW : public Window class WinGLFW : public Window
{ {
public: public:
@ -31,9 +33,10 @@ namespace Bk::Plaform {
bool is_open() override { return h_is_open; } bool is_open() override { return h_is_open; }
private: private:
bool h_is_open; //!< indicaste if the window is opened or not bool h_is_open; //!< indicaste if the window is opened or not
GLFWwindow* p_window;
bool p_shutdown; bool p_shutdown;
GLFWwindow* p_window;
OpenglContext* context;
struct WindowData struct WindowData
{ {
std::string title; std::string title;

@ -0,0 +1,27 @@
#include "opengl_context.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
namespace Bk::Platform
{
OpenglContext::OpenglContext(GLFWwindow* window_handle)
: window_handle(window_handle) {}
void OpenglContext::init()
{
glfwMakeContextCurrent(window_handle);
int success = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
BK_CORE_MSG_ASSERT(success, "Couldn't load glad!")
GLint majVers = 0, minVers = 0;
glGetIntegerv(GL_MAJOR_VERSION, &majVers);
glGetIntegerv(GL_MINOR_VERSION, &minVers);
BK_CORE_INFO("Opengl Version : {0}.{1}", majVers, minVers);
}
void OpenglContext::swap_buffers()
{
glfwSwapBuffers(window_handle);
}
}

@ -0,0 +1,19 @@
#pragma once
#include "bakara.pch"
#include "bakara/renderer/graphics_context.h"
struct GLFWwindow;
namespace Bk::Platform
{
class OpenglContext : public GraphicsContext
{
public:
OpenglContext(GLFWwindow* window_handle);
void init() override;
void swap_buffers() override;
private:
GLFWwindow* window_handle;
};
}
Loading…
Cancel
Save