Add sdl2 template to App. Start Math in App
This commit is contained in:
parent
c391b7cfa5
commit
53dbb607dd
3
App/.vscode/settings.json
vendored
3
App/.vscode/settings.json
vendored
@ -43,5 +43,6 @@
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
},
|
||||
"cmake.configureOnOpen": true
|
||||
}
|
||||
@ -11,7 +11,9 @@ add_executable(App
|
||||
${HDRS}
|
||||
)
|
||||
|
||||
target_link_libraries(App PUBLIC AppLib)
|
||||
find_package(SDL2 CONFIG REQUIRED)
|
||||
target_link_libraries(App PRIVATE AppLib SDL2::SDL2 SDL2::SDL2main)
|
||||
# target_link_libraries(App PUBLIC )
|
||||
|
||||
target_include_directories(App PUBLIC "${CMAKE_SOURCE_DIR}/App/include")
|
||||
target_include_directories(App PUBLIC "${CMAKE_SOURCE_DIR}/AppLib/include/AppLib")
|
||||
|
||||
@ -8,8 +8,10 @@ namespace App
|
||||
{
|
||||
private:
|
||||
Logger* _logger;
|
||||
int _return_code;
|
||||
public:
|
||||
App(/* args */);
|
||||
int getReturnCode() const;
|
||||
~App();
|
||||
};
|
||||
} // namespace App
|
||||
|
||||
@ -1,16 +1,117 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "SDL2/SDL.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
|
||||
|
||||
namespace App
|
||||
{
|
||||
App::App()
|
||||
App::App() : _return_code(0)
|
||||
{
|
||||
std::cout << "This is app" << std::endl;
|
||||
std::cout << "Eternity Engine" << std::endl;
|
||||
_logger = new Logger();
|
||||
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;
|
||||
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)
|
||||
{
|
||||
std::cout << "Window could not be created!" << std::endl
|
||||
<< "SDL_Error: " << SDL_GetError() << std::endl;
|
||||
_return_code=-1;
|
||||
return;
|
||||
}
|
||||
// Create renderer
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
if(!renderer)
|
||||
{
|
||||
std::cout << "Renderer could not be created!" << std::endl
|
||||
<< "SDL_Error: " << SDL_GetError() << std::endl;
|
||||
_return_code=-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;
|
||||
|
||||
// Event loop
|
||||
while(!quit)
|
||||
{
|
||||
SDL_Event e;
|
||||
|
||||
// Wait indefinitely for the next available event
|
||||
SDL_WaitEvent(&e);
|
||||
|
||||
// User requests quit
|
||||
if(e.type == SDL_QUIT)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Destroy renderer
|
||||
SDL_DestroyRenderer(renderer);
|
||||
}
|
||||
|
||||
// Destroy window
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
App::~App()
|
||||
{
|
||||
_logger->~Logger();
|
||||
delete _logger;
|
||||
}
|
||||
|
||||
int App::getReturnCode() const
|
||||
{
|
||||
return _return_code;
|
||||
}
|
||||
|
||||
} // namespace App
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
#include "App.hh"
|
||||
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
App::App* app = new App::App();
|
||||
return 0;
|
||||
return app->getReturnCode();
|
||||
}
|
||||
|
||||
17
App/AppLib/include/AppLib/Math.hh
Normal file
17
App/AppLib/include/AppLib/Math.hh
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Core
|
||||
{
|
||||
struct Vec2
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
struct Vec3
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w = 1;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
4
App/AppLib/src/Math.cpp
Normal file
4
App/AppLib/src/Math.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
namespace Core
|
||||
{
|
||||
|
||||
} // namespace Core
|
||||
Loading…
x
Reference in New Issue
Block a user