Skip to content

Commit 9f26bba

Browse files
committed
Created a tilemap example for testing texture atlases
1 parent 449e1c0 commit 9f26bba

File tree

10 files changed

+144
-7
lines changed

10 files changed

+144
-7
lines changed

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ export renderLib := $(libDir)/librender.a
4747
export testApp := $(binDir)/tests/build/app
4848
export exampleGameApp := $(binDir)/examples/game/build/app
4949
export exampleRenderApp := $(binDir)/examples/render/build/app
50+
export exampleTilemapApp := $(binDir)/examples/tilemap/build/app
5051

5152
# Set build vars
5253
export compileFlags := -Wall -std=c++17
5354
export linkFlags += -L $(libDir)
5455
buildFlagsFile:=.buildflags
5556

56-
.PHONY: all testapp gameapp renderapp package-gameapp package-renderapp buildFlags clean format
57+
.PHONY: all testapp gameapp renderapp tilemapapp package-gameapp package-renderapp package-tilemap buildFlags clean format
5758

58-
all: testapp package-gameapp package-renderapp
59+
all: testapp package-gameapp package-renderapp package-tilemap
5960

6061
$(utilsLib): buildFlags
6162
"$(MAKE)" -C $(engineDir)/utils CXXFLAGS="$(CXXFLAGS)"
@@ -78,18 +79,26 @@ $(exampleGameApp): buildFlags $(renderLib) $(coreLib)
7879
$(exampleRenderApp): buildFlags $(renderLib)
7980
"$(MAKE)" -C $(examplesDir)/render CXXFLAGS="$(CXXFLAGS)"
8081

82+
$(exampleTilemapApp): buildFlags $(renderLib)
83+
"$(MAKE)" -C $(examplesDir)/tilemap CXXFLAGS="$(CXXFLAGS)"
84+
8185
testapp: $(testApp)
8286

8387
gameapp: $(exampleGameApp)
8488

8589
renderapp: $(exampleRenderApp)
8690

91+
tilemapapp: $(exampleTilemapApp)
92+
8793
package-gameapp: gameapp
8894
"$(MAKE)" package -C $(examplesDir)/game CXXFLAGS="$(CXXFLAGS)"
8995

9096
package-renderapp: renderapp
9197
"$(MAKE)" package -C $(examplesDir)/render CXXFLAGS="$(CXXFLAGS)"
9298

99+
package-tilemap: tilemapapp
100+
"$(MAKE)" package -C $(examplesDir)/tilemap CXXFLAGS="$(CXXFLAGS)"
101+
93102
# Check to invalidate the build if flags have changed
94103
buildFlags:
95104
$(call BUILD_FLAGS_SCRIPT, $(buildFlagsFile), $(CXXFLAGS), $(libDir) $(binDir))

engine/render/renderer/Renderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Renderer::Renderer(Window& window) : window {window}
4848
Renderer::~Renderer()
4949
{
5050
CC_LOG_INFO("Destroying renderer")
51+
Vulkan::Context::GetCurrentDevice()->WaitIdle();
5152
DescriptorPool::DestroyPool();
5253
Renderer3D::DestroyRenderer3D();
5354
Statics::Free();

engine/render/renderer/platform/vulkan/Font.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ void Font::PopulateTextureAtlas(uint8_t* buffer)
143143
auto& glyph = glyphs[c];
144144
float xPos {glyph.uvxMin}, yPos {glyph.uvyMin};
145145

146-
// TODO: Add an extent type which uses floating point numbers
147-
148146
glyph.uvxMin /= extent.width;
149147
glyph.uvyMin /= extent.height;
150148

engine/utils/collections/ArrayUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <cstring>
1919
#include <initializer_list>
2020
#include <utility>
21+
#include <iterator>
2122

2223
namespace Siege
2324
{

examples/render/src/main.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// https://opensource.org/licenses/Zlib
88
//
99

10-
#include <GLFW/glfw3.h>
1110
#include <render/renderer/ObjectLoader.h>
1211
#include <render/renderer/Renderer.h>
1312
#include <render/renderer/platform/vulkan/Material.h>
@@ -369,7 +368,5 @@ int main()
369368
renderer.EndFrame();
370369
}
371370

372-
renderer.ClearDeviceQueue();
373-
374371
return 0;
375372
}

examples/tilemap/Makefile

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright (c) 2020-present Caps Collective & contributors
2+
# Originally authored by Jonathan Moallem (@jonjondev) & Aryeh Zinn (@Raelr)
3+
#
4+
# This code is released under an unmodified zlib license.
5+
# For conditions of distribution and use, please see:
6+
# https://opensource.org/licenses/Zlib
7+
8+
include $(makeDir)/Functions.mk
9+
include $(makeDir)/Platform.mk
10+
11+
# Set source build vars
12+
exampleTilemapSrcDir := .
13+
exampleTilemapBinDir := $(binDir)/examples/tilemap
14+
exampleTilemapSources := $(call rwildcard,$(exampleTilemapSrcDir)/,*.cpp)
15+
exampleTilemapObjects := $(call findobjs,$(exampleTilemapSrcDir),$(exampleTilemapBinDir),$(exampleTilemapSources))
16+
exampleTilemapDepends := $(patsubst %.o, %.d, $(call rwildcard,$(exampleTilemapBinDir)/,*.o))
17+
exampleTilemapBuildDir := $(exampleTilemapBinDir)/build
18+
exampleTilemapOutputName := "Tilemap Example"
19+
20+
# Set packaging vars
21+
ifeq ($(platform), linux)
22+
packagingEnvVars := \
23+
export DYLD_LIBRARY_PATH='./lib'; \
24+
export VK_LAYER_PATH='./lib/explicit_layer.d';
25+
else ifeq ($(platform), macos)
26+
packagingEnvVars := \
27+
export DYLD_LIBRARY_PATH='./lib'; \
28+
export VK_LAYER_PATH='./lib/explicit_layer.d'; \
29+
export VK_ICD_FILENAMES='./lib/icd.d/MoltenVK_icd.json'
30+
endif
31+
32+
ifneq ($(ENABLE_VALIDATION_LAYERS), 1)
33+
packagingExcludes := $(VALIDATION_LAYERS_INSTALL_DIR)
34+
endif
35+
36+
ifneq ("$(packagingEnvVars)","")
37+
ENV_VARS = --env-vars "$(packagingEnvVars)"
38+
endif
39+
40+
packagingFlags = $(ENV_VARS) --excludes "$(packagingExcludes)"
41+
42+
# Set build vars
43+
compileFlags += -I $(vendorDir)/glfw/include -I $(vendorDir)/glm \
44+
-I $(vendorDir)/tinyobjloader -I $(vendorDir)/freetype/include
45+
linkFlags += -l render -l window -l utils
46+
47+
.PHONY: all render-assets tilemap-assets
48+
49+
all: $(exampleTilemapApp) tilemap-assets render-assets
50+
51+
# Link the object files and create an executable
52+
$(exampleTilemapApp): $(renderLib) $(exampleTilemapObjects)
53+
$(MKDIR) $(call platformpth, $(@D))
54+
$(CXX) $(exampleTilemapObjects) -o $(exampleTilemapApp) $(linkFlags)
55+
56+
# Add all rules from dependency files
57+
-include $(exampleTilemapDepends)
58+
59+
# Compile object files to the bin directory
60+
$(exampleTilemapBinDir)/%.o: $(exampleTilemapSrcDir)/%.cpp
61+
$(MKDIR) $(call platformpth, $(@D))
62+
$(CXX) -MMD -MP -c $(compileFlags) -I $(engineDir) $< -o $@ $(CXXFLAGS)
63+
64+
# Copy assets directory to the build directory
65+
tilemap-assets:
66+
$(MKDIR) $(call platformpth, $(exampleTilemapBuildDir)/assets)
67+
$(call COPY,$(exampleTilemapSrcDir)/assets,$(exampleTilemapBuildDir)/assets,**)
68+
69+
# Copy assets (and other required build files) directory to the build directory
70+
render-assets:
71+
$(MKDIR) $(call platformpth,$(exampleTilemapBuildDir))
72+
$(call COPY,$(binDir)/engine/render/build,$(exampleTilemapBuildDir),**)
73+
$(MKDIR) $(call platformpth,$(exampleTilemapBuildDir)/assets)
74+
$(call COPY,$(exampleTilemapSrcDir)/assets,$(exampleTilemapBuildDir)/assets,**)
75+
76+
# Package the built application and all its assets to the output directory
77+
package:
78+
$(RM) "$(outputDir)/$(exampleTilemapOutputName)"
79+
$(call PACKAGE_SCRIPT, $(exampleTilemapOutputName), $(shell basename $(exampleTilemapApp)), $(outputDir), $(exampleTilemapBuildDir), $(packagingFlags))
95.2 KB
Binary file not shown.
544 Bytes
Loading
222 Bytes
Loading

examples/tilemap/src/main.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// Copyright (c) 2020-present Caps Collective & contributors
3+
// Originally authored by Jonathan Moallem (@jonjondev) & Aryeh Zinn (@Raelr)
4+
//
5+
// This code is released under an unmodified zlib license.
6+
// For conditions of distribution and use, please see:
7+
// https://opensource.org/licenses/Zlib
8+
//
9+
10+
#include <window/Window.h>
11+
#include <render/renderer/Renderer.h>
12+
#include <render/renderer/camera/Camera.h>
13+
#include <utils/math/vec/Vec3.h>
14+
#include <utils/math/Projection.h>
15+
#include <utils/math/Transform.h>
16+
17+
static const constexpr int WIDTH = 800;
18+
static const constexpr int HEIGHT = 600;
19+
20+
int main()
21+
{
22+
Siege::Window window("Tilemap Example", {WIDTH, HEIGHT});
23+
24+
Siege::Renderer renderer(window);
25+
26+
auto pixel = Siege::Vulkan::Font("assets/fonts/PublicPixel.ttf");
27+
auto tilemap = Siege::Vulkan::Texture2D("tilemap", "assets/textures/tilemap.png");
28+
29+
Siege::Camera camera;
30+
31+
camera.projection = Siege::Orthographic(0.f, window.GetWidth(), window.GetHeight(), 0.f, 0.1f, 1000.f);
32+
camera.view = Siege::LookAt(Siege::Vec3::Zero(), {0.f, 0.f, 1.f});
33+
34+
renderer.SetCamera2D(camera);
35+
36+
while (!window.WindowShouldClose())
37+
{
38+
window.Update();
39+
40+
if(!renderer.StartFrame()) continue;
41+
42+
renderer.DrawGrid2D(100.f, {.2f, .2f, .2f}, window.GetDPI());
43+
44+
renderer.DrawText2D("Hello World!", pixel, {10.f, 10.f}, {64.f, 64.f}, 0.f, Siege::IColour::Black);
45+
46+
renderer.DrawQuad({400.f, 300.f}, {256.f, 256.f}, Siege::IColour::White, 0.f, 0, &tilemap);
47+
48+
renderer.EndFrame();
49+
}
50+
51+
return 0;
52+
}

0 commit comments

Comments
 (0)