Rename DisplayExample to WindowExample
This commit is contained in:
parent
24da7f45e0
commit
8901257bb6
6 changed files with 25 additions and 19 deletions
70
examples/window/WindowExample.cpp
Normal file
70
examples/window/WindowExample.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
#include <Spectre/Window/Window.h>
|
||||
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||
#include <Spectre/System/MessageHandler.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
#include "WindowExample.h"
|
||||
|
||||
void WindowExample::init()
|
||||
{
|
||||
m_renderer = new sp::BatchRenderer2D();
|
||||
m_mode = sp::Window::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 WindowExample::onEvent(const sp::Event& event)
|
||||
{
|
||||
if (event.type == sp::Event::Key && event.key.pressed == false) {
|
||||
|
||||
if (event.key.code == sp::Keyboard::W) {
|
||||
|
||||
if (m_mode == sp::Window::WINDOWED) {
|
||||
m_mode = sp::Window::WINDOWEDFULLSCREEN;
|
||||
sp::Log::info("Windowed Fullscreen");
|
||||
} else {
|
||||
m_mode = sp::Window::WINDOWED;
|
||||
sp::Log::info("Windowed");
|
||||
}
|
||||
|
||||
getGraphics()->setWindowMode(m_mode);
|
||||
|
||||
} else if (event.key.code == sp::Keyboard::Space) {
|
||||
|
||||
if (m_mode == sp::Window::WINDOWED) {
|
||||
m_mode = sp::Window::FULLSCREEN;
|
||||
sp::Log::info("Fullscreen");
|
||||
} else {
|
||||
m_mode = sp::Window::WINDOWED;
|
||||
sp::Log::info("Windowed");
|
||||
}
|
||||
|
||||
getGraphics()->setWindowMode(m_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WindowExample::update(double dt)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
void WindowExample::render()
|
||||
{
|
||||
sp::Graphics* g = getGraphics();
|
||||
|
||||
g->clearBuffer();
|
||||
|
||||
m_renderer->begin();
|
||||
m_renderer->submit(m_sprite);
|
||||
m_renderer->render();
|
||||
|
||||
g->swapBuffers();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue