You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.9 KiB
C++
93 lines
2.9 KiB
C++
|
4 years ago
|
/******************************************************************************
|
||
|
|
* File - simpleRenderScene.cpp
|
||
|
|
* Author - Joey Pollack
|
||
|
|
* Date - 2021/10/27 (y/m/d)
|
||
|
|
* Mod Date - 2021/10/27 (y/m/d)
|
||
|
|
* Description - Displays a simple scene that tests basic render features.
|
||
|
|
******************************************************************************/
|
||
|
|
|
||
|
|
#include "simpleRenderScene.h"
|
||
|
|
#include <core/core.h>
|
||
|
|
#include <utils/helpers.h>
|
||
|
|
#include <utils/logger.h>
|
||
|
|
#include <graphics/igraphics.h>
|
||
|
|
#include <input/inputManager.h>
|
||
|
|
#include <assets/types/image.h>
|
||
|
|
|
||
|
|
namespace lunarium
|
||
|
|
{
|
||
|
|
SimpleRenderScene::SimpleRenderScene(uint32_t logCat)
|
||
|
|
: BaseScene(logCat)
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
void SimpleRenderScene::OnLoad()
|
||
|
|
{
|
||
|
|
mTextBoxWidth = 500;
|
||
|
|
|
||
|
|
// Currently the full default window size
|
||
|
|
mImageSize.Width = 1280;
|
||
|
|
mImageSize.Height = 720;
|
||
|
|
}
|
||
|
|
|
||
|
|
void SimpleRenderScene::OnTick(double delta)
|
||
|
|
{
|
||
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE))
|
||
|
|
{
|
||
|
|
Core::GetInstance().SignalShutdown();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Textbox size adjustment
|
||
|
|
if (Core::Input().IsKeyDown(KeyCode::LEFT))
|
||
|
|
{
|
||
|
|
mTextBoxWidth -= 10;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Core::Input().IsKeyDown(KeyCode::RIGHT))
|
||
|
|
{
|
||
|
|
mTextBoxWidth += 10;
|
||
|
|
}
|
||
|
|
|
||
|
|
mTextBoxWidth = Math::ClampI(mTextBoxWidth, 20, 500);
|
||
|
|
|
||
|
|
// Image Size adjustment
|
||
|
|
if (Core::Input().IsKeyDown(KeyCode::DOWN))
|
||
|
|
{
|
||
|
|
mImageSize.Width -= 10;
|
||
|
|
mImageSize.Height -= 10;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Core::Input().IsKeyDown(KeyCode::UP))
|
||
|
|
{
|
||
|
|
mImageSize.Width += 10;
|
||
|
|
mImageSize.Height += 10;
|
||
|
|
}
|
||
|
|
|
||
|
|
mImageSize.Width = Math::ClampI(mImageSize.Width, 320, 1280);
|
||
|
|
mImageSize.Height = Math::ClampI(mImageSize.Height, 180, 720);
|
||
|
|
|
||
|
|
// Render to texture testing
|
||
|
|
OpRes result = Core::GetInstance().BeginRenderToTexture();
|
||
|
|
if (Failed(result))
|
||
|
|
{
|
||
|
|
Logger::Log(mLogCat, LogLevel::WARNING, "Unable to render to texture: %s", result.Description.c_str());
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
IGraphics& g = Core::Graphics();
|
||
|
|
|
||
|
|
g.DrawFilledEllipse(glm::vec2(600, 300), glm::vec2(100, 150), Color(1.0f, 0.0f, 1.0f, 1.0f), 100);
|
||
|
|
g.DrawString("This is a test of the text renderer!", Rectangle(100, 200, mTextBoxWidth, 300),
|
||
|
|
Color(0.0f, 1.0f, 1.0f, 1.0f), 0.5f, g.DefaultFont());
|
||
|
|
|
||
|
|
mpRenderedImage = Core::GetInstance().EndRenderToTexture();
|
||
|
|
}
|
||
|
|
|
||
|
|
void SimpleRenderScene::OnRender(IGraphics* g)
|
||
|
|
{
|
||
|
|
g->DrawImage(*mpRenderedImage, Rectangle(0.0f, 0.0f, (float)mpRenderedImage->GetWidth(), (float)mpRenderedImage->GetHeight()),
|
||
|
|
Rectangle(0.0f, 0.0f, (float)mImageSize.Width, (float)mImageSize.Height), Color(1.0f, 1.0f, 1.0f, 1.0f));
|
||
|
|
|
||
|
|
g->DrawBox(Rectangle(0.0f, 0.0f, (float)mImageSize.Width, (float)mImageSize.Height), Color(0.0f, 0.0f, 0.0f, 1.0f), 1.0f);
|
||
|
|
}
|
||
|
|
}
|