Working on examples
This commit is contained in:
1 parent
13f3e3ee9b
commit
69c5aa1f0e
16 files changed
+1033
-39
No files matched your search
+117
-37
@@ -47,6 +47,7 @@ Matrix3f quatToMatrix(Vector4f q) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TMyApplication::InnerInit()
|
||||
{
|
||||
|
||||
@@ -75,8 +76,13 @@ void TMyApplication::InnerInit()
|
||||
ResourceManager->ShaderManager.AddShader("ColorShader", "color_vertex.txt", "color_fragment.txt");
|
||||
ResourceManager->ShaderManager.AddShader("SSAA_4X", "SSAA_4X.vertex", "SSAA_4X.frag");
|
||||
ResourceManager->ShaderManager.AddShader("ParallaxShader", "parallax_vertex.txt", "parallax_fragment.txt");
|
||||
ResourceManager->ShaderManager.AddShader("PhongShader", "phong_vertex.txt", "phong_fragment.txt");
|
||||
|
||||
|
||||
|
||||
Renderer->PushShader("DefaultShader");
|
||||
|
||||
|
||||
ResourceManager->TexList.AddTexture("console_bkg.bmp");
|
||||
|
||||
ResourceManager->TexList.AddTexture("background.jpg");
|
||||
@@ -84,11 +90,14 @@ void TMyApplication::InnerInit()
|
||||
ResourceManager->TexList.AddTexture("NormalMap.png");
|
||||
ResourceManager->TexList.AddTexture("linesAll.png");
|
||||
|
||||
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
|
||||
|
||||
Vector2f const bottomLeft(-1000, -1000);
|
||||
float const W = 2000;
|
||||
float const H = 2000;
|
||||
Vector2f const bottomLeft(-500, -500);
|
||||
float const W = 1000;
|
||||
float const H = 1000;
|
||||
|
||||
Vector2f const backgroundBottomLeft(-1000, -1000);
|
||||
float const backgroundW = 2000;
|
||||
float const backgroundH = 2000;
|
||||
|
||||
{
|
||||
//resolution of background image
|
||||
@@ -96,13 +105,13 @@ void TMyApplication::InnerInit()
|
||||
float const imageH = 512;
|
||||
|
||||
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(bottomLeft[0], 0, bottomLeft[1]));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(bottomLeft[0], 0, bottomLeft[1] + H));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(bottomLeft[0] + W, 0, bottomLeft[1] + H));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0], 0, backgroundBottomLeft[1]));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0], 0, backgroundBottomLeft[1] + backgroundH));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0] + backgroundW, 0, backgroundBottomLeft[1] + backgroundH));
|
||||
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(bottomLeft[0] + W, 0, bottomLeft[0] + H));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(bottomLeft[0] + W, 0, bottomLeft[0]));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(bottomLeft[0], 0, bottomLeft[0]));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0] + backgroundW, 0, backgroundBottomLeft[0] + backgroundH));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0] + backgroundW, 0, backgroundBottomLeft[0]));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0], 0, backgroundBottomLeft[0]));
|
||||
|
||||
float const tw = W / imageW;
|
||||
float const th = H / imageH;
|
||||
@@ -134,32 +143,59 @@ void TMyApplication::InnerInit()
|
||||
float const step = 12;
|
||||
float const thick = 10;
|
||||
|
||||
auto f = [this, texW, texH, thick, W, H] (const Vector3f &p1, const Vector3f &p2) {
|
||||
auto f = [this, texW, texH, thick, W, H] (const Vector3f &p1, const Vector3f &p2, float t) {
|
||||
auto pv = p2 - p1;
|
||||
Vector3f ortho(pv[2], 0, pv[0]);
|
||||
ortho.normalize();
|
||||
auto p3 = p2 + ortho * thick;
|
||||
auto p4 = p1 + ortho * thick;
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p2);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p4);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
|
||||
float extraHeight = std::min(20.f, -(t - 1)*t*100.f);
|
||||
|
||||
auto texThick = thick / texW;
|
||||
auto m = (p1[0] + p2[0]) / 2 / texW;
|
||||
auto y = H / texH;
|
||||
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, y));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, 0));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
|
||||
const size_t segmentCount = 20;
|
||||
|
||||
for (int i = 0; i < segmentCount; i++)
|
||||
{
|
||||
auto pStart = p1 + pv * i/ segmentCount;
|
||||
auto pEnd = p1 + pv * (i+1)/ segmentCount;
|
||||
|
||||
auto pStartShifted = pStart + ortho * thick;
|
||||
auto pEndShifted = pEnd + ortho * thick;
|
||||
|
||||
float innerHeightStart = std::min(20.f, -(i / 20.f) * (i / 20.f - 1.f)*100.f);
|
||||
float innerHeightEnd = std::min(20.f, -((i+1) / 20.f) * ((i+1) / 20.f - 1.f)*100.f);
|
||||
|
||||
Vector3f extraShiftStart = { 0, std::min(innerHeightStart, extraHeight), 0 };
|
||||
Vector3f extraShiftEnd = { 0, std::min(innerHeightEnd, extraHeight), 0 };
|
||||
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pStart + extraShiftStart);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pEnd + extraShiftEnd);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pEndShifted + extraShiftEnd);
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pEndShifted + extraShiftEnd);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pStartShifted + extraShiftStart);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pStart + extraShiftStart);
|
||||
|
||||
auto texThick = thick / texW;
|
||||
auto m = (pStart[0] + pEnd[0]) / 2 / texW;
|
||||
auto yStart = (H / texH)*(i / 20.f);
|
||||
auto yEnd = (H / texH)*((i+1) / 20.f);
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, yStart));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, yEnd));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, yEnd));
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, yEnd));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, yStart));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, yStart));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -168,19 +204,25 @@ void TMyApplication::InnerInit()
|
||||
|
||||
while (p1[0] < bottomLeft[0] + W) {
|
||||
|
||||
float t = (p1(0) - bottomLeft(0)) / W;
|
||||
|
||||
auto p2 = p1 - Vector3f(0, 0, W);
|
||||
f(p1, p2);
|
||||
f(p1, p2, t);
|
||||
|
||||
auto p3 = p1 + step * stepDirection;
|
||||
f(p3, p2);
|
||||
f(p3, p2, t);
|
||||
|
||||
p1 = p3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
background.first.ShaderName ="ParallaxShader";
|
||||
//background.first.ShaderName ="ParallaxShader";
|
||||
//DefaultShader
|
||||
background.first.ShaderName = "DefaultShader";
|
||||
|
||||
fabricRender.first.ShaderName = "ParallaxShader";
|
||||
//fabricRender.first.ShaderName = "PhongShader";
|
||||
|
||||
/*
|
||||
* Line below should be in tes-engine/include/ShaderManager/ShaderManager.h
|
||||
@@ -195,6 +237,32 @@ void TMyApplication::InnerInit()
|
||||
|
||||
background.second.RefreshBuffer();
|
||||
fabricRender.second.RefreshBuffer();
|
||||
|
||||
|
||||
|
||||
|
||||
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 0, 0));
|
||||
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 512, 0));
|
||||
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 512, 0));
|
||||
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 512, 0));
|
||||
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 0, 0));
|
||||
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 0, 0));
|
||||
|
||||
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
|
||||
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 1));
|
||||
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1, 1));
|
||||
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1, 1));
|
||||
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1, 0));
|
||||
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
|
||||
|
||||
|
||||
rect.second.RefreshBuffer();
|
||||
|
||||
Renderer->SetOrthoProjection();
|
||||
|
||||
Renderer->SetFullScreenViewport();
|
||||
|
||||
|
||||
|
||||
Inited = true;
|
||||
}
|
||||
@@ -262,6 +330,12 @@ void TMyApplication::OnMouseWheel(short int delta)
|
||||
}
|
||||
|
||||
void TMyApplication::InnerDraw()
|
||||
{
|
||||
|
||||
DrawScene();
|
||||
}
|
||||
|
||||
void TMyApplication::DrawScene()
|
||||
{
|
||||
|
||||
Renderer->SetPerspectiveProjection(pi / 6, 10.f, 10000.f);
|
||||
@@ -291,7 +365,7 @@ void TMyApplication::InnerDraw()
|
||||
|
||||
auto mat2 = quatToMatrix(quat2);
|
||||
|
||||
Vector3f lightPos = {0.f, 1.f, 1.f};
|
||||
Vector3f lightPos = { 0.f, -1.f, -1.f };
|
||||
|
||||
Vector3f eye = mat2 * mat1 * Vector3f(0.0f, 0.f, -distance);
|
||||
|
||||
@@ -312,23 +386,29 @@ void TMyApplication::InnerDraw()
|
||||
{
|
||||
TRenderParamsSetter params(fabricRender.first);
|
||||
|
||||
//RenderUniform3fv("cameraPos", eye.data());
|
||||
RenderUniform3fv("eye", eye.data());
|
||||
RenderUniform3fv("lightPos", lightPos.data());
|
||||
|
||||
Matrix3f normMatrix = Renderer->GetModelviewMatrix().inverse().transpose().block<3,3>(0,0);
|
||||
|
||||
//RenderUniform3fv("ambientLight", Vector3f(0.0f, 0.0f, 0.0f).data());
|
||||
//RenderUniform3fv("specularLight", Vector3f(0.0f, 0.0f, 0.0f).data());
|
||||
//RenderUniform3fv("ambientLight", Vector3f(0.0f, 0.0f, 0.0f).data());
|
||||
//RenderUniform1f("specularPower", 20.f);
|
||||
|
||||
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());
|
||||
RenderUniformMatrix3fv("ModelViewMatrix3x3", false, Renderer->GetModelviewMatrix().block<3, 3>(0, 0).data());
|
||||
|
||||
Renderer->DrawTriangleList(fabricRender.second);
|
||||
Renderer->DrawTriangleList(fabricRender.second);
|
||||
}
|
||||
|
||||
|
||||
Renderer->PopMatrix();
|
||||
|
||||
CheckGlError("");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ protected:
|
||||
public:
|
||||
TRenderPair fabricRender;
|
||||
TRenderPair background;
|
||||
TRenderPair rect;
|
||||
|
||||
bool Loaded;
|
||||
|
||||
@@ -46,6 +47,9 @@ public:
|
||||
|
||||
virtual void InnerDraw();
|
||||
|
||||
|
||||
void DrawScene();
|
||||
|
||||
virtual void InnerUpdate(size_t dt);
|
||||
|
||||
bool IsLoaded();
|
||||
|
||||
Reference in new issue
Block a user