Rename DisplayExample to WindowExample
This commit is contained in:
parent
24da7f45e0
commit
8901257bb6
6 changed files with 25 additions and 19 deletions
7
examples/window/CMakeLists.txt
Normal file
7
examples/window/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
#find_package(Spectre REQUIRED)
|
||||
|
||||
spectre_example(window
|
||||
main.cpp
|
||||
WindowExample.cpp
|
||||
)
|
||||
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();
|
||||
}
|
||||
34
examples/window/WindowExample.h
Normal file
34
examples/window/WindowExample.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 WindowExample : public sp::Game, sp::EventListener
|
||||
{
|
||||
public :
|
||||
void onEvent(const sp::Event& event);
|
||||
|
||||
protected :
|
||||
|
||||
void init();
|
||||
|
||||
void update(double dt);
|
||||
|
||||
void render();
|
||||
|
||||
protected :
|
||||
|
||||
sp::Window::Mode m_mode;
|
||||
|
||||
sp::Camera2D m_camera;
|
||||
sp::Renderer2D *m_renderer;
|
||||
sp::Texture m_texture;
|
||||
sp::Sprite m_sprite;
|
||||
};
|
||||
|
||||
#endif /* DISPLAY_EXAMPLE_H */
|
||||
11
examples/window/main.cpp
Normal file
11
examples/window/main.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#include "WindowExample.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
WindowExample game;
|
||||
|
||||
game.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue