git repos / saland

commit 798449f4

sago007 · 2017-04-27 17:09
798449f49afb2ce64e1af32e236082cf82c4831d patch · browse files
parent 742266998b1383da134f6e2836a99edebe41101a

Started adding a scene

Changed files

M CMakeLists.txt before
A data/fonts/freeserif.ttf
M src/sago/GameStateInterface.hpp before
M src/saland.cpp before
diff --git a/CMakeLists.txt b/CMakeLists.txt index 773cc4d..c08af4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -16,6 +16,7 @@ find_package(PkgConfig REQUIRED)
pkg_search_module(SDL2MIXER REQUIRED SDL2_mixer)
pkg_search_module(SDL2IMAGE REQUIRED SDL2_image)
pkg_search_module(SDL2TTF REQUIRED SDL2_ttf)
+pkg_search_module(SDL2GFX REQUIRED SDL2_gfx)
pkg_search_module(XML2 REQUIRED libxml-2.0)
@@ -32,4 +33,4 @@ TARGET_LINK_LIBRARIES( saland ${Boost_LIBRARIES} )
target_link_libraries( saland ${SDL2_LIBRARY})
target_link_libraries( saland physfs z b64)
target_link_libraries( saland ${XML2_LIBRARIES})
-target_link_libraries( saland ${SDL2MIXER_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES})
+target_link_libraries( saland ${SDL2MIXER_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES} ${SDL2GFX_LIBRARIES})
diff --git a/data/fonts/freeserif.ttf b/data/fonts/freeserif.ttf new file mode 100644 index 0000000..2f3dfc3
Binary files /dev/null and b/data/fonts/freeserif.ttf differ
diff --git a/src/sago/GameStateInterface.hpp b/src/sago/GameStateInterface.hpp index 43b528b..3cb0067 100644 --- a/src/sago/GameStateInterface.hpp +++ b/src/sago/GameStateInterface.hpp
@@ -46,6 +46,8 @@ public:
virtual void ProcessInput(const SDL_Event& event, bool &processed) = 0;
virtual void Update() {}
+
+ virtual ~GameStateInterface() {}
};
} //sago
diff --git a/src/saland.cpp b/src/saland.cpp index 7ac9657..6c5ada6 100644 --- a/src/saland.cpp +++ b/src/saland.cpp
@@ -3,11 +3,15 @@
#include <SDL_mixer.h>
#include "sago/SagoDataHolder.hpp"
#include "sago/SagoSpriteHolder.hpp"
+#include "sago/GameStateInterface.hpp"
#include <sstream>
#include <SDL_events.h>
#include <SDL_render.h>
#include <SDL_rect.h>
#include <SDL2/SDL_render.h>
+#include <SDL2/SDL_pixels.h>
+#include <SDL2/SDL2_gfxPrimitives.h>
+#include "Libs/NFont.h"
#include "sago/SagoMisc.hpp"
#include "sago/platform_folders.h"
@@ -18,6 +22,31 @@
#define GAMENAME "saland_game"
+static NFont nf_standard_font;
+
+static void NFont_Write(SDL_Renderer* target, int x, int y, const char* text) {
+ nf_standard_font.draw(target, x, y, "%s", text);
+}
+
+class TheGame : sago::GameStateInterface {
+ virtual bool IsActive() override {
+ return true;
+ }
+
+ virtual void Draw(SDL_Renderer* target) override {
+ SDL_RenderClear(target);
+ SDL_RenderPresent(target);
+ }
+
+ virtual void ProcessInput(const SDL_Event& event, bool &processed) override {
+
+ }
+
+ virtual void Update() override {
+
+ }
+};
+
void runGame() {
SDL_Window* win = NULL;
SDL_Renderer* renderer = NULL;
@@ -31,6 +60,7 @@ void runGame() {
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
sago::SagoDataHolder holder(renderer);
sago::SagoSpriteHolder spriteHolder(holder);
+ nf_standard_font.load(renderer, holder.getFontPtr("freeserif", 30),NFont::Color(255,255,255));
while (1) {
SDL_Event e;
if (SDL_PollEvent(&e)) {
@@ -39,10 +69,14 @@ void runGame() {
}
}
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
-
- usleep(10);
+ NFont_Write(renderer, 10, 10, "Hello World");
+ circleRGBA(renderer,
+ 150, 150, 75,
+ 0, 0, 255, 255);
SDL_RenderPresent(renderer);
+ usleep(10);
}
SDL_DestroyRenderer(renderer);