Skip to content

Commit

Permalink
apply changes to all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathSpirit committed Sep 17, 2024
1 parent d639d89 commit 16c28a8
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 101 deletions.
32 changes: 13 additions & 19 deletions examples/clientServerLifeSimulator_004/client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,24 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
return -1;
}

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window* window =
SDL_CreateWindow(("Life simulator client, a FastEngine example by Guillaume Guillet - version " +
std::to_string(LIFESIM_VERSION))
.c_str(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, LIFESIM_MAP_WIDTH, LIFESIM_MAP_HEIGHT,
SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
using namespace fge::vulkan;

auto instance =
Context::init(SDL_INIT_VIDEO | SDL_INIT_EVENTS, "example 004: life simulator client", LIFESIM_VERSION);
Context::enumerateExtensions();

SurfaceSDLWindow window(instance, FGE_WINDOWPOS_CENTERED, {LIFESIM_MAP_WIDTH, LIFESIM_MAP_HEIGHT},
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Check that the window was successfully created
if (window == nullptr)
if (!window.isCreated())
{
// In the case that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 1;
}

fge::vulkan::Context vulkanContext{};
fge::vulkan::Context::initVolk();
fge::vulkan::Context::enumerateExtensions();
vulkanContext.initVulkan(window);

fge::vulkan::SetActiveContext(vulkanContext);

Context vulkanContext(window);
vulkanContext._garbageCollector.enable(true);

fge::shader::Init();
Expand All @@ -82,7 +77,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
fge::shader::LoadFromFile(FGE_OBJSPRITEBATCHES_SHADER_VERTEX, "resources/shaders/objSpriteBatches_vertex.vert",
fge::vulkan::Shader::Type::SHADER_VERTEX, fge::shader::ShaderInputTypes::SHADER_GLSL);

fge::RenderWindow renderWindow(vulkanContext);
fge::RenderWindow renderWindow(vulkanContext, window);
renderWindow.setClearColor(fge::Color::White);

fge::Event event;
Expand Down Expand Up @@ -460,10 +455,9 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])

vulkanContext.destroy();

SDL_DestroyWindow(window);

window.destroy();
instance.destroy();
fge::net::Socket::uninitSocket();

SDL_Quit();

return 0;
Expand Down
25 changes: 11 additions & 14 deletions examples/deepText_005/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,32 +181,29 @@ class MainScene : public fge::Scene

int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window* window = SDL_CreateWindow("example 005: deepText", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800,
600, SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
using namespace fge::vulkan;

auto instance = Context::init(SDL_INIT_VIDEO | SDL_INIT_EVENTS, "example 005: deepText");
Context::enumerateExtensions();

SurfaceSDLWindow window(instance, FGE_WINDOWPOS_CENTERED, {800, 600}, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Check that the window was successfully created
if (window == nullptr)
if (!window.isCreated())
{
// In the case that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 1;
}

fge::vulkan::Context vulkanContext{};
fge::vulkan::Context::initVolk();
fge::vulkan::Context::enumerateExtensions();
vulkanContext.initVulkan(window);

fge::vulkan::SetActiveContext(vulkanContext);

Context vulkanContext(window);
vulkanContext._garbageCollector.enable(true);

fge::shader::Init();
fge::shader::LoadFromFile(FGE_OBJSHAPE_INSTANCES_SHADER_VERTEX, "resources/shaders/objShapeInstances_vertex.vert",
fge::vulkan::Shader::Type::SHADER_VERTEX, fge::shader::ShaderInputTypes::SHADER_GLSL);

fge::RenderWindow renderWindow(vulkanContext);
fge::RenderWindow renderWindow(vulkanContext, window);
renderWindow.setClearColor(fge::Color::White);

std::unique_ptr<MainScene> scene = std::make_unique<MainScene>();
Expand All @@ -221,8 +218,8 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])

vulkanContext.destroy();

SDL_DestroyWindow(window);

window.destroy();
instance.destroy();
SDL_Quit();

return 0;
Expand Down
2 changes: 0 additions & 2 deletions examples/guiWindow_003/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
vulkanContext.destroy();

window.destroy();

instance.destroy();

SDL_Quit();

return 0;
Expand Down
26 changes: 11 additions & 15 deletions examples/lightAndObstacle_002/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,31 +341,27 @@ class MainScene : public fge::Scene

int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window* window =
SDL_CreateWindow("example 002: lightAndObstacle", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600,
SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
using namespace fge::vulkan;

auto instance = Context::init(SDL_INIT_VIDEO | SDL_INIT_EVENTS, "example 002: lightAndObstacle");
Context::enumerateExtensions();

SurfaceSDLWindow window(instance, FGE_WINDOWPOS_CENTERED, {800, 600}, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Check that the window was successfully created
if (window == nullptr)
if (!window.isCreated())
{
// In the case that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 1;
}

fge::vulkan::Context vulkanContext{};
fge::vulkan::Context::initVolk();
fge::vulkan::Context::enumerateExtensions();
vulkanContext.initVulkan(window);

fge::vulkan::SetActiveContext(vulkanContext);

Context vulkanContext(window);
vulkanContext._garbageCollector.enable(true);

fge::shader::Init();

fge::RenderWindow renderWindow(vulkanContext);
fge::RenderWindow renderWindow(vulkanContext, window);
renderWindow.setClearColor(fge::Color::White);

std::unique_ptr<MainScene> scene = std::make_unique<MainScene>();
Expand All @@ -380,8 +376,8 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])

vulkanContext.destroy();

SDL_DestroyWindow(window);

window.destroy();
instance.destroy();
SDL_Quit();

return 0;
Expand Down
28 changes: 11 additions & 17 deletions examples/mipmaps_007/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,33 +167,27 @@ class MainScene : public fge::Scene

int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window* window = SDL_CreateWindow("example 007: mipmaps", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800,
600, SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
using namespace fge::vulkan;

auto instance = Context::init(SDL_INIT_VIDEO | SDL_INIT_EVENTS, "example 007: mipmaps");
Context::enumerateExtensions();

SurfaceSDLWindow window(instance, FGE_WINDOWPOS_CENTERED, {800, 600}, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Check that the window was successfully created
if (window == nullptr)
if (!window.isCreated())
{
// In the case that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 1;
}

fge::vulkan::InstanceLayers.clear();
fge::vulkan::InstanceLayers.push_back("VK_LAYER_LUNARG_monitor");

fge::vulkan::Context vulkanContext{};
fge::vulkan::Context::initVolk();
fge::vulkan::Context::enumerateExtensions();
vulkanContext.initVulkan(window);

fge::vulkan::SetActiveContext(vulkanContext);

Context vulkanContext(window);
vulkanContext._garbageCollector.enable(true);

fge::shader::Init();

fge::RenderWindow renderWindow(vulkanContext);
fge::RenderWindow renderWindow(vulkanContext, window);
renderWindow.setClearColor(fge::Color::White);
renderWindow.setPresentMode(VK_PRESENT_MODE_FIFO_KHR);

Expand All @@ -209,8 +203,8 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])

vulkanContext.destroy();

SDL_DestroyWindow(window);

window.destroy();
instance.destroy();
SDL_Quit();

return 0;
Expand Down
32 changes: 14 additions & 18 deletions examples/multipleSprites_006/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,29 +275,25 @@ class MainScene : public fge::Scene

int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window* window =
SDL_CreateWindow("example 006: multipleSprites", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600,
SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
using namespace fge::vulkan;

InstanceLayers.clear();
InstanceLayers.push_back("VK_LAYER_LUNARG_monitor");

auto instance = Context::init(SDL_INIT_VIDEO | SDL_INIT_EVENTS, "example 006: multipleSprites");
Context::enumerateExtensions();

SurfaceSDLWindow window(instance, FGE_WINDOWPOS_CENTERED, {800, 600}, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Check that the window was successfully created
if (window == nullptr)
if (!window.isCreated())
{
// In the case that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 1;
}

fge::vulkan::InstanceLayers.clear();
fge::vulkan::InstanceLayers.push_back("VK_LAYER_LUNARG_monitor");

fge::vulkan::Context vulkanContext{};
fge::vulkan::Context::initVolk();
fge::vulkan::Context::enumerateExtensions();
vulkanContext.initVulkan(window);

fge::vulkan::SetActiveContext(vulkanContext);

Context vulkanContext(window);
vulkanContext._garbageCollector.enable(true);

fge::shader::Init();
Expand All @@ -308,7 +304,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
fge::shader::LoadFromFile(FGE_OBJSPRITEBATCHES_SHADER_VERTEX, "resources/shaders/objSpriteBatches_vertex.vert",
fge::vulkan::Shader::Type::SHADER_VERTEX, fge::shader::ShaderInputTypes::SHADER_GLSL);

fge::RenderWindow renderWindow(vulkanContext);
fge::RenderWindow renderWindow(vulkanContext, window);
renderWindow.setClearColor(fge::Color::White);
renderWindow.setPresentMode(VK_PRESENT_MODE_IMMEDIATE_KHR);

Expand All @@ -324,8 +320,8 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])

vulkanContext.destroy();

SDL_DestroyWindow(window);

window.destroy();
instance.destroy();
SDL_Quit();

return 0;
Expand Down
26 changes: 11 additions & 15 deletions examples/tileMapAndPathFinding_001/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,33 +312,29 @@ class MainScene : public fge::Scene

int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window* window =
SDL_CreateWindow("example 001: tileMapAndPathfinding", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800,
600, SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
using namespace fge::vulkan;

auto instance = Context::init(SDL_INIT_VIDEO | SDL_INIT_EVENTS, "example 001: tileMapAndPathfinding");
Context::enumerateExtensions();

SurfaceSDLWindow window(instance, FGE_WINDOWPOS_CENTERED, {800, 600}, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Check that the window was successfully created
if (window == nullptr)
if (!window.isCreated())
{
// In the case that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 1;
}

fge::vulkan::Context vulkanContext{};
fge::vulkan::Context::initVolk();
fge::vulkan::Context::enumerateExtensions();
vulkanContext.initVulkan(window);

fge::vulkan::SetActiveContext(vulkanContext);

Context vulkanContext(window);
vulkanContext._garbageCollector.enable(true);

fge::shader::Init();
fge::shader::LoadFromFile(FGE_OBJSHAPE_INSTANCES_SHADER_VERTEX, "resources/shaders/objShapeInstances_vertex.vert",
fge::vulkan::Shader::Type::SHADER_VERTEX, fge::shader::ShaderInputTypes::SHADER_GLSL);

fge::RenderWindow renderWindow(vulkanContext);
fge::RenderWindow renderWindow(vulkanContext, window);
renderWindow.setClearColor(fge::Color::White);

std::unique_ptr<MainScene> scene = std::make_unique<MainScene>();
Expand All @@ -353,8 +349,8 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])

vulkanContext.destroy();

SDL_DestroyWindow(window);

window.destroy();
instance.destroy();
SDL_Quit();

return 0;
Expand Down
2 changes: 1 addition & 1 deletion includes/FastEngine/vulkan/C_surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "FastEngine/fge_extern.hpp"
#include "volk.h"
#include "FastEngine/C_vector.hpp"
#include "SDL_vulkan.h"
#include "SDL_video.h"
#include <string_view>

#define FGE_WINDOWPOS_UNDEFINED {SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED}
Expand Down

0 comments on commit 16c28a8

Please sign in to comment.