Test rendering. Works
This commit is contained in:
parent
e5b1e63085
commit
d80637e343
@ -19,6 +19,34 @@ boost::shared_ptr<TMyApplication> App(new TMyApplication);
|
||||
|
||||
bool animPaused = false;
|
||||
|
||||
|
||||
Eigen::Matrix3f quatToMatrix(Eigen::Vector4f q) {
|
||||
using namespace Eigen;
|
||||
Matrix3f result;
|
||||
double sqw = q(3)*q(3);
|
||||
double sqx = q(0)*q(0);
|
||||
double sqy = q(1)*q(1);
|
||||
double sqz = q(2)*q(2);
|
||||
// invs (inverse square length) is only required if quaternion is not already normalised
|
||||
double invs = 1 / (sqx + sqy + sqz + sqw);
|
||||
result(0, 0) = (sqx - sqy - sqz + sqw)*invs; // since sqw + sqx + sqy + sqz =1/invs*invs
|
||||
result(1, 1) = (-sqx + sqy - sqz + sqw)*invs;
|
||||
result(2, 2) = (-sqx - sqy + sqz + sqw)*invs;
|
||||
double tmp1 = q(0)*q(1);
|
||||
double tmp2 = q(2)*q(3);
|
||||
result(1, 0) = 2.0 * (tmp1 + tmp2)*invs;
|
||||
result(0, 1) = 2.0 * (tmp1 - tmp2)*invs;
|
||||
tmp1 = q(0)*q(2);
|
||||
tmp2 = q(1)*q(3);
|
||||
result(2, 0) = 2.0 * (tmp1 - tmp2)*invs;
|
||||
result(0, 2) = 2.0 * (tmp1 + tmp2)*invs;
|
||||
tmp1 = q(1)*q(2);
|
||||
tmp2 = q(0)*q(3);
|
||||
result(2, 1) = 2.0 * (tmp1 + tmp2)*invs;
|
||||
result(1, 2) = 2.0 * (tmp1 - tmp2)*invs;
|
||||
return result;
|
||||
}
|
||||
|
||||
struct TOnClickTest
|
||||
{
|
||||
void operator()()
|
||||
@ -105,6 +133,26 @@ void TMyApplication::InnerInit()
|
||||
px = SE::FileToPropertyTree("textures.xml");
|
||||
SE::ResourceManager->TexList.Serialize(*px);
|
||||
|
||||
|
||||
|
||||
//test
|
||||
SE::ResourceManager->TexList.AddTexture("levelshot1.png");
|
||||
|
||||
testPair.second.Data.Vec3CoordArr[SE::CONST_STRING_POSITION_ATTRIB].emplace_back(Eigen::Vector3f(-100, -100, 0));
|
||||
testPair.second.Data.Vec3CoordArr[SE::CONST_STRING_POSITION_ATTRIB].emplace_back(Eigen::Vector3f(100, 0, 0));
|
||||
testPair.second.Data.Vec3CoordArr[SE::CONST_STRING_POSITION_ATTRIB].emplace_back(Eigen::Vector3f(0, 100, 0));
|
||||
|
||||
testPair.second.Data.Vec2CoordArr[SE::CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Eigen::Vector2f(0, 0));
|
||||
testPair.second.Data.Vec2CoordArr[SE::CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Eigen::Vector2f(1, 0));
|
||||
testPair.second.Data.Vec2CoordArr[SE::CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Eigen::Vector2f(0, 1));
|
||||
|
||||
testPair.first.ShaderName = "DefaultShader";
|
||||
|
||||
testPair.first.SamplerMap[SE::CONST_STRING_TEXTURE_UNIFORM] = "levelshot1.png";
|
||||
testPair.second.RefreshBuffer();
|
||||
//end
|
||||
|
||||
|
||||
//this cause exception
|
||||
//px = SE::FileToPropertyTree("fonts.xml");
|
||||
//SE::ResourceManager->FontManager.Serialize(*px);
|
||||
@ -160,6 +208,39 @@ void TMyApplication::InnerDeinit()
|
||||
//What to do on draw
|
||||
void TMyApplication::InnerDraw()
|
||||
{
|
||||
using namespace SE;
|
||||
Renderer->SetPerspectiveProjection(pi / 6, 10.f, 10000.f);
|
||||
Renderer->SetFullScreenViewport();
|
||||
Renderer->PushMatrix();
|
||||
float phi = pi / 6;
|
||||
float alpha = 0;
|
||||
float distance = 2000;
|
||||
Renderer->TranslateMatrix(Vector3f(0, 0, -distance));
|
||||
Vector4f quat1 = Vector4f(sin(phi / 2), 0, 0, cos(phi / 2));
|
||||
Vector4f quat2 = Vector4f(0, sin(alpha / 2), 0, cos(alpha / 2));
|
||||
Renderer->RotateMatrix(quat1);
|
||||
Renderer->RotateMatrix(quat2);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
CheckGlError("");
|
||||
auto mat1 = quatToMatrix(quat1);
|
||||
auto mat2 = quatToMatrix(quat2);
|
||||
Vector3f lightPos = { 0.f, 1.f, 1.f };
|
||||
Vector3f eye = mat2 * mat1 * Vector3f(0.0f, 0.f, -distance);
|
||||
{
|
||||
TRenderParamsSetter params(testPair.first);
|
||||
RenderUniform3fv("eye", eye.data());
|
||||
RenderUniform3fv("lightPos", lightPos.data());
|
||||
Matrix3f normMatrix = Renderer->GetModelviewMatrix().inverse().transpose().block<3, 3>(0, 0);
|
||||
RenderUniformMatrix3fv("NormalMatrix", false, normMatrix.data());
|
||||
RenderUniformMatrix4fv("ModelViewMatrix", false, Renderer->GetModelviewMatrix().data());
|
||||
RenderUniformMatrix3fv("ModelViewMatrix3x3", false, Renderer->GetModelviewMatrix().block<3, 3>(0, 0).data());
|
||||
Renderer->DrawTriangleList(testPair.second);
|
||||
}
|
||||
Renderer->PopMatrix();
|
||||
CheckGlError("");
|
||||
|
||||
}
|
||||
|
||||
//What to do on update. timer means how many ms passed since last update
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
|
||||
TMatch3Controller Match3Controller;
|
||||
|
||||
SE::TRenderPair testPair;
|
||||
|
||||
TMyApplication() : Inited(false) { }
|
||||
|
||||
virtual void InnerInit();
|
||||
|
Loading…
Reference in New Issue
Block a user