Skip to content

Commit

Permalink
Tests|GL: Added a MD2 test model for GLSandbox
Browse files Browse the repository at this point in the history
Getting started with ModelDrawable.
  • Loading branch information
skyjake committed Mar 11, 2014
1 parent f82bdf1 commit 2022495
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Binary file added doomsday/tests/test_glsandbox/marine.md2
Binary file not shown.
4 changes: 3 additions & 1 deletion doomsday/tests/test_glsandbox/test_glsandbox.pro
Expand Up @@ -17,6 +17,7 @@ SOURCES += \
deployTest($$TARGET)

gfx.files = testpic.png
model.files = marine.md2

macx {
linkBinaryToBundledLibdeng2($${TARGET}.app/Contents/MacOS/$${TARGET})
Expand All @@ -27,7 +28,8 @@ macx {
}
else {
gfx.path = $$DENG_DATA_DIR/graphics
INSTALLS += gfx
model.path = $$DENG_DATA_DIR
INSTALLS += gfx model
}

HEADERS += \
Expand Down
33 changes: 32 additions & 1 deletion doomsday/tests/test_glsandbox/testwindow.cpp
Expand Up @@ -30,6 +30,7 @@
#include <de/GLTexture>
#include <de/GLTarget>
#include <de/AtlasTexture>
#include <de/ModelDrawable>
#include <de/GuiApp>
#include <de/Clock>

Expand All @@ -44,7 +45,8 @@ DENG2_OBSERVES(Bank, Load)
enum Mode
{
TestRenderToTexture,
TestDynamicAtlas
TestDynamicAtlas,
TestModel
};

Mode mode;
Expand All @@ -59,6 +61,7 @@ DENG2_OBSERVES(Bank, Load)
GLUniform uTex;
GLTexture frameTex;
GLTexture testpic;
ModelDrawable model;
std::auto_ptr<AtlasTexture> atlas;
std::auto_ptr<GLTarget> frameTarget;
Time startedAt;
Expand Down Expand Up @@ -95,6 +98,8 @@ DENG2_OBSERVES(Bank, Load)
imageBank.add("rtt.cube", "/data/graphics/testpic.png");
//imageBank.loadAll();
imageBank.audienceForLoad() += this;

model.load(App::rootFolder().locate<File const>("/data/marine.md2"));
}

void canvasGLInit(Canvas &cv)
Expand Down Expand Up @@ -272,6 +277,12 @@ DENG2_OBSERVES(Bank, Load)
Matrix4f::scale(cv.height()/150.f) *
Matrix4f::translate(Vector2f(-50, -50));
break;

case TestModel:
// 3D projection.
projMatrix = Matrix4f::perspective(40, float(cv.width())/float(cv.height())) *
Matrix4f::lookAt(Vector3f(), Vector3f(0, 0, -5), Vector3f(0, -1, 0));
break;
}
}

Expand Down Expand Up @@ -313,6 +324,10 @@ DENG2_OBSERVES(Bank, Load)
drawAtlasFrame();
GLState::pop();
break;

case TestModel:
drawModel();
break;
}
}

Expand Down Expand Up @@ -342,6 +357,15 @@ DENG2_OBSERVES(Bank, Load)
atlasOb.draw();
}

void drawModel()
{
GLState::current().target().clear(GLTarget::ColorDepth);

// TODO: provide mvp matrix (projection * model)

model.draw();
}

void timeChanged(Clock const &clock)
{
if(!startedAt.isValid())
Expand All @@ -353,6 +377,7 @@ DENG2_OBSERVES(Bank, Load)
switch(mode)
{
case TestRenderToTexture:
case TestModel:
modelMatrix = Matrix4f::rotate(std::cos(uTime.toFloat()/2) * 45, Vector3f(1, 0, 0)) *
Matrix4f::rotate(std::sin(uTime.toFloat()/3) * 60, Vector3f(0, 1, 0));
break;
Expand Down Expand Up @@ -421,6 +446,7 @@ TestWindow::TestWindow() : d(new Instance(this))
QToolBar *tools = addToolBar(tr("Tests"));
tools->addAction("RTT", this, SLOT(testRenderToTexture()));
tools->addAction("Atlas", this, SLOT(testDynamicAtlas()));
tools->addAction("Model", this, SLOT(testModel()));
}

void TestWindow::canvasGLDraw(Canvas &canvas)
Expand All @@ -440,3 +466,8 @@ void TestWindow::testDynamicAtlas()
{
d->setMode(Instance::TestDynamicAtlas);
}

void TestWindow::testModel()
{
d->setMode(Instance::TestModel);
}
1 change: 1 addition & 0 deletions doomsday/tests/test_glsandbox/testwindow.h
Expand Up @@ -34,6 +34,7 @@ class TestWindow : public de::CanvasWindow
public slots:
void testRenderToTexture();
void testDynamicAtlas();
void testModel();

private:
DENG2_PRIVATE(d)
Expand Down

0 comments on commit 2022495

Please sign in to comment.