diff --git a/App/.vscode/settings.json b/App/.vscode/settings.json index cbab875..a7cb670 100644 --- a/App/.vscode/settings.json +++ b/App/.vscode/settings.json @@ -45,7 +45,32 @@ "xutility": "cpp", "list": "cpp", "vector": "cpp", - "xtree": "cpp" + "xtree": "cpp", + "any": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "condition_variable": "cpp", + "format": "cpp", + "forward_list": "cpp", + "functional": "cpp", + "iomanip": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "optional": "cpp", + "ratio": "cpp", + "set": "cpp", + "sstream": "cpp", + "stop_token": "cpp", + "string": "cpp", + "thread": "cpp", + "unordered_map": "cpp", + "variant": "cpp", + "xhash": "cpp", + "xlocbuf": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xloctime": "cpp" }, "cmake.configureOnOpen": true } \ No newline at end of file diff --git a/App/App/CMakeLists.txt b/App/App/CMakeLists.txt index 55f67e1..784423c 100644 --- a/App/App/CMakeLists.txt +++ b/App/App/CMakeLists.txt @@ -12,7 +12,13 @@ add_executable(App ) find_package(SDL2 CONFIG REQUIRED) -target_link_libraries(App PRIVATE AppLib SDL2::SDL2 SDL2::SDL2main) +find_package(OpenGL REQUIRED) +target_link_libraries(App PRIVATE + AppLib + SDL2::SDL2 + SDL2::SDL2main + OpenGL::GL +) # target_link_libraries(App PUBLIC ) target_include_directories(App PUBLIC "${CMAKE_SOURCE_DIR}/App/include") diff --git a/App/App/include/App.hh b/App/App/include/App.hh index 446e6a3..d947af0 100644 --- a/App/App/include/App.hh +++ b/App/App/include/App.hh @@ -1,5 +1,13 @@ +#include + +#include "SDL2/SDL.h" +// #include "SDL2/SDL_vulkan.h" +#include +#include + #include "Logger.hh" + using namespace Core; namespace App @@ -7,8 +15,13 @@ namespace App class App { private: - Logger* _logger; - int _return_code; + std::shared_ptr m_Logger; + int m_ReturnCode; + int m_WindowWidth; + int m_WindowHeight; + SDL_Window* m_Window; + SDL_GLContext m_glContext; + bool m_Quit; public: App(/* args */); int getReturnCode() const; diff --git a/App/App/src/App.cpp b/App/App/src/App.cpp index a4249fc..b95be6e 100644 --- a/App/App/src/App.cpp +++ b/App/App/src/App.cpp @@ -1,72 +1,63 @@ #include -#include "SDL2/SDL.h" -#include "SDL2/SDL_vulkan.h" #include "App.hh" -// #ifdef _WIN32 -// #pragma comment(linker, "/subsystem:windows") -// #define VK_USE_PLATFORM_WIN32_KHR -// #define PLATFORM_SURFACE_EXTENSION_NAME VK_KHR_WIN32_SURFACE_EXTENSION_NAME -// #endif - -#define SCREEN_WIDTH 800 -#define SCREEN_HEIGHT 600 +#ifdef _WIN32 + #pragma comment(linker, "/subsystem:windows") + #define VK_USE_PLATFORM_WIN32_KHR + #define PLATFORM_SURFACE_EXTENSION_NAME VK_KHR_WIN32_SURFACE_EXTENSION_NAME +#endif namespace App { - App::App() : _return_code(0) + App::App() : m_ReturnCode(0), m_WindowWidth(800), m_WindowHeight(600), m_Quit(false) { std::cout << "Eternity Engine" << std::endl; - _logger = new Logger(); + m_Logger = std::make_shared(); + + //Use OpenGL 3.1 core + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + if(SDL_Init(SDL_INIT_VIDEO) < 0) { std::cout << "SDL could not be initialized!" << std::endl << "SDL_Error: " << SDL_GetError() << std::endl; - _return_code=-1; + m_ReturnCode=-1; return; } + // SDL_Vulkan_LoadLibrary(nullptr); - SDL_Window *window = SDL_CreateWindow("Basic C++ SDL project", - SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, - SCREEN_WIDTH, SCREEN_HEIGHT, - SDL_WINDOW_SHOWN); - if(!window) + m_Window = SDL_CreateWindow("App", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + m_WindowWidth, m_WindowHeight, + SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); + if(!m_Window) { std::cout << "Window could not be created!" << std::endl << "SDL_Error: " << SDL_GetError() << std::endl; - _return_code=-1; + m_ReturnCode=-1; return; } - // Create renderer - SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); - if(!renderer) + + m_glContext = SDL_GL_CreateContext(m_Window); + if( !m_glContext ) { - std::cout << "Renderer could not be created!" << std::endl - << "SDL_Error: " << SDL_GetError() << std::endl; - _return_code=-1; + // Display error message + std::cout << "OpenGL context could not be created!" << std::endl + << "SDL_Error: " << SDL_GetError() << std::endl; + m_ReturnCode=-1; return; } else { - // Declare rect of square - SDL_Rect squareRect; - - // Square dimensions: Half of the min(SCREEN_WIDTH, SCREEN_HEIGHT) - squareRect.w = std::min(SCREEN_WIDTH, SCREEN_HEIGHT) / 2; - squareRect.h = std::min(SCREEN_WIDTH, SCREEN_HEIGHT) / 2; - - // Square position: In the middle of the screen - squareRect.x = SCREEN_WIDTH / 2 - squareRect.w / 2; - squareRect.y = SCREEN_HEIGHT / 2 - squareRect.h / 2; - - // Event loop exit flag - bool quit = false; + m_Quit = false; // Event loop - while(!quit) + while(!m_Quit) { SDL_Event e; @@ -76,43 +67,32 @@ namespace App // User requests quit if(e.type == SDL_QUIT) { - quit = true; + m_Quit = true; } - // Initialize renderer color white for the background - SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); - - // Clear screen - SDL_RenderClear(renderer); - - // Set renderer color red to draw the square - SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF); - - // Draw filled square - SDL_RenderFillRect(renderer, &squareRect); - - // Update screen - SDL_RenderPresent(renderer); + // Set background color as cornflower blue + glClearColor(0.39f, 0.58f, 0.93f, 1.f); + // Clear color buffer + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + // Update window with OpenGL rendering + SDL_GL_SwapWindow(m_Window); } - - // Destroy renderer - SDL_DestroyRenderer(renderer); } - // Destroy window - SDL_DestroyWindow(window); - SDL_Quit(); + + } App::~App() { - _logger->~Logger(); - delete _logger; + SDL_DestroyWindow(m_Window); + SDL_Quit(); + m_Logger->~Logger(); } int App::getReturnCode() const { - return _return_code; + return m_ReturnCode; } } // namespace App diff --git a/App/App/src/main.cpp b/App/App/src/main.cpp index 02927d7..4a21f8c 100644 --- a/App/App/src/main.cpp +++ b/App/App/src/main.cpp @@ -5,7 +5,7 @@ using namespace std; -int main(int argc, char const *argv[]) +int main(int argc, char * argv[]) { App::App* app = new App::App(); return app->getReturnCode();