1 // Copyright (C) 2008-2012 Christian Stehno, Colin MacDonald
\r
2 // No rights reserved: this software is in the public domain.
\r
4 #include "testUtils.h"
\r
7 using namespace core;
\r
8 using namespace scene;
\r
9 using namespace video;
\r
11 using namespace gui;
\r
13 //! Tests projection matrices
\r
14 static bool runTestWithDriver(E_DRIVER_TYPE driverType)
\r
16 IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
\r
18 return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs
\r
20 IVideoDriver* driver = device->getVideoDriver();
\r
22 stabilizeScreenBackground(driver);
\r
24 logTestString("Testing driver %ls\n", driver->getName());
\r
28 driver->beginScene(video::ECBF_COLOR, SColor(255,0,0,0));
\r
31 mat.MaterialType = EMT_SOLID;
\r
32 mat.Lighting = false;
\r
33 mat.ZBuffer = false;
\r
34 mat.ZWriteEnable = video::EZW_OFF;
\r
37 driver->setMaterial(mat);
\r
39 core::dimension2d<f32> dims(driver->getCurrentRenderTargetSize());
\r
40 //apply custom projection, no offset
\r
41 core::matrix4 pmtx = matrix4().buildProjectionMatrixOrthoLH(dims.Width, dims.Height, 0, 100);
\r
42 driver->setTransform(ETS_PROJECTION, pmtx);
\r
43 driver->setTransform(ETS_VIEW, matrix4());
\r
44 driver->setTransform(ETS_WORLD, matrix4());
\r
46 //the red cross appears at center
\r
47 for (u32 i=0; i<10; ++i)
\r
49 driver->draw3DLine(vector3df(0.f+i,-50.f,1.f), vector3df(0.f+i,50.f,1.f), SColor(255,255,0,0));
\r
50 driver->draw3DLine(vector3df(-50.f,0.f+i,1.f), vector3df(50.f,0.f+i,1.f), SColor(255,255,0,0));
\r
53 //apply custom projection, offset to right-top
\r
54 pmtx.setTranslation(vector3df(0.7f, 0.7f, 0.f));
\r
55 driver->setTransform(ETS_PROJECTION, pmtx);
\r
56 driver->setTransform(ETS_VIEW, matrix4());
\r
57 driver->setTransform(ETS_WORLD, matrix4());
\r
59 //The green cross must be in right-top corner. But for OpenGL driver it is in left-top corner
\r
60 for (u32 i=0; i<10; ++i)
\r
62 driver->draw3DLine(vector3df(0.f+i,-50,1), vector3df(0.f+i,50,1), SColor(255,0,255,0));
\r
63 driver->draw3DLine(vector3df(-50,0.f+i,1), vector3df(50,0.f+i,1), SColor(255,0,255,0));
\r
68 result = takeScreenshotAndCompareAgainstReference(driver, "-projMat.png", 98.71f);
\r
70 device->closeDevice();
\r
78 bool projectionMatrix(void)
\r
82 // TODO: Seems that software driver does not handle this projection matrix
\r
83 TestWithAllDrivers(runTestWithDriver);
\r