2017-01-10 12:43:06 +00:00
|
|
|
#include "main_code.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "include/Engine.h"
|
|
|
|
|
|
|
|
#include "main_code.h"
|
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
TMyApplication* Application;
|
2017-01-10 12:43:06 +00:00
|
|
|
|
2018-04-11 13:40:22 +00:00
|
|
|
//static const float BUFFER_DISTANCE = 30.f;
|
|
|
|
static const float BUFFER_DISTANCE = 50.f;
|
|
|
|
|
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
TRenderPair linesToRenderBoxes(const std::vector<std::pair<Vector2f, Vector2f>>& lineArr)
|
2018-01-14 00:17:27 +00:00
|
|
|
{
|
2018-04-11 14:16:37 +00:00
|
|
|
TRenderPair pair;
|
2018-01-14 00:17:27 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < lineArr.size(); i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
Vector2f startPoint = lineArr[i].first;
|
|
|
|
Vector2f endPoint = lineArr[i].second;
|
|
|
|
|
2018-04-11 13:40:22 +00:00
|
|
|
Vector2f renderAreaStart{ std::min<float>(startPoint(0), endPoint(0)) - BUFFER_DISTANCE, std::min<float>(startPoint(1), endPoint(1)) - BUFFER_DISTANCE };
|
|
|
|
|
|
|
|
Vector2f renderAreEnd{ std::max<float>(startPoint(0), endPoint(0)) + BUFFER_DISTANCE, std::max<float>(startPoint(1), endPoint(1)) + BUFFER_DISTANCE };
|
2018-01-14 00:17:27 +00:00
|
|
|
|
2018-04-11 13:40:22 +00:00
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreaStart(0), renderAreaStart(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreaStart(0), renderAreEnd(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreEnd(0), renderAreEnd(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreaStart(0), renderAreaStart(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreEnd(0), renderAreEnd(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreEnd(0), renderAreaStart(1), 0));
|
|
|
|
|
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1));
|
|
|
|
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1));
|
|
|
|
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1));
|
|
|
|
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1));
|
|
|
|
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1));
|
|
|
|
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1));
|
|
|
|
|
|
|
|
Vector2f lineVec = endPoint - startPoint;
|
|
|
|
Vector2f lineNormVec = { -lineVec(1), lineVec(0) };
|
|
|
|
|
|
|
|
lineNormVec.normalize();
|
|
|
|
|
|
|
|
//float distance = abs(normVec.x*(position.x - startPoint.x) + normVec.y*(position.y - startPoint.y));
|
|
|
|
//distance = a*x + b*y + c, here we calculate a, b,c and pass them to shader
|
|
|
|
float a = lineNormVec(0);
|
|
|
|
float b = lineNormVec(1);
|
|
|
|
float c = -(lineNormVec(0)*startPoint(0) + lineNormVec(1)*startPoint(1));
|
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
|
|
|
|
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
|
|
|
|
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
|
|
|
|
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
|
|
|
|
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
|
|
|
|
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
|
|
|
|
|
|
|
|
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
|
|
|
|
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
|
|
|
|
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
|
|
|
|
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
|
|
|
|
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
|
|
|
|
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
|
|
|
|
|
2018-04-11 13:40:22 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
pair.second.RefreshBuffer();
|
2018-04-11 13:40:22 +00:00
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
return pair;
|
2018-01-14 00:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-05 21:51:05 +00:00
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
void TMyApplication::InnerInit()
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
Application = this;
|
|
|
|
|
|
|
|
#ifdef TARGET_WIN32
|
|
|
|
#ifdef NDEBUG
|
|
|
|
ST::PathToResources = "resources/";
|
|
|
|
#else
|
|
|
|
ST::PathToResources = "../../../assets/";
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TARGET_IOS
|
|
|
|
ST::PathToResources = "assets/";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (Console != NULL)
|
|
|
|
{
|
|
|
|
*Console<<"APP INIT\n";
|
|
|
|
}
|
2017-11-14 17:04:04 +00:00
|
|
|
srand (static_cast<size_t>(time(NULL)));
|
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
//ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt");
|
|
|
|
//ResourceManager->ShaderManager.AddShader("ColorShader", "color_vertex.txt", "color_fragment.txt");
|
2018-01-05 21:51:05 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
#ifdef USE_SHADER_X16
|
|
|
|
ResourceManager->ShaderManager.AddShader("AntialiasingShader", "ms_vertex.txt", "ms_fragment_x16.txt");
|
|
|
|
#else
|
|
|
|
ResourceManager->ShaderManager.AddShader("AntialiasingShader", "ms_vertex.txt", "ms_fragment.txt");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-01-05 21:51:05 +00:00
|
|
|
|
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
//Renderer->PushShader("DefaultShader");
|
2017-11-14 17:04:04 +00:00
|
|
|
|
2017-01-10 12:43:06 +00:00
|
|
|
ResourceManager->TexList.AddTexture("console_bkg.bmp");
|
2017-11-14 17:04:04 +00:00
|
|
|
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
Renderer->PushShader("AntialiasingShader");
|
|
|
|
|
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
std::vector<std::pair<Vector2f, Vector2f>> lineArr;
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
2018-04-11 13:40:22 +00:00
|
|
|
lineArr.push_back({ {50.f + i * 20.f, 50.f}, { 60.f + i * 20.f, 440.f } });
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2018-04-11 13:40:22 +00:00
|
|
|
lineArr.push_back({ { 60.f + i * 20.f, 440.f },{ 70.f + i * 20.f, 50.f } });
|
2018-01-14 00:17:27 +00:00
|
|
|
};
|
2017-12-04 11:14:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
lineRenderPair = linesToRenderBoxes(lineArr);
|
2017-01-10 12:43:06 +00:00
|
|
|
|
|
|
|
Renderer->SetOrthoProjection();
|
|
|
|
|
|
|
|
Renderer->SetFullScreenViewport();
|
2018-01-05 21:51:05 +00:00
|
|
|
|
2017-12-04 11:14:14 +00:00
|
|
|
Inited = true;
|
|
|
|
|
2017-12-02 10:25:02 +00:00
|
|
|
|
|
|
|
|
2018-01-05 21:51:05 +00:00
|
|
|
|
|
|
|
|
2017-01-10 12:43:06 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
void TMyApplication::InnerDeinit()
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
|
|
|
Inited = false;
|
|
|
|
Loaded = false;
|
|
|
|
if (Console != NULL)
|
|
|
|
{
|
|
|
|
*Console<<"APP DEINIT\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
void TMyApplication::InnerOnTapDown(Vector2f p)
|
|
|
|
{
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2017-01-10 12:43:06 +00:00
|
|
|
}
|
2017-11-14 17:04:04 +00:00
|
|
|
|
|
|
|
void TMyApplication::InnerOnTapUp(Vector2f p)
|
|
|
|
{
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2017-01-10 12:43:06 +00:00
|
|
|
}
|
2017-02-26 23:07:37 +00:00
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
void TMyApplication::InnerOnTapUpAfterMove(Vector2f p)
|
2017-02-26 23:07:37 +00:00
|
|
|
{
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2017-02-26 23:07:37 +00:00
|
|
|
}
|
2017-11-14 17:04:04 +00:00
|
|
|
|
|
|
|
void TMyApplication::InnerOnMove(Vector2f p, Vector2f shift)
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2017-01-10 12:43:06 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
void TMyApplication::OnFling(Vector2f v)
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-04 11:14:14 +00:00
|
|
|
|
|
|
|
void TMyApplication::InnerDraw()
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
|
|
|
|
2018-01-05 21:51:05 +00:00
|
|
|
//Render the frame
|
2018-01-14 00:17:27 +00:00
|
|
|
Renderer->PushShader("AntialiasingShader");
|
|
|
|
|
2017-12-04 11:14:14 +00:00
|
|
|
Renderer->SetProjectionMatrix(512.f, 512.f);
|
2018-01-05 21:51:05 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
2017-12-04 11:14:14 +00:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
|
|
|
CheckGlError("");
|
2017-01-10 12:43:06 +00:00
|
|
|
|
2018-04-11 14:16:37 +00:00
|
|
|
|
|
|
|
EnableVertexAttribArray("vLineParams");
|
|
|
|
EnableVertexAttribArray("vStartPointEndPoint");
|
|
|
|
|
|
|
|
TRenderParamsSetter params(lineRenderPair.first);
|
|
|
|
Renderer->DrawTriangleList(lineRenderPair.second);
|
|
|
|
|
|
|
|
DisableVertexAttribArray("vStartPointEndPoint");
|
|
|
|
DisableVertexAttribArray("vLineParams");
|
2017-01-10 12:43:06 +00:00
|
|
|
|
2017-12-04 11:14:14 +00:00
|
|
|
Renderer->PopShader();
|
2017-01-10 12:43:06 +00:00
|
|
|
|
2017-12-04 11:14:14 +00:00
|
|
|
CheckGlError("");
|
2018-01-05 21:51:05 +00:00
|
|
|
|
|
|
|
|
2017-01-10 12:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
void TMyApplication::InnerUpdate(size_t dt)
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
bool TMyApplication::IsLoaded()
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
|
|
|
return Loaded;
|
|
|
|
}
|
|
|
|
|
2017-11-14 17:04:04 +00:00
|
|
|
bool TMyApplication::IsInited()
|
2017-01-10 12:43:06 +00:00
|
|
|
{
|
|
|
|
return Inited;
|
|
|
|
}
|