Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schellingb/f7df8b34e896a62581540fddf27f12e9 to your computer and use it in GitHub Desktop.
Save schellingb/f7df8b34e896a62581540fddf27f12e9 to your computer and use it in GitHub Desktop.
#include <ZL_Application.h>
#include <ZL_Display.h>
#include <ZL_Display3D.h>
#include <ZL_Surface.h>
#include <ZL_Input.h>
// Size of the inner screen
enum { WW = 64, WH = 64 };
// 3D Stuff
static ZL_Mesh mshBox;
static ZL_Light Light;
static ZL_Camera Camera;
static ZL_RenderList RenderList;
void Init()
{
// Make a 3D cube with dimensions 1,1,1 and a shiny material
using namespace ZL_MaterialModes;
mshBox = ZL_Mesh::BuildBox(ZL_Vector3(1.f), ZL_Material(MM_STATICCOLOR | MM_SPECULARSTATIC));
// Place the light and the camera
Light.SetPosition(ZL_Vector3(-5, 0, 3)).SetColor(ZLRGB(.5,.5,.5));
Camera.SetAspectRatio((float)WW / WH).SetLookAt(ZLV3(-3,0,0), ZLV3(0,0,0));
}
void Update()
{
if (ZL_Input::Down(ZLK_ESCAPE)) ZL_Application::Quit();
// Prepare to draw the cube with a rotation based on passed time
RenderList.Reset();
RenderList.Add(mshBox, ZL_Matrix::MakeRotateX(ZLSECONDS)*ZL_Matrix::MakeRotateY(ZLSECONDS));
}
void Draw()
{
// Clear the screen dark blue then draw the prepared rendering list
ZL_Display::ClearFill(ZL_Color::DarkBlue);
ZL_Display3D::DrawListWithLight(RenderList, Camera, Light);
}
static struct sLowRez : public ZL_Application
{
sLowRez() : ZL_Application(60) { }
ZL_Surface srfScreen;
virtual void Load(int argc, char *argv[])
{
if (!ZL_Application::LoadReleaseDesktopDataBundle()) return;
if (!ZL_Display::Init("LowRez", 1280, 720, ZL_DISPLAY_ALLOWRESIZEHORIZONTAL)) return;
ZL_Display3D::Init();
ZL_Input::Init();
// Create a render-to-texture with a set size and disable bilinear filtering on it
srfScreen = ZL_Surface(WW, WH).SetTextureFilterMode();
Init();
}
virtual void AfterFrame()
{
Update();
// Draw to our screen texture
srfScreen.RenderToBegin();
Draw();
srfScreen.RenderToEnd();
// Figure out if the screen texture inside the window needs a horizontal or vertical offset
ZL_Display::ClearFill();
float InnerAspectR = (float)WW/WH;
if (InnerAspectR > ZLASPECTR)
{
// Screen texture is wider than window, draw with a vertical offset
srfScreen.DrawTo(ZL_Rectf(ZLCENTER, ZLV(ZLHALFW, ZLHALFW / InnerAspectR)));
}
else
{
// Screen texture is taller than window, draw with a horizontal offset
srfScreen.DrawTo(ZL_Rectf(ZLCENTER, ZLV(ZLHALFH * InnerAspectR, ZLHALFH)));
}
}
} LowRez;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment