Engine as library (both static & shared) #1
102
CMakeLists.txt
102
CMakeLists.txt
@ -1,6 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(CodingGame LANGUAGES C CXX)
|
||||
|
||||
set(ENGINE_TARGET engine)
|
||||
|
||||
# ---------- Build-type defaults (only affects single-config generators like Ninja/Make) ----------
|
||||
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
||||
@ -12,7 +14,7 @@ if (UNIX)
|
||||
FetchContent_Declare(
|
||||
glm
|
||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||
GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e # refs/tags/1.0.1
|
||||
GIT_TAG a532f5b1cf27d6a3c099437e6959cf7e398a0a67 # refs/tags/1.0.2
|
||||
)
|
||||
FetchContent_MakeAvailable(glm)
|
||||
|
||||
@ -34,99 +36,5 @@ elseif (MSVC) # vcpkg
|
||||
find_package(EnTT CONFIG REQUIRED)
|
||||
endif()
|
||||
|
||||
add_executable(CodingGame
|
||||
src/IO/parser.cpp
|
||||
src/IO/file_manager.cpp
|
||||
|
||||
src/window/window.cpp
|
||||
|
||||
src/components/batch.cpp
|
||||
|
||||
src/renderer/debug.cpp
|
||||
src/renderer/mesh.cpp
|
||||
src/renderer/shader.cpp
|
||||
src/renderer/texture.cpp
|
||||
src/renderer/wavefront.cpp
|
||||
src/renderer/engine.cpp
|
||||
src/renderer/renderer.cpp
|
||||
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
set_property(TARGET CodingGame PROPERTY CXX_STANDARD 17)
|
||||
set_property(TARGET CodingGame PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
file(COPY src/shaders DESTINATION ${CMAKE_BINARY_DIR}/)
|
||||
|
||||
target_include_directories(CodingGame PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/contrib
|
||||
)
|
||||
target_link_libraries(CodingGame PRIVATE
|
||||
SDL3::SDL3
|
||||
OpenGL::GL
|
||||
GLEW::GLEW
|
||||
glm::glm
|
||||
EnTT::EnTT
|
||||
)
|
||||
|
||||
# ---------- Visibility (helps optimizer & smaller binaries on Release) ----------
|
||||
# Only affects non-Windows compilers
|
||||
set_target_properties(CodingGame PROPERTIES
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
VISIBILITY_INLINES_HIDDEN YES
|
||||
)
|
||||
|
||||
# ---------- Per-config flags ----------
|
||||
# Debug flags (your original intent, kept)
|
||||
if (MSVC)
|
||||
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/Zi>)
|
||||
target_link_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
|
||||
else()
|
||||
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:-ggdb>)
|
||||
endif()
|
||||
|
||||
# Release flags
|
||||
if (MSVC)
|
||||
# /O2: optimize speed, /GL: whole program opt (LTCG), /DNDEBUG: disable asserts
|
||||
target_compile_options(CodingGame PRIVATE
|
||||
$<$<CONFIG:Release>:/O2>
|
||||
$<$<CONFIG:Release>:/DNDEBUG>
|
||||
$<$<CONFIG:RelWithDebInfo>:/O2>
|
||||
)
|
||||
# Link-time codegen & extra linker opts for smaller/faster binaries
|
||||
target_link_options(CodingGame PRIVATE
|
||||
$<$<CONFIG:Release>:/LTCG /OPT:ICF /OPT:REF>
|
||||
$<$<CONFIG:RelWithDebInfo>:/LTCG /OPT:ICF /OPT:REF>
|
||||
)
|
||||
else()
|
||||
# GCC/Clang
|
||||
# -O3 for max opts, -ffast-math optional but can be risky; we keep it OFF by default.
|
||||
option(CODINGGAME_USE_MARCH_NATIVE "Enable -march=native on Release for this machine" ON)
|
||||
target_compile_options(CodingGame PRIVATE
|
||||
$<$<CONFIG:Release>:-O3>
|
||||
$<$<AND:$<CONFIG:Release>,$<BOOL:${CODINGGAME_USE_MARCH_NATIVE}>>:-march=native>
|
||||
$<$<CONFIG:Release>:-DNDEBUG>
|
||||
$<$<CONFIG:RelWithDebInfo>:-O3 -g>
|
||||
)
|
||||
# Linker: enable LTO when available; optionally strip symbols on non-Apple
|
||||
include(CheckIPOSupported) # IPO == LTO in CMake terms
|
||||
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_msg)
|
||||
if(ipo_supported)
|
||||
set_property(TARGET CodingGame PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
||||
set_property(TARGET CodingGame PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
|
||||
# -s strips symbols at link stage (use only for pure Release)
|
||||
target_link_options(CodingGame PRIVATE $<$<CONFIG:Release>:-s>)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ---------- Windows: copy runtime DLLs ----------
|
||||
if (WIN32)
|
||||
add_custom_command(TARGET CodingGame POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_RUNTIME_DLLS:CodingGame> $<TARGET_FILE_DIR:CodingGame>
|
||||
COMMAND_EXPAND_LISTS)
|
||||
endif()
|
||||
add_subdirectory(engine)
|
||||
add_subdirectory(sandbox)
|
||||
|
102
engine/CMakeLists.txt
Normal file
102
engine/CMakeLists.txt
Normal file
@ -0,0 +1,102 @@
|
||||
option(ENGINE_BUILD_SHARED "Build the Engine library as a shared library" ON)
|
||||
|
||||
set(SOURCES
|
||||
src/IO/parser.cpp
|
||||
src/IO/file_manager.cpp
|
||||
|
||||
src/window/window.cpp
|
||||
|
||||
src/components/batch.cpp
|
||||
|
||||
src/renderer/debug.cpp
|
||||
src/renderer/mesh.cpp
|
||||
src/renderer/shader.cpp
|
||||
src/renderer/texture.cpp
|
||||
src/renderer/wavefront.cpp
|
||||
src/renderer/core.cpp
|
||||
src/renderer/renderer.cpp
|
||||
|
||||
# src/main.cpp
|
||||
)
|
||||
|
||||
#if (ENGINE_BUILD_SHARED)
|
||||
# add_library(${ENGINE_TARGET} SHARED ${SOURCES})
|
||||
#else()
|
||||
# add_library(${ENGINE_TARGET} STATIC ${SOURCES})
|
||||
#endif()
|
||||
|
||||
if(ENGINE_BUILD_SHARED)
|
||||
add_library(${ENGINE_TARGET} SHARED ${SOURCES})
|
||||
if(WIN32)
|
||||
target_compile_definitions(${ENGINE_TARGET} PRIVATE ENGINE_BUILD_SHARED ENGINE_EXPORTS)
|
||||
else()
|
||||
target_compile_definitions(${ENGINE_TARGET} PRIVATE ENGINE_BUILD_SHARED)
|
||||
endif()
|
||||
else()
|
||||
add_library(${ENGINE_TARGET} STATIC ${SOURCES})
|
||||
target_compile_definitions(${ENGINE_TARGET} PRIVATE ENGINE_STATIC)
|
||||
endif()
|
||||
|
||||
set_target_properties(${ENGINE_TARGET} PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
VISIBILITY_INLINES_HIDDEN YES
|
||||
)
|
||||
|
||||
target_include_directories(${ENGINE_TARGET} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/contrib
|
||||
)
|
||||
target_link_libraries(${ENGINE_TARGET} PUBLIC
|
||||
SDL3::SDL3
|
||||
OpenGL::GL
|
||||
GLEW::GLEW
|
||||
glm::glm
|
||||
EnTT::EnTT
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:/Zi>)
|
||||
target_link_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
|
||||
else()
|
||||
target_compile_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:-ggdb>)
|
||||
endif()
|
||||
|
||||
# Release flags
|
||||
if (MSVC)
|
||||
# /O2: optimize speed, /GL: whole program opt (LTCG), /DNDEBUG: disable asserts
|
||||
target_compile_options(${ENGINE_TARGET} PRIVATE
|
||||
$<$<CONFIG:Release>:/O2>
|
||||
$<$<CONFIG:Release>:/DNDEBUG>
|
||||
$<$<CONFIG:RelWithDebInfo>:/O2>
|
||||
)
|
||||
# Link-time codegen & extra linker opts for smaller/faster binaries
|
||||
target_link_options(${ENGINE_TARGET} PRIVATE
|
||||
$<$<CONFIG:Release>:/LTCG /OPT:ICF /OPT:REF>
|
||||
$<$<CONFIG:RelWithDebInfo>:/LTCG /OPT:ICF /OPT:REF>
|
||||
)
|
||||
else()
|
||||
# GCC/Clang
|
||||
# -O3 for max opts, -ffast-math optional but can be risky; we keep it OFF by default.
|
||||
option(CODINGGAME_USE_MARCH_NATIVE "Enable -march=native on Release for this machine" ON)
|
||||
target_compile_options(${ENGINE_TARGET} PRIVATE
|
||||
$<$<CONFIG:Release>:-O3>
|
||||
$<$<AND:$<CONFIG:Release>,$<BOOL:${CODINGGAME_USE_MARCH_NATIVE}>>:-march=native>
|
||||
$<$<CONFIG:Release>:-DNDEBUG>
|
||||
$<$<CONFIG:RelWithDebInfo>:-O3 -g>
|
||||
)
|
||||
# Linker: enable LTO when available; optionally strip symbols on non-Apple
|
||||
include(CheckIPOSupported) # IPO == LTO in CMake terms
|
||||
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_msg)
|
||||
if(ipo_supported)
|
||||
set_property(TARGET ${ENGINE_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
||||
set_property(TARGET ${ENGINE_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
|
||||
# -s strips symbols at link stage (use only for pure Release)
|
||||
target_link_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Release>:-s>)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -1,7 +1,10 @@
|
||||
#ifndef APPLICATION_H_
|
||||
#define APPLICATION_H_
|
||||
|
||||
class IApplication {
|
||||
#include "engine/window/events/window.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
class ENGINE_API IApplication {
|
||||
public:
|
||||
virtual ~IApplication() = default;
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef COMPONENT_BATCH_H_
|
||||
#define COMPONENT_BATCH_H_
|
||||
|
||||
#include "renderer/renderer.h"
|
||||
#include "engine/renderer/renderer.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
// requires mesh component
|
||||
struct batch {
|
||||
struct ENGINE_API batch {
|
||||
friend class Renderer;
|
||||
public:
|
||||
// requires transform component
|
@ -1,6 +1,8 @@
|
||||
#ifndef COMPONENTS_PLAYER_H_
|
||||
#define COMPONENTS_PLAYER_H_
|
||||
|
||||
struct camera {};
|
||||
#include "engine/export.h"
|
||||
|
||||
struct ENGINE_API camera {};
|
||||
|
||||
#endif // COMPONENTS_PLAYER_H_
|
@ -2,9 +2,11 @@
|
||||
#define COMPONENTS_LIGHT_H_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "renderer/renderer.h"
|
||||
|
||||
struct light {
|
||||
#include "engine/renderer/renderer.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
struct ENGINE_API light {
|
||||
friend class Renderer;
|
||||
public:
|
||||
enum LightType {
|
@ -2,9 +2,11 @@
|
||||
#define COMPONENTS_MESH_H_
|
||||
|
||||
#include <memory>
|
||||
#include "renderer/wavefront.h"
|
||||
|
||||
struct mesh {
|
||||
#include "engine/renderer/wavefront.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
struct ENGINE_API mesh {
|
||||
std::shared_ptr<Object> object;
|
||||
};
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef COMPONENT_ROTATE_H_
|
||||
#define COMPONENT_ROTATE_H_
|
||||
|
||||
struct rotate {};
|
||||
#include "engine/export.h"
|
||||
|
||||
struct ENGINE_API rotate {};
|
||||
|
||||
#endif // COMPONENT_ROTATE_H_
|
@ -2,8 +2,9 @@
|
||||
#define COMPONENTS_TRANSFORM_H_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "engine/export.h"
|
||||
|
||||
struct transform {
|
||||
struct ENGINE_API transform {
|
||||
glm::vec3 position;
|
||||
glm::vec3 rotation;
|
||||
glm::vec3 scale;
|
17
engine/include/engine/engine.h
Normal file
17
engine/include/engine/engine.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <corecrt_math_defines.h>
|
||||
#endif
|
||||
|
||||
#include "engine/app/app.h"
|
||||
#include "engine/renderer/core.h"
|
||||
|
||||
extern IApplication* CreateApplication();
|
||||
|
||||
int main() {
|
||||
Engine::Run(std::unique_ptr<IApplication>(CreateApplication()));
|
||||
return 0;
|
||||
}
|
20
engine/include/engine/export.h
Normal file
20
engine/include/engine/export.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
// For static libs, ENGINE_API should be empty.
|
||||
#if defined(_WIN32)
|
||||
#if defined(ENGINE_BUILD_SHARED)
|
||||
#if defined(ENGINE_EXPORTS)
|
||||
#define ENGINE_API __declspec(dllexport)
|
||||
#else
|
||||
#define ENGINE_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ENGINE_API
|
||||
#endif
|
||||
#else
|
||||
#if defined(ENGINE_BUILD_SHARED)
|
||||
#define ENGINE_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define ENGINE_API
|
||||
#endif
|
||||
#endif
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "renderer/mesh.h"
|
||||
#include "engine/renderer/mesh.h"
|
||||
|
||||
class Vertex {
|
||||
friend class Mesh;
|
@ -4,12 +4,13 @@
|
||||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "window/window.h"
|
||||
#include "window/events/window.h"
|
||||
#include "engine/window/window.h"
|
||||
#include "engine/window/events/window.h"
|
||||
|
||||
#include "app/app.h"
|
||||
#include "engine/app/app.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
class Engine {
|
||||
class ENGINE_API Engine {
|
||||
public:
|
||||
static void Run(std::unique_ptr<IApplication> app);
|
||||
private:
|
@ -4,7 +4,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include "texture.h"
|
||||
#include "engine/renderer/texture.h"
|
||||
|
||||
class Material {
|
||||
private:
|
@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "renderer/basics.h"
|
||||
#include "engine/renderer/basics.h"
|
||||
|
||||
class Mesh {
|
||||
public: // TODO: abstract away
|
@ -4,10 +4,11 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
#include "renderer/shader.h"
|
||||
#include "engine/renderer/shader.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
// TODO: make static or singleton
|
||||
class Renderer {
|
||||
class ENGINE_API Renderer {
|
||||
public:
|
||||
Renderer(entt::registry& registry);
|
||||
|
@ -5,7 +5,9 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Shader
|
||||
#include "engine/export.h"
|
||||
|
||||
class ENGINE_API Shader
|
||||
{
|
||||
public:
|
||||
Shader();
|
@ -7,15 +7,17 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include "shader.h"
|
||||
#include "renderer/renderer.h"
|
||||
#include "renderer/material.h"
|
||||
#include "renderer/mesh.h"
|
||||
#include "engine/renderer/shader.h"
|
||||
#include "engine/renderer/renderer.h"
|
||||
#include "engine/renderer/material.h"
|
||||
#include "engine/renderer/mesh.h"
|
||||
|
||||
#include "engine/export.h"
|
||||
|
||||
enum ObjElement { OHASH, MTLLIB, USEMTL, O, V, VN, VT, F, OUNKNOWN };
|
||||
enum MtlElement { MHASH, NEWMTL, NS, KA, KS, KD, NI, D, ILLUM, MAP_KD, MAP_KA, MUNKNOWN };
|
||||
|
||||
class Object {
|
||||
class ENGINE_API Object {
|
||||
friend class Renderer;
|
||||
private:
|
||||
static inline int NormalizeIndex(int idx, int baseCount);
|
@ -3,7 +3,7 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <memory>
|
||||
|
||||
#include "event.h"
|
||||
#include "engine/window/event.h"
|
||||
|
||||
#define ENGINE_GL_MAJOR_VERSION 4
|
||||
#define ENGINE_GL_MINOR_VERSION 6
|
@ -1,4 +1,4 @@
|
||||
#include "IO/file_manager.h"
|
||||
#include "engine/IO/file_manager.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
@ -2,7 +2,7 @@
|
||||
#include <cstdlib> // for strtof (fallback)
|
||||
#include <cstring>
|
||||
|
||||
#include "IO/parser.h"
|
||||
#include "engine/IO/parser.h"
|
||||
|
||||
// Skip whitespace
|
||||
void Parser::SkipSpaces() {
|
@ -1,6 +1,6 @@
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "components/batch.h"
|
||||
#include "engine/components/batch.h"
|
||||
|
||||
unsigned int batch::LastID = 0;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <memory>
|
||||
|
||||
#include "renderer/engine.h"
|
||||
#include "window/event.h"
|
||||
#include "engine/renderer/core.h"
|
||||
#include "engine/window/event.h"
|
||||
|
||||
#include "renderer/wavefront.h"
|
||||
#include "engine/renderer/wavefront.h"
|
||||
|
||||
std::unique_ptr<IApplication> Engine::s_app = nullptr;
|
||||
std::shared_ptr<Window> Engine::s_window = nullptr;
|
@ -1,4 +1,4 @@
|
||||
#include "renderer/debug.h"
|
||||
#include "engine/renderer/debug.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <cstddef>
|
||||
|
||||
#include "renderer/mesh.h"
|
||||
#include "engine/renderer/mesh.h"
|
||||
|
||||
Mesh::Mesh() {
|
||||
m_vao = 0;
|
@ -1,23 +1,22 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <corecrt_math_defines.h>
|
||||
#endif
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/euler_angles.hpp>
|
||||
|
||||
#include "renderer/renderer.h"
|
||||
#include "window/window.h"
|
||||
#include "IO/file_manager.h"
|
||||
#include "engine/renderer/renderer.h"
|
||||
#include "engine/window/window.h"
|
||||
#include "engine/IO/file_manager.h"
|
||||
|
||||
#include "components/transform.h"
|
||||
#include "components/camera.h"
|
||||
#include "components/light.h"
|
||||
#include "components/mesh.h"
|
||||
#include "components/batch.h"
|
||||
#include "engine/components/transform.h"
|
||||
#include "engine/components/camera.h"
|
||||
#include "engine/components/light.h"
|
||||
#include "engine/components/mesh.h"
|
||||
#include "engine/components/batch.h"
|
||||
|
||||
Renderer::Renderer(entt::registry& registry) : m_registry(registry)
|
||||
{
|
||||
@ -29,13 +28,13 @@ Renderer::Renderer(entt::registry& registry) : m_registry(registry)
|
||||
);
|
||||
|
||||
m_shader.init(
|
||||
FileManager::read("./src/shaders/main.vs"),
|
||||
FileManager::read("./src/shaders/pbr.fs")
|
||||
FileManager::read("./engine/src/shaders/main.vs"),
|
||||
FileManager::read("./engine/src/shaders/pbr.fs")
|
||||
);
|
||||
|
||||
m_depthShader.init(
|
||||
FileManager::read("./src/shaders/depth.vs"),
|
||||
FileManager::read("./src/shaders/depth.fs")
|
||||
FileManager::read("./engine/src/shaders/depth.vs"),
|
||||
FileManager::read("./engine/src/shaders/depth.fs")
|
||||
);
|
||||
|
||||
m_model = glm::mat4(1.f);
|
@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <GL/glew.h>
|
||||
#include "renderer/shader.h"
|
||||
#include "engine/renderer/shader.h"
|
||||
|
||||
Shader::Shader()
|
||||
{
|
@ -2,7 +2,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "renderer/texture.h"
|
||||
#include "engine/renderer/texture.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
@ -5,9 +5,9 @@
|
||||
#include <filesystem>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "IO/parser.h"
|
||||
#include "renderer/mesh.h"
|
||||
#include "renderer/wavefront.h"
|
||||
#include "engine/IO/parser.h"
|
||||
#include "engine/renderer/mesh.h"
|
||||
#include "engine/renderer/wavefront.h"
|
||||
|
||||
#define DEFAULT_MATERIAL_NAME "default"
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "window/window.h"
|
||||
#include "window/events/window.h"
|
||||
#include "engine/window/window.h"
|
||||
#include "engine/window/events/window.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "renderer/debug.h"
|
||||
#include "engine/renderer/debug.h"
|
||||
|
||||
std::shared_ptr<Window> Window::s_instance = nullptr;
|
||||
|
||||
@ -31,6 +31,8 @@ Window::Window(const char* title, int width, int height) {
|
||||
}
|
||||
|
||||
SDL_SetWindowRelativeMouseMode(m_handle, true);
|
||||
SDL_Rect boundaries = {0, 0, m_width, m_height};
|
||||
SDL_SetWindowMouseRect(m_handle, &boundaries);
|
||||
|
||||
m_context = SDL_GL_CreateContext(m_handle);
|
||||
|
||||
@ -121,6 +123,9 @@ void Window::ProcessEvents() {
|
||||
width,
|
||||
height);
|
||||
Dispatch(WindowResized{ m_width, m_height });
|
||||
SDL_SetWindowRelativeMouseMode(m_handle, true);
|
||||
SDL_Rect boundaries = {0, 0, m_width, m_height};
|
||||
SDL_SetWindowMouseRect(m_handle, &boundaries);
|
||||
}
|
||||
break;
|
||||
default: break;
|
19
sandbox/CMakeLists.txt
Normal file
19
sandbox/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
set(SANDBOX_TARGET sandbox)
|
||||
|
||||
add_executable(${SANDBOX_TARGET} src/main.cpp)
|
||||
|
||||
set_target_properties(${SANDBOX_TARGET} PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
|
||||
target_link_libraries(${SANDBOX_TARGET} PRIVATE ${ENGINE_TARGET})
|
||||
|
||||
# --- Copy engine.dll and all dependent DLLs next to sandbox.exe ---
|
||||
if (WIN32)
|
||||
add_custom_command(TARGET ${SANDBOX_TARGET} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_RUNTIME_DLLS:${SANDBOX_TARGET}> $<TARGET_FILE_DIR:${SANDBOX_TARGET}>
|
||||
COMMAND_EXPAND_LISTS
|
||||
)
|
||||
endif()
|
@ -1,30 +1,26 @@
|
||||
#ifndef WIN32
|
||||
#define GLEW_STATIC
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <corecrt_math_defines.h>
|
||||
#endif
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
|
||||
#include "renderer/shader.h"
|
||||
#include "renderer/wavefront.h"
|
||||
#include "renderer/engine.h"
|
||||
#include "renderer/renderer.h"
|
||||
#ifdef _WIN32
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/extended_min_max.hpp>
|
||||
#endif
|
||||
|
||||
#include "IO/file_manager.h"
|
||||
#include "engine/renderer/wavefront.h"
|
||||
#include "engine/renderer/renderer.h"
|
||||
|
||||
#include "components/transform.h"
|
||||
#include "components/light.h"
|
||||
#include "components/camera.h"
|
||||
#include "components/mesh.h"
|
||||
#include "components/rotate.h"
|
||||
#include "components/batch.h"
|
||||
#include "engine/app/app.h"
|
||||
|
||||
#include "engine/components/transform.h"
|
||||
#include "engine/components/light.h"
|
||||
#include "engine/components/camera.h"
|
||||
#include "engine/components/mesh.h"
|
||||
#include "engine/components/rotate.h"
|
||||
#include "engine/components/batch.h"
|
||||
|
||||
#include "engine/engine.h"
|
||||
|
||||
class Game : public IApplication {
|
||||
public:
|
||||
@ -39,18 +35,18 @@ public:
|
||||
m_registry.emplace<transform>(cameraEntity, glm::vec3(0.f, 2.f, 2.f));
|
||||
m_registry.emplace<camera>(cameraEntity);
|
||||
|
||||
Object* targetObj = Object::LoadFile("./assets/wizard/wizard.obj");
|
||||
Object* targetObj = Object::LoadFile("./assets/monkey.obj");
|
||||
const auto targetEntity = m_registry.create();
|
||||
m_registry.emplace<transform>(targetEntity, glm::vec3(0.f, 0.0f, 0.f));
|
||||
m_registry.emplace<mesh>(targetEntity, std::shared_ptr<Object>(targetObj));
|
||||
|
||||
Object* grass = Object::LoadFile("./assets/grass_block/grass_block.obj");
|
||||
Object* grass = Object::LoadFile("./assets/cube.obj");
|
||||
const auto cubeEntity = m_registry.create();
|
||||
m_registry.emplace<transform>(cubeEntity, glm::vec3(-1.5f, 0.4f, 0.f));
|
||||
m_registry.emplace<mesh>(cubeEntity, std::shared_ptr<Object>(grass));
|
||||
|
||||
// Cube template (use shared object to avoid reloading 1000 times)
|
||||
std::shared_ptr<Object> cubeObj = std::shared_ptr<Object>(Object::LoadFile("./assets/grass_block/grass_block.obj"));
|
||||
std::shared_ptr<Object> cubeObj = std::shared_ptr<Object>(Object::LoadFile("./assets/cube.obj"));
|
||||
const auto batchEntt = m_registry.create();
|
||||
m_registry.emplace<batch>(batchEntt);
|
||||
m_registry.emplace<mesh>(batchEntt, cubeObj);
|
||||
@ -166,7 +162,7 @@ public:
|
||||
glm::vec3 sunDir = glm::normalize(glm::vec3(0.0f, sin(sunAngle), cos(sunAngle)));
|
||||
|
||||
// Compute intensity: bright at noon, dim at dusk/dawn, dark at night
|
||||
float intensity = glm::max(sin(sunAngle), (double)0.0f); // 0 at night, 1 at noon
|
||||
float intensity = glm::max(static_cast<double>(sin(sunAngle)), static_cast<double>(0.0f)); // 0 at night, 1 at noon
|
||||
intensity = glm::mix(0.05f, 1.5f, intensity); // keep some ambient even at night
|
||||
|
||||
// Optional: tint color (warm at sunrise/sunset)
|
||||
@ -232,7 +228,6 @@ private:
|
||||
Uint64 m_currentTicks;
|
||||
};
|
||||
|
||||
int main() {
|
||||
Engine::Run(std::make_unique<Game>());
|
||||
return 0;
|
||||
IApplication* CreateApplication() {
|
||||
return new Game();
|
||||
}
|
Reference in New Issue
Block a user