添加opengl框架并测试渲染第一个三角形

This commit is contained in:
2025-04-21 13:29:10 +08:00
parent 899c62bfeb
commit ffc50ef8a7
25 changed files with 8524 additions and 73 deletions

7
.gitmodules vendored
View File

@ -4,3 +4,10 @@
[submodule "Hazel/vendor/SDL"]
path = Hazel/vendor/SDL
url = https://github.com/libsdl-org/SDL
[submodule "Hazel/vendor/imgui"]
path = Hazel/vendor/imgui
url = https://github.com/ocornut/imgui.git
branch = docking
[submodule "Hazel/vendor/glm"]
path = Hazel/vendor/glm
url = https://github.com/g-truc/glm.git

View File

@ -1,12 +1,23 @@
set(PROJECT_NAME Hazel)
project(${PROJECT_NAME})
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_library(Hazel SHARED ${SOURCES})
add_subdirectory(vendor/spdlog)
add_subdirectory(vendor/GLAD)
add_subdirectory(vendor/glm)
file(GLOB_RECURSE SOURCES "src/*.cpp")
include_directories(vendor/imgui)
include_directories(vendor/imgui/backends)
file(GLOB IMGUI vendor/imgui/**.cpp
vendor/imgui/backends/imgui_impl_opengl3.cpp
vendor/imgui/backends/imgui_impl_sdl3.cpp)
add_library(Hazel SHARED ${SOURCES} ${IMGUI})
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE)
@ -17,15 +28,23 @@ set(SDL3_SHARED ON CACHE BOOL "Build SDL as shared library" FORCE)
target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src # 暴露头文件给其他项目
vendor/imgui
vendor/imgui/backends
)
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog SDL3::SDL3)
target_link_libraries(${PROJECT_NAME} PUBLIC
spdlog::spdlog
SDL3::SDL3
glad
opengl32
glm::glm
)
target_compile_definitions(${PROJECT_NAME} PRIVATE HZ_BUILD_DLL)# 编译DLL时定义
if(WIN32)
target_compile_definitions(${PROJECT_NAME} PUBLIC HZ_PLATFORM_WINDOWS)# 编译DLL时定义
target_compile_definitions(${PROJECT_NAME} PUBLIC HZ_PLATFORM_WINDOWS IMGUI_API=__declspec\(dllexport\))# 编译DLL时定义
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif ()

View File

@ -1,9 +1,12 @@
#pragma once
// For use by Hazel Applications
#include "Hazel/Core.h"
#include "Hazel/Application.h"
#include "Hazel/Log.h"
#include "Hazel/Window.h"
#include "Hazel/ImGui/ImGuiLayer.h"
#include "Hazel/Renderer/GraphicsContext.h"
// ------------------------ Entry Point ------------------------

View File

@ -1,15 +1,62 @@
#include "Application.h"
#include <imgui_impl_opengl3_loader.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_opengl_glext.h>
#include "Log.h"
namespace Hazel {
Application* Application::s_Instance = nullptr;
Application::Application()
{
if (s_Instance != nullptr)
{
HZ_CORE_ERROR("Application already exists!");
}
s_Instance = this;
m_Window = std::unique_ptr<Window>(Window::Create());
m_Window->SetEventCallback(std::bind(&Application::OnEvent, this, std::placeholders::_1));
m_imguiLayer = new ImGuiLayer();
PushOverlay(m_imguiLayer);
// Vertex Array
glGenVertexArrays(1, &m_VertexArray);
glBindVertexArray(m_VertexArray);
// Vertex Buffer
glGenBuffers(1, &m_VertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
float vertices[3 * 3] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
};
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
// Index Buffer
glGenBuffers(1, &m_IndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBuffer);
uint32_t indices[3] = { 0, 1, 2 };
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// Shader
}
Application::~Application() = default;
@ -17,6 +64,25 @@ namespace Hazel {
void Application::Run() {
while (m_Running)
{
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(m_VertexArray);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
for (Layer* layer : m_layerStack)
{
layer->OnUpdate();
}
m_imguiLayer->Begin();
for (Layer* layer : m_layerStack)
{
layer->OnImGuiRender();
}
m_imguiLayer->End();
// HZ_CORE_INFO("{}", Input::IsKeyPressed(HZ_KEY_0));
m_Window->OnUpdate();
}
@ -24,16 +90,26 @@ namespace Hazel {
void Application::OnEvent(SDL_Event& e)
{
while (SDL_PollEvent(&e))
for (auto it = m_layerStack.end(); it != m_layerStack.begin();)
{
switch (e.type)
{
case SDL_EVENT_QUIT:
m_Running = false;
break;
default:
break;
}
(*--it)->OnEvent(e);
}
if (e.type == SDL_EVENT_QUIT)
{
m_Running = false;
}
}
void Application::PushLayer(Layer* layer)
{
m_layerStack.PushLayer(layer);
}
void Application::PushOverlay(Layer* layer)
{
m_layerStack.PushOverlay(layer);
layer->OnAttach();
}
}

View File

@ -3,6 +3,9 @@
#include <Platform/Windows/WindowsWindow.h>
#include "Core.h"
#include "Layer.h"
#include "LayerStack.h"
#include "ImGui/ImGuiLayer.h"
namespace Hazel {
@ -15,13 +18,25 @@ namespace Hazel {
void Run();
void OnEvent(SDL_Event& e);
void PushLayer(Layer* layer);
void PushOverlay(Layer* layer);
inline Window& GetWindow() { return *m_Window; }
inline static Application& Get() { return *s_Instance; }
private:
std::unique_ptr<Hazel::Window> m_Window;
ImGuiLayer* m_imguiLayer;
bool m_Running = true;
LayerStack m_layerStack;
unsigned m_VertexArray, m_VertexBuffer, m_IndexBuffer;
private:
static Application* s_Instance;
};
// to be defined int CLIENT
// to be defined int CLIENT
Application* CreateApplication();
}

View File

@ -8,21 +8,6 @@ extern Hazel::Application* Hazel::CreateApplication();
int main(int argc, char* argv[]) {
Hazel::Log::init();
HZ_CORE_TRACE("hello");
HZ_CORE_DEBUG("hello");
HZ_CORE_INFO("hello");
HZ_CORE_WARN("hello");
HZ_CORE_ERROR("hello");
HZ_CORE_FATAL("hello");
HZ_CLIENT_TRACE("hello");
HZ_CLIENT_DEBUG("hello");
HZ_CLIENT_INFO("hello");
HZ_CLIENT_WARN("hello");
HZ_CLIENT_ERROR("hello");
HZ_CLIENT_FATAL("hello");
auto app = Hazel::CreateApplication();
app->Run();
}

View File

@ -0,0 +1,95 @@
//
// Created by sfd on 25-4-19.
//
#include "ImGuiLayer.h"
#include <imgui.h>
#include <imgui_impl_opengl3.h>
#include <imgui_impl_sdl3.h>
#include <Hazel/Application.h>
namespace Hazel
{
ImGuiLayer::ImGuiLayer() : Layer("ImGuiLayer")
{
}
ImGuiLayer::~ImGuiLayer()
{
}
void ImGuiLayer::OnAttach()
{
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui::StyleColorsDark();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiBackendFlags_HasMouseCursors;
io.ConfigFlags |= ImGuiBackendFlags_HasSetMousePos;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // IF using Docking Branch
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
Application& app = Application::Get();
auto window = static_cast<SDL_Window*>(app.GetWindow().GetNativeWindow());
auto GL_Context = static_cast<SDL_GLContext>(app.GetWindow().GetNativeGLContext());
ImGui_ImplSDL3_InitForOpenGL(window, GL_Context);
ImGui_ImplOpenGL3_Init("#version 460");
// ------
}
void ImGuiLayer::OnDetech()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();
}
void ImGuiLayer::OnEvent(SDL_Event& e)
{
ImGui_ImplSDL3_ProcessEvent(&e);
}
void ImGuiLayer::OnImGuiRender()
{
ImGui::ShowDemoWindow();
}
void ImGuiLayer::Begin()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
}
void ImGuiLayer::End()
{
ImGuiIO& io = ImGui::GetIO();
Application& app = Application::Get();
io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight());
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
}
}
}

View File

@ -0,0 +1,32 @@
//
// Created by sfd on 25-4-19.
//
#ifndef IMGUILAYER_H
#define IMGUILAYER_H
#include <Hazel/Layer.h>
namespace Hazel {
class HAZEL_API ImGuiLayer : public Layer
{
public:
ImGuiLayer();
~ImGuiLayer();
void OnAttach() override;
void OnDetech() override;
void OnEvent(SDL_Event& e) override;
void OnImGuiRender() override;
void Begin();
void End();
private:
float m_Time = 0.0f;
};
}
#endif //IMGUILAYER_H

View File

@ -21,7 +21,8 @@ namespace Hazel {
virtual void OnAttach() {}
virtual void OnDetech() {}
virtual void OnUpdate() {}
virtual void OnEvent(SDL_Event& event) {}
virtual void OnImGuiRender() {}
virtual void OnEvent(SDL_Event& e) {}
inline const std::string& GetName() const { return m_DebugName; }

View File

@ -3,3 +3,50 @@
//
#include "LayerStack.h"
namespace Hazel
{
LayerStack::LayerStack()
{
}
LayerStack::~LayerStack()
{
for (Layer* layer : m_layers)
{
delete layer;
}
}
void LayerStack::PushLayer(Layer* layer)
{
m_layers.emplace(m_layers.begin() + m_LayerInsertIndex++, layer);
}
void LayerStack::PushOverlay(Layer* layer)
{
m_layers.emplace_back(layer);
}
void LayerStack::PopLayer(Layer* layer)
{
auto it = std::ranges::find(m_layers.begin(), m_layers.end(), layer);
if (it != m_layers.end())
{
m_layers.erase(it);
m_LayerInsertIndex--;
}
}
void LayerStack::PopOverlay(Layer* layer)
{
auto it = std::ranges::find(m_layers.begin(), m_layers.end(), layer);
if (it != m_layers.end())
{
m_layers.erase(it);
}
}
}

View File

@ -12,25 +12,25 @@
namespace Hazel
{
// class HAZEL_API LayerStack
// {
// public:
// LayerStack();
// ~LayerStack();
//
// void PushLayer(Layer* layer);
// void PushOverlay(Layer* layer);
// void PopLayer(Layer* layer);
// void PopOverlay(Layer* layer);
//
// std::vector<Layer*>::iterator begin() {}
// std::vector<Layer*>::iterator end() {}
//
// private:
// std::vector<Layer*> m_layers;
// std::vector<Layer*>::iterator m_LayerInsert;
//
// };
class HAZEL_API LayerStack
{
public:
LayerStack();
~LayerStack();
void PushLayer(Layer* layer);
void PushOverlay(Layer* layer);
void PopLayer(Layer* layer);
void PopOverlay(Layer* layer);
std::vector<Layer*>::iterator begin() {return m_layers.begin();}
std::vector<Layer*>::iterator end() { return m_layers.end(); }
private:
std::vector<Layer*> m_layers;
unsigned int m_LayerInsertIndex = 0;
};
}

View File

@ -0,0 +1,23 @@
//
// Created by sfd on 25-4-21.
//
#ifndef GRAPHICSCONTEXT_H
#define GRAPHICSCONTEXT_H
#include "Hazel/Core.h"
namespace Hazel
{
class HAZEL_API GraphicsContext
{
public:
virtual void Init() = 0;
virtual void SwapBuffers() = 0;
virtual void* GetGLContext() = 0;
};
}
#endif //GRAPHICSCONTEXT_H

View File

@ -43,6 +43,10 @@ namespace Hazel
static Window* Create(const WindowProps& props = WindowProps());
virtual void* GetNativeWindow() const = 0;
virtual void* GetNativeGLContext() const = 0;
};
}

View File

@ -0,0 +1,44 @@
//
// Created by sfd on 25-4-21.
//
#include "OpenGLContext.h"
#include <Hazel/Log.h>
#include <SDL3/SDL_opengl.h>
namespace Hazel
{
OpenGLContext::OpenGLContext(SDL_Window* windowHandle) : m_windowHandle(windowHandle)
{
}
void OpenGLContext::Init()
{
m_GLContext = SDL_GL_CreateContext(m_windowHandle);
if (!m_GLContext)
{
HZ_CORE_ERROR("Could not create OpenGL context: {}", SDL_GetError());
exit(EXIT_FAILURE);
}
const GLubyte* vender = glGetString(GL_VENDOR);
const GLubyte* renderer = glGetString(GL_RENDERER);
const GLubyte* version = glGetString(GL_VERSION);
HZ_CORE_INFO("OpenGL info: ");
HZ_CORE_INFO(" Vender: {0}", reinterpret_cast<const char*>(vender));
HZ_CORE_INFO(" Renderer: {0}", reinterpret_cast<const char*>(renderer));
HZ_CORE_INFO(" Version: {0}", reinterpret_cast<const char*>(version));
}
void OpenGLContext::SwapBuffers()
{
SDL_GL_SwapWindow(m_windowHandle);
}
void* OpenGLContext::GetGLContext()
{
return m_GLContext;
}
}

View File

@ -0,0 +1,30 @@
//
// Created by sfd on 25-4-21.
//
#ifndef OPENGLCONTEXT_H
#define OPENGLCONTEXT_H
#include <Hazel/Renderer/GraphicsContext.h>
#include <SDL3/SDL_video.h>
struct SDL_Window;
namespace Hazel
{
class OpenGLContext : public GraphicsContext
{
public:
OpenGLContext(SDL_Window* windowHandle);
void Init() override;
void SwapBuffers() override;
void *GetGLContext() override;
private:
SDL_Window* m_windowHandle;
SDL_GLContext m_GLContext;
};
}
#endif //OPENGLCONTEXT_H

View File

@ -4,7 +4,10 @@
#include "WindowsWindow.h"
#include <iostream>
#include <Hazel/Log.h>
#include <Platform/OpenGL/OpenGLContext.h>
#include <glad/glad.h>
namespace Hazel
@ -46,23 +49,33 @@ namespace Hazel
s_SDLInitialized = true;
}
m_Window = SDL_CreateWindow(m_Data.title.c_str(), props.width, props.height, 0);
HZ_CORE_INFO("Creating Renderer...");
m_Renderer = SDL_CreateRenderer(m_Window, nullptr);
if (m_Renderer == nullptr)
m_Window = SDL_CreateWindow(m_Data.title.c_str(), props.width, props.height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!m_Window)
{
HZ_CORE_ERROR("Could not create renderer: {}", SDL_GetError());
HZ_CORE_ERROR("Could not create window: {}", SDL_GetError());
exit(EXIT_FAILURE);
}
m_Context = new OpenGLContext(m_Window);
m_Context->Init();
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
HZ_CORE_INFO("Initing GLAD...");
if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
{
HZ_CORE_ERROR("Could not initialize GLAD context!");
}
SetVSync(true);
}
void WindowsWindow::Shutdown()
{
SDL_DestroyRenderer(m_Renderer);
SDL_DestroyWindow(m_Window);
SDL_Quit();
}
@ -70,22 +83,16 @@ namespace Hazel
void WindowsWindow::OnUpdate()
{
SDL_Event event;
if (m_Data.eventCallback != nullptr)
{
m_Data.eventCallback(event);
}
while (SDL_PollEvent(&event))
{
if (event.type == SDL_EVENT_QUIT)
if (m_Data.eventCallback != nullptr)
{
//TODO: quit this window
m_Data.eventCallback(event);
}
}
SDL_SetRenderDrawColor(m_Renderer, 0, 0, 0, 0xFF);
SDL_RenderClear(m_Renderer);
SDL_RenderPresent(m_Renderer);
m_Context->SwapBuffers();
}
void WindowsWindow::SetVSync(bool enabled)
@ -106,5 +113,4 @@ namespace Hazel
{
return m_Data.vSync;
}
}

View File

@ -5,12 +5,16 @@
#ifndef WINDOWSWINDOW_H
#define WINDOWSWINDOW_H
#include <Hazel/Renderer/GraphicsContext.h>
#include "Hazel/Window.h"
#include <SDL3/SDL.h>
namespace Hazel
{
class GraphicsContext;
class WindowsWindow : public Window
{
public:
@ -28,13 +32,16 @@ namespace Hazel
void SetVSync(bool enabled) override;
bool IsVSync() const override;
void* GetNativeWindow() const override {return m_Window;}
void* GetNativeGLContext() const override {return m_Context->GetGLContext();}
private:
virtual void Init(const WindowProps& props);
virtual void Shutdown();
private:
SDL_Window* m_Window;
SDL_Renderer* m_Renderer;
SDL_Window* m_Window;
GraphicsContext* m_Context;
struct WindowData
{

5
Hazel/vendor/GLAD/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,5 @@
project(glad)
add_library(glad STATIC src/glad.c)
target_include_directories(glad PUBLIC include)

View File

@ -0,0 +1,311 @@
#ifndef __khrplatform_h_
#define __khrplatform_h_
/*
** Copyright (c) 2008-2018 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/* Khronos platform-specific types and definitions.
*
* The master copy of khrplatform.h is maintained in the Khronos EGL
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
* The last semantic modification to khrplatform.h was at commit ID:
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
*
* Adopters may modify this file to suit their platform. Adopters are
* encouraged to submit platform specific modifications to the Khronos
* group so that they can be included in future versions of this file.
* Please submit changes by filing pull requests or issues on
* the EGL Registry repository linked above.
*
*
* See the Implementer's Guidelines for information about where this file
* should be located on your system and for more details of its use:
* http://www.khronos.org/registry/implementers_guide.pdf
*
* This file should be included as
* #include <KHR/khrplatform.h>
* by Khronos client API header files that use its types and defines.
*
* The types in khrplatform.h should only be used to define API-specific types.
*
* Types defined in khrplatform.h:
* khronos_int8_t signed 8 bit
* khronos_uint8_t unsigned 8 bit
* khronos_int16_t signed 16 bit
* khronos_uint16_t unsigned 16 bit
* khronos_int32_t signed 32 bit
* khronos_uint32_t unsigned 32 bit
* khronos_int64_t signed 64 bit
* khronos_uint64_t unsigned 64 bit
* khronos_intptr_t signed same number of bits as a pointer
* khronos_uintptr_t unsigned same number of bits as a pointer
* khronos_ssize_t signed size
* khronos_usize_t unsigned size
* khronos_float_t signed 32 bit floating point
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for
* booleans cannot use this as the base type for their boolean.
*
* Tokens defined in khrplatform.h:
*
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
*
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
*
* Calling convention macros defined in this file:
* KHRONOS_APICALL
* KHRONOS_APIENTRY
* KHRONOS_APIATTRIBUTES
*
* These may be used in function prototypes as:
*
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
* int arg1,
* int arg2) KHRONOS_APIATTRIBUTES;
*/
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
# define KHRONOS_STATIC 1
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APICALL
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
#if defined(KHRONOS_STATIC)
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
* header compatible with static linking. */
# define KHRONOS_APICALL
#elif defined(_WIN32)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
#elif defined(__ANDROID__)
# define KHRONOS_APICALL __attribute__((visibility("default")))
#else
# define KHRONOS_APICALL
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIENTRY
*-------------------------------------------------------------------------
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else
# define KHRONOS_APIENTRY
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIATTRIBUTES
*-------------------------------------------------------------------------
* This follows the closing parenthesis of the function prototype arguments.
*/
#if defined (__ARMCC_2__)
#define KHRONOS_APIATTRIBUTES __softfp
#else
#define KHRONOS_APIATTRIBUTES
#endif
/*-------------------------------------------------------------------------
* basic type definitions
*-----------------------------------------------------------------------*/
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
/*
* Using <stdint.h>
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
/*
* To support platform where unsigned long cannot be used interchangeably with
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
* unsigned long long or similar (this results in different C++ name mangling).
* To avoid changes for existing platforms, we restrict usage of intptr_t to
* platforms where the size of a pointer is larger than the size of long.
*/
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
#define KHRONOS_USE_INTPTR_T
#endif
#endif
#elif defined(__VMS ) || defined(__sgi)
/*
* Using <inttypes.h>
*/
#include <inttypes.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
/*
* Win32
*/
typedef __int32 khronos_int32_t;
typedef unsigned __int32 khronos_uint32_t;
typedef __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__sun__) || defined(__digital__)
/*
* Sun or Digital
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#if defined(__arch64__) || defined(_LP64)
typedef long int khronos_int64_t;
typedef unsigned long int khronos_uint64_t;
#else
typedef long long int khronos_int64_t;
typedef unsigned long long int khronos_uint64_t;
#endif /* __arch64__ */
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif 0
/*
* Hypothetical platform with no float or int64 support
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#define KHRONOS_SUPPORT_INT64 0
#define KHRONOS_SUPPORT_FLOAT 0
#else
/*
* Generic fallback
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#endif
/*
* Types that are (so far) the same on all platforms
*/
typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t;
/*
* Types that differ between LLP64 and LP64 architectures - in LLP64,
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
* to be the only LLP64 architecture in current use.
*/
#ifdef KHRONOS_USE_INTPTR_T
typedef intptr_t khronos_intptr_t;
typedef uintptr_t khronos_uintptr_t;
#elif defined(_WIN64)
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
#else
typedef signed long int khronos_intptr_t;
typedef unsigned long int khronos_uintptr_t;
#endif
#if defined(_WIN64)
typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t;
#else
typedef signed long int khronos_ssize_t;
typedef unsigned long int khronos_usize_t;
#endif
#if KHRONOS_SUPPORT_FLOAT
/*
* Float type
*/
typedef float khronos_float_t;
#endif
#if KHRONOS_SUPPORT_INT64
/* Time types
*
* These types can be used to represent a time interval in nanoseconds or
* an absolute Unadjusted System Time. Unadjusted System Time is the number
* of nanoseconds since some arbitrary system event (e.g. since the last
* time the system booted). The Unadjusted System Time is an unsigned
* 64 bit value that wraps back to 0 every 584 years. Time intervals
* may be either signed or unsigned.
*/
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t;
#endif
/*
* Dummy value used to pad enum types to 32 bits.
*/
#ifndef KHRONOS_MAX_ENUM
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
#endif
/*
* Enumerated boolean type
*
* Values other than zero should be considered to be true. Therefore
* comparisons should not be made against KHRONOS_TRUE.
*/
typedef enum {
KHRONOS_FALSE = 0,
KHRONOS_TRUE = 1,
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
} khronos_boolean_enum_t;
#endif /* __khrplatform_h_ */

