Adding Display Example
This commit is contained in:
parent
b43f2fcca8
commit
4d69ff3a18
5 changed files with 112 additions and 1 deletions
|
|
@ -25,7 +25,8 @@ assets = CopyDir(PathJoin(paths.build, paths.examples), "assets")
|
|||
examples = BuildExamples(example_settings, {
|
||||
"text",
|
||||
"events",
|
||||
"input"
|
||||
"input",
|
||||
"display"
|
||||
}, assets)
|
||||
|
||||
PseudoTarget("examples", examples)
|
||||
|
|
|
|||
58
examples/display/DisplayExample.cpp
Normal file
58
examples/display/DisplayExample.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
#include <Spectre/Display/Display.h>
|
||||
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||
#include <Spectre/System/MessageHandler.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
#include "DisplayExample.h"
|
||||
|
||||
void DisplayExample::init()
|
||||
{
|
||||
m_renderer = new sp::BatchRenderer2D();
|
||||
m_mode = sp::Display::WINDOWED;
|
||||
getMessageHandler()->registerListener(this);
|
||||
|
||||
m_texture.create("assets/textures/tux.png");
|
||||
|
||||
m_sprite.setTexture(m_texture);
|
||||
m_sprite.setPosition(sp::vec2f(50, 50));
|
||||
m_sprite.setSize(sp::vec2f(100, 100));
|
||||
|
||||
m_renderer->setCamera(m_camera);
|
||||
}
|
||||
|
||||
void DisplayExample::onEvent(const sp::Event& event)
|
||||
{
|
||||
if (event.type == sp::Event::Key && event.key.pressed == false) {
|
||||
|
||||
if (event.key.code == sp::Keyboard::Space) {
|
||||
|
||||
if (m_mode == sp::Display::WINDOWED) {
|
||||
m_mode = sp::Display::FULLSCREEN;
|
||||
sp::Log::info("Fullscreen");
|
||||
} else {
|
||||
m_mode = sp::Display::WINDOWED;
|
||||
sp::Log::info("Windowed");
|
||||
}
|
||||
|
||||
getGraphics()->setDisplayMode(m_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayExample::update(double dt)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
void DisplayExample::render()
|
||||
{
|
||||
sp::Graphics* g = getGraphics();
|
||||
|
||||
g->clearBuffer();
|
||||
|
||||
m_renderer->begin();
|
||||
m_renderer->submit(m_sprite);
|
||||
m_renderer->render();
|
||||
|
||||
g->swapBuffers();
|
||||
}
|
||||
34
examples/display/DisplayExample.h
Normal file
34
examples/display/DisplayExample.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
#ifndef DISPLAY_EXAMPLE_H
|
||||
#define DISPLAY_EXAMPLE_H
|
||||
|
||||
#include <Spectre/Scene/Camera2D.h>
|
||||
#include <Spectre/Graphics/Texture.h>
|
||||
#include <Spectre/Graphics/Sprite.h>
|
||||
#include <Spectre/System/EventListener.h>
|
||||
#include <Spectre/Game.h>
|
||||
|
||||
class DisplayExample : public sp::Game, sp::EventListener
|
||||
{
|
||||
public :
|
||||
void onEvent(const sp::Event& event);
|
||||
|
||||
protected :
|
||||
|
||||
void init();
|
||||
|
||||
void update(double dt);
|
||||
|
||||
void render();
|
||||
|
||||
protected :
|
||||
|
||||
sp::Display::Mode m_mode;
|
||||
|
||||
sp::Camera2D m_camera;
|
||||
sp::Renderer2D *m_renderer;
|
||||
sp::Texture m_texture;
|
||||
sp::Sprite m_sprite;
|
||||
};
|
||||
|
||||
#endif /* DISPLAY_EXAMPLE_H */
|
||||
7
examples/display/bam.lua
Normal file
7
examples/display/bam.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
local base = PathDir(ModuleFilename())
|
||||
|
||||
src ={
|
||||
base .. "/main.cpp",
|
||||
base .. "/DisplayExample.cpp"
|
||||
}
|
||||
11
examples/display/main.cpp
Normal file
11
examples/display/main.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#include "DisplayExample.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
DisplayExample game;
|
||||
|
||||
game.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue