Adding example code and project files.
This commit is contained in:
parent
008cb6d33f
commit
07417491cb
5 changed files with 162 additions and 0 deletions
88
examples/text/Game.cpp
Normal file
88
examples/text/Game.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
|
||||
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||
#include <Spectre/Input/InputModule.h>
|
||||
#include <Spectre/Graphics/Font.h>
|
||||
#include <Spectre/Graphics/Text.h>
|
||||
#include "Game.h"
|
||||
|
||||
Font smallFont;
|
||||
Font myFont;
|
||||
Font fntLarge;
|
||||
|
||||
Text myText;
|
||||
Text txtLarge;
|
||||
Text txtKerning;
|
||||
Text fpsText;
|
||||
Text txtSmall;
|
||||
|
||||
Camera2D guiCamera;
|
||||
|
||||
BatchRenderer2D *renderer;
|
||||
|
||||
void TextExample::init()
|
||||
{
|
||||
Graphics* g = getGraphics();
|
||||
|
||||
g->setClearColor(52.0f / 255.0f, 58.0f / 255.0f, 80.0f / 255.0f);
|
||||
|
||||
smallFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf", 14);
|
||||
myFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf", 20);
|
||||
fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf", 48);
|
||||
|
||||
myText.setFont(myFont);
|
||||
myText.setColor(Color::Green);
|
||||
myText.setString("Hello");
|
||||
myText.setPosition(25.0f, 50.0f);
|
||||
|
||||
txtLarge.setFont(myFont);
|
||||
txtLarge.setColor(Color(200, 100, 0));
|
||||
txtLarge.setString("Large Text, Looks good?");
|
||||
txtLarge.setPosition(300.0f, 150.0f);
|
||||
txtLarge.setScale(2.0f);
|
||||
|
||||
txtKerning.setFont(fntLarge);
|
||||
txtKerning.setColor(Color(150, 0, 230));
|
||||
txtKerning.setString("Kerning: VA Ta");
|
||||
txtKerning.setPosition(150.0f, 200.0f);
|
||||
|
||||
txtSmall.setFont(smallFont);
|
||||
txtSmall.setString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a rhoncus odio, nec finibus libero.");
|
||||
txtSmall.setPosition(50.0f, 450.0f);
|
||||
|
||||
fpsText.setFont(myFont);
|
||||
fpsText.setString("FPS: 0");
|
||||
fpsText.setPosition(10.0f, 10.0f);
|
||||
|
||||
renderer = new BatchRenderer2D();
|
||||
}
|
||||
|
||||
void TextExample::update(double dt)
|
||||
{
|
||||
InputModule* input = getInput();
|
||||
input->update();
|
||||
|
||||
if (getFpsCounter().update()) {
|
||||
std::string str = "FPS: " + core::to_string(getFpsCounter().getFPS(), 0);
|
||||
fpsText.setString(str);
|
||||
}
|
||||
}
|
||||
|
||||
void TextExample::render()
|
||||
{
|
||||
Graphics* g = getGraphics();
|
||||
|
||||
g->clearBuffer();
|
||||
|
||||
renderer->begin();
|
||||
|
||||
renderer->submit(fpsText);
|
||||
renderer->submit(myText);
|
||||
renderer->submit(txtLarge);
|
||||
renderer->submit(txtKerning);
|
||||
renderer->submit(txtSmall);
|
||||
|
||||
renderer->setCamera(guiCamera);
|
||||
renderer->render();
|
||||
|
||||
g->swapBuffers();
|
||||
}
|
||||
20
examples/text/Game.h
Normal file
20
examples/text/Game.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
#ifndef TEXT_GAME_H
|
||||
#define TEXT_GAME_H
|
||||
|
||||
#include <Spectre/Math/Vector2.h>
|
||||
#include <Spectre/Input/InputListener.h>
|
||||
#include <Spectre/Game.h>
|
||||
|
||||
class TextExample : public Game, public InputListener
|
||||
{
|
||||
protected :
|
||||
|
||||
void init();
|
||||
|
||||
void update(double dt);
|
||||
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif /* TEXT_GAME_H*/
|
||||
11
examples/text/main.cpp
Normal file
11
examples/text/main.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#include "Game.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
TextExample game;
|
||||
|
||||
game.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
examples/vsproj/example_text.filters
Normal file
17
examples/vsproj/example_text.filters
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
26
vsproj/Examples.sln
Normal file
26
vsproj/Examples.sln
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_text", "examples\vsproj\example_text.vcxproj", "{C33DE942-1754-4592-AAA4-ED75BFF50E44}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Spectre", "Spectre.vcxproj", "{E789E1AD-BD26-4D1C-BAA7-A5A0FF50D59C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C33DE942-1754-4592-AAA4-ED75BFF50E44}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{C33DE942-1754-4592-AAA4-ED75BFF50E44}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{C33DE942-1754-4592-AAA4-ED75BFF50E44}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{C33DE942-1754-4592-AAA4-ED75BFF50E44}.Release|Win32.Build.0 = Release|Win32
|
||||
{E789E1AD-BD26-4D1C-BAA7-A5A0FF50D59C}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{E789E1AD-BD26-4D1C-BAA7-A5A0FF50D59C}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{E789E1AD-BD26-4D1C-BAA7-A5A0FF50D59C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{E789E1AD-BD26-4D1C-BAA7-A5A0FF50D59C}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Loading…
Add table
Add a link
Reference in a new issue