5169
Hazel/vendor/GLAD/include/glad/glad.h vendored Normal file

File diff suppressed because it is too large Load Diff

2532
Hazel/vendor/GLAD/src/glad.c vendored Normal file

File diff suppressed because it is too large Load Diff

1
Hazel/vendor/glm vendored Submodule

Submodule Hazel/vendor/glm added at 2d4c4b4dd3

1
Hazel/vendor/imgui vendored Submodule

Submodule Hazel/vendor/imgui added at 87f12e56fe

View File

@ -1,9 +1,9 @@
set(PROJECT_NAME "Sandbox")
project(${PROJECT_NAME})
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE Hazel)

View File

@ -1,17 +1,55 @@
#include <Hazel.h>
#include "imgui.h"
#include "imgui_impl_sdl2.h"
#include "imgui_impl_opengl3.h"
class ExampleLayer : public Hazel::Layer
{
public:
ExampleLayer() : Layer("ExampleLayer")
{
}
void OnUpdate() override
{
}
void OnEvent(SDL_Event& event) override
{
if (event.type == SDL_EVENT_KEY_DOWN)
{
HZ_CORE_TRACE("{}", event.key.key);
}
}
void OnImGuiRender() override
{
ImGui::Begin("Hazel Layer");
ImGui::Text("Hello World");
ImGui::End();
}
};
class Sandbox : public Hazel::Application
{
public:
Sandbox();
Sandbox()
{
PushLayer(new ExampleLayer());
}
~Sandbox();
private:
};
Sandbox::Sandbox() = default;
Sandbox::~Sandbox() = default;