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-01-14 00:17:27 +00:00
|
|
|
#define USE_SHADER_X16
|
2017-11-14 17:04:04 +00:00
|
|
|
|
2018-01-05 21:51:05 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
#ifdef USE_SHADER_X16
|
2018-01-05 21:51:05 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
|
|
|
|
std::vector<TRenderPair> linesToRenderBoxesX16(const std::vector<std::pair<Vector2f, Vector2f>>& lineArr)
|
|
|
|
{
|
|
|
|
std::vector<TRenderPair> lineRenderPairArr;
|
|
|
|
|
|
|
|
size_t boxCount = lineArr.size() / 16;
|
|
|
|
|
|
|
|
if (lineArr.size() % 16 > 0)
|
|
|
|
{
|
|
|
|
boxCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
lineRenderPairArr.resize(boxCount);
|
|
|
|
|
|
|
|
//Set some initial values:
|
|
|
|
for (size_t i = 0; i < lineRenderPairArr.size(); i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t j = 0; j < 16; j++)
|
|
|
|
{
|
|
|
|
lineRenderPairArr[i].first.Vec4Map["lineParams" + boost::lexical_cast<std::string>(j)] = Vector4f(0, 0, 9999, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < lineArr.size(); i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
size_t boxIndex = i / 16;
|
|
|
|
|
|
|
|
Vector2f startPoint = lineArr[i].first;
|
|
|
|
Vector2f endPoint = lineArr[i].second;
|
|
|
|
|
|
|
|
|
|
|
|
auto& pair = lineRenderPairArr[boxIndex];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), startPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), endPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), endPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), startPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), endPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), startPoint(1), 0));
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
|
|
pair.first.Vec4Map["lineParams" + boost::lexical_cast<std::string>(i % 16)] = Vector4f(a, b, c, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& pair : lineRenderPairArr)
|
|
|
|
{
|
|
|
|
pair.second.RefreshBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return lineRenderPairArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<TRenderPair> linesToRenderBoxes(const std::vector<std::pair<Vector2f, Vector2f>>& lineArr)
|
|
|
|
{
|
|
|
|
std::vector<TRenderPair> lineRenderPairArr;
|
|
|
|
|
|
|
|
lineRenderPairArr.resize(lineArr.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < lineArr.size(); i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
Vector2f startPoint = lineArr[i].first;
|
|
|
|
Vector2f endPoint = lineArr[i].second;
|
|
|
|
|
|
|
|
|
|
|
|
auto& pair = lineRenderPairArr[i];
|
|
|
|
|
|
|
|
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), startPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), endPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), endPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), startPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), endPoint(1), 0));
|
|
|
|
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), startPoint(1), 0));
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
pair.first.Vec4Map["lineParams"] = Vector4f(a, b, c, 0);
|
|
|
|
|
|
|
|
pair.second.RefreshBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
return lineRenderPairArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
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)));
|
|
|
|
|
2017-01-10 12:43:06 +00:00
|
|
|
ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt");
|
2017-12-02 10:25:02 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2017-01-10 12:43:06 +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-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++)
|
|
|
|
{
|
|
|
|
lineArr.push_back({ {10.f + i * 20.f, 10.f}, { 20.f + i * 20.f, 400.f } });
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
lineArr.push_back({ { 20.f + i * 20.f, 400.f },{ 30.f + i * 20.f, 10.f } });
|
|
|
|
};
|
2017-12-04 11:14:14 +00:00
|
|
|
|
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
#ifdef USE_SHADER_X16
|
|
|
|
lineRenderPairArr = linesToRenderBoxesX16(lineArr);
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
#else
|
|
|
|
lineRenderPairArr = linesToRenderBoxes(lineArr);
|
2017-12-04 11:14:14 +00:00
|
|
|
|
2018-01-14 00:17:27 +00:00
|
|
|
#endif
|
|
|
|
|
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-01-14 00:17:27 +00:00
|
|
|
for (auto& pair : lineRenderPairArr)
|
2017-12-04 11:14:14 +00:00
|
|
|
{
|
|
|
|
TRenderParamsSetter params(pair.first);
|
|
|
|
Renderer->DrawTriangleList(pair.second);
|
|
|
|
}
|
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;
|
|
|
|
}
|