2018-10-18 16:04:42 +00:00
|
|
|
#include "main_code.h"
|
|
|
|
#ifdef TARGET_ANDROID
|
|
|
|
#include "android_api.h"
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "include/Engine.h"
|
|
|
|
|
|
|
|
#include "main_code.h"
|
|
|
|
|
|
|
|
bool makeShot = true;
|
|
|
|
|
|
|
|
|
|
|
|
extern int TimeOfDayPref;
|
|
|
|
extern bool SnowPref;
|
|
|
|
|
|
|
|
extern float lastOffsetX;
|
|
|
|
|
|
|
|
#ifdef TARGET_WIN32
|
|
|
|
int TimeOfDayPref = 0;
|
|
|
|
bool SnowPref = false;
|
|
|
|
|
|
|
|
#else
|
|
|
|
extern int TimeOfDayPref;
|
|
|
|
extern bool SnowPref;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
boost::mutex m2;
|
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
TPanoramicCamera mCamera;
|
|
|
|
const float cameraDistance = 100.f;
|
|
|
|
std::vector<int> iceIndexes;
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
class LoadingQueueVisitor : public boost::static_visitor<void>
|
|
|
|
{
|
|
|
|
public:
|
2018-10-19 05:34:55 +00:00
|
|
|
void operator()(boost::function<size_t()> f) const
|
2018-10-18 16:04:42 +00:00
|
|
|
{
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(boost::function<bool()> f) const
|
|
|
|
{
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(boost::function<void()> f) const
|
|
|
|
{
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TAndroidApplication::TAndroidApplication()
|
|
|
|
: TApplication()
|
|
|
|
, Inited(false)
|
|
|
|
, Loaded(false)
|
|
|
|
, WaterTimer(0)
|
|
|
|
, SnowTimer(0)
|
|
|
|
, CloudTimer(0)
|
|
|
|
, SkyTexShift(0)
|
|
|
|
, WaveDir(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TAndroidApplication::Serialize(boost::property_tree::ptree& propertyTree)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
float myMin(float a, float b)
|
|
|
|
{
|
|
|
|
return a < b ? a : b;
|
|
|
|
}
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
float myMax(float a, float b)
|
|
|
|
{
|
|
|
|
return a > b ? a : b;
|
|
|
|
}
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
void TAndroidApplication::LoadModels()
|
|
|
|
{
|
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
auto objData = loadObjFile("mountain/mountain2.obj", "");
|
2018-10-19 05:34:55 +00:00
|
|
|
mountain = ObjDataToRenderPairs(objData)[0][0];
|
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
ResourceManager->TexList.AddTexture("mountain.png");
|
|
|
|
mountain.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "mountain.png";
|
|
|
|
|
|
|
|
Vector3f size = objData.models[0].maxCorner - objData.models[0].minCorner;
|
|
|
|
float radius = myMax(size[0], myMax(size[1], size[2])) / 2;
|
|
|
|
|
|
|
|
mountainTransformation = Affine3f(Scaling(cameraDistance / radius * 0.25f)).matrix();
|
2018-10-29 08:01:19 +00:00
|
|
|
//mountainTransformation = Affine3f(Translation3f(0, -size[1] / 20 * cameraDistance / radius * 0.25f, 0)).matrix() * mountainTransformation;
|
2018-10-20 05:56:48 +00:00
|
|
|
//Matrix3f rotation(Quaternionf(0, 1 * sin(pi / 8 + pi / 2), 0, 1 * cos(pi / 8 + pi / 2)).toRotationMatrix());
|
|
|
|
//mountainTransformation = Affine3f(rotation).matrix() * mountainTransformation;
|
|
|
|
//mountainTransformation = Affine3f(Translation3f(0, 0, -size[2] / 2.f)).matrix() * mountainTransformation;
|
|
|
|
|
|
|
|
for (int i = 1; i <= 6; ++i)
|
|
|
|
{
|
|
|
|
objData = loadObjFile("ice/ice" + std::to_string(i) + ".obj", "");
|
|
|
|
ices[i - 1] = ObjDataToRenderPairs(objData)[0][0].second;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = objData.models[0].maxCorner - objData.models[0].minCorner;
|
|
|
|
Vector3f centerShift = -(objData.models[0].maxCorner + objData.models[0].minCorner) / 2;
|
|
|
|
radius = myMax(size[0], myMax(size[1], size[2])) / 2;
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
ResourceManager->TexList.AddTexture("ice/Textures/ice1.png");
|
|
|
|
ResourceManager->TexList.AddTexture("ice/Textures/ice2.png");
|
|
|
|
ResourceManager->TexList.AddTexture("ice/Textures/ice3.png");
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
std::shared_ptr<boost::property_tree::ptree> p = FileToPropertyTree("ices.json");
|
|
|
|
|
|
|
|
for (auto ice : p->get_child("ices"))
|
|
|
|
{
|
|
|
|
TRenderParams params;
|
|
|
|
|
|
|
|
Vector3f position = JSONVectorReader::readVector3f(ice.second.get_child("position"));
|
|
|
|
float scale = ice.second.get<float>("scale");
|
|
|
|
float angle = ice.second.get<float>("angle");
|
|
|
|
iceIndexes.push_back(ice.second.get<int>("type"));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
params.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "ice" + ice.second.get<std::string>("texture") + ".png";
|
|
|
|
|
|
|
|
iceParams.push_back(params);
|
|
|
|
|
|
|
|
Matrix4f iceTransformation = Affine3f(Translation3f(centerShift)).matrix();
|
|
|
|
iceTransformation = Affine3f(Scaling(cameraDistance / radius * 0.1f * scale)).matrix() * iceTransformation;
|
|
|
|
//Matrix3f rotation(Quaternionf(0, cos(angle*pi / 360.f), 0, sin(angle*pi / 360.f)).toRotationMatrix());
|
|
|
|
//iceTransformation = Affine3f(rotation).matrix() * iceTransformation;
|
|
|
|
iceTransformation = Affine3f(Translation3f(position)).matrix() * iceTransformation;
|
2018-10-29 08:01:19 +00:00
|
|
|
//iceTransformation = Affine3f(Translation3f(0, size[1] / 2, 0)).matrix() * iceTransformation;
|
2018-10-20 05:56:48 +00:00
|
|
|
|
|
|
|
iceTransformations.push_back(iceTransformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Serialize(*p);
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TAndroidApplication::AddFrameBuffers()
|
|
|
|
{
|
|
|
|
ResourceManager->FrameManager.AddFrameRenderBuffer("WaterFrame", 256, 256);
|
|
|
|
ResourceManager->FrameManager.AddFrameRenderBuffer("ScreenshotFrame", 512, 512);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAndroidApplication::DrawSceneWithoutWater(bool inv)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Renderer->PushProjectionMatrix(1,1);
|
2018-10-20 08:09:22 +00:00
|
|
|
Renderer->LoadIdentity();
|
|
|
|
//Renderer->PushSpecialMatrix(Matrix4f::Identity());
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 08:09:22 +00:00
|
|
|
if (inv)
|
2018-10-18 16:04:42 +00:00
|
|
|
{
|
2018-10-20 08:09:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (TimeOfDayPref == 2)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky_night.png"]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky.png"]);
|
|
|
|
}
|
|
|
|
Renderer->DrawRect(Vector2f(0.0f, 0.56f), Vector2f(1.f, 0.f), Vector2f(0.5f + SkyTexShift, 0.f), Vector2f(1.f + SkyTexShift, 1.f));
|
|
|
|
|
|
|
|
if (TimeOfDayPref == 1)
|
|
|
|
{
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["final_cloud.png"]);
|
|
|
|
Renderer->DrawRect(Vector2f(0.0f, 0.56f), Vector2f(4.f, 0.f), Vector2f(0.0f + SkyTexShift + CloudTimer, 0.f), Vector2f(1.f + SkyTexShift + CloudTimer, 0.5f));
|
|
|
|
}
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-20 08:09:22 +00:00
|
|
|
if (TimeOfDayPref == 2)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky_night.png"]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky.png"]);
|
|
|
|
}
|
|
|
|
Renderer->DrawRect(Vector2f(0.0f, 0.54f), Vector2f(1.f, 1.f), Vector2f(0.5f + SkyTexShift, 0.f), Vector2f(1.f + SkyTexShift, 1.f));
|
|
|
|
|
|
|
|
if (TimeOfDayPref == 1)
|
|
|
|
{
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["final_cloud.png"]);
|
|
|
|
Renderer->DrawRect(Vector2f(0.0f, 0.54f), Vector2f(4.f, 1.f), Vector2f(0.0f + SkyTexShift + CloudTimer, 0.f), Vector2f(1.f + SkyTexShift + CloudTimer, 0.5f));
|
|
|
|
}
|
2018-10-20 05:56:48 +00:00
|
|
|
}
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 08:09:22 +00:00
|
|
|
//if (TimeOfDayPref == 2)
|
|
|
|
//{
|
|
|
|
// glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky_night.png"]);
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky.png"]);
|
|
|
|
//}
|
2018-10-20 05:56:48 +00:00
|
|
|
|
2018-10-20 08:09:22 +00:00
|
|
|
//Renderer->DrawRect(Vector2f(0.0f, 0.56f), Vector2f(1.f, 0.f), Vector2f(0.5f + SkyTexShift, 0.f), Vector2f(1.f + SkyTexShift, 1.f));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 08:09:22 +00:00
|
|
|
//if (TimeOfDayPref == 1)
|
|
|
|
//{
|
|
|
|
// glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
// glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["final_cloud.png"]);
|
|
|
|
// Renderer->DrawRect(Vector2f(0.0f, 0.56f), Vector2f(4.f, 0.f), Vector2f(0.0f + SkyTexShift + CloudTimer, 0.f), Vector2f(1.f + SkyTexShift + CloudTimer, 0.5f));
|
|
|
|
//}
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
|
2018-10-20 08:09:22 +00:00
|
|
|
|
|
|
|
//Renderer->PopMatrix();
|
2018-10-18 16:04:42 +00:00
|
|
|
Renderer->PopProjectionMatrix();
|
|
|
|
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
Renderer->SetGLCamView();
|
|
|
|
|
|
|
|
if (inv)
|
|
|
|
{
|
2018-10-20 08:09:22 +00:00
|
|
|
//Renderer->PushMatrix();
|
2018-10-19 05:34:55 +00:00
|
|
|
Renderer->TranslateMatrix(Vector3f(0,0.1f,0));
|
|
|
|
Renderer->ScaleMatrix(Vector3f(1, -1, 1));
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Renderer->PushShader("SimplelightShader");
|
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
RenderUniform3fv("LightDirection", Vector3f(1, 1, 1).data());
|
|
|
|
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
Vector3f dayColor = Vector3f(0,0,0);
|
|
|
|
Vector3f nightColor = Vector3f(0, 0.1f, 0.2f);
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
if (TimeOfDayPref == 0)
|
|
|
|
{
|
2018-10-19 05:34:55 +00:00
|
|
|
RenderUniform3fv("TimeOfDayColor", dayColor.data());
|
2018-10-18 16:04:42 +00:00
|
|
|
RenderUniform1f("TimeOfDayCoef1", 0.75f);
|
|
|
|
RenderUniform1f("TimeOfDayCoef2", 0.25f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (TimeOfDayPref == 1)
|
|
|
|
{
|
2018-10-19 05:34:55 +00:00
|
|
|
RenderUniform3fv("TimeOfDayColor", dayColor.data());
|
2018-10-18 16:04:42 +00:00
|
|
|
RenderUniform1f("TimeOfDayCoef1", 0.5f);
|
|
|
|
RenderUniform1f("TimeOfDayCoef2", 0.25f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 05:34:55 +00:00
|
|
|
RenderUniform3fv("TimeOfDayColor", nightColor.data());
|
2018-10-18 16:04:42 +00:00
|
|
|
RenderUniform1f("TimeOfDayCoef1", 0.0f);
|
|
|
|
RenderUniform1f("TimeOfDayCoef2", 0.4f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
Renderer->PushPerspectiveProjectionMatrix(pi/6, Renderer->GetMatrixWidth() / Renderer->GetMatrixHeight(), 1.f, 450.f);
|
2018-10-20 08:09:22 +00:00
|
|
|
//Renderer->PushMatrix();
|
2018-10-20 05:56:48 +00:00
|
|
|
//mCamera.SetCamView();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
{
|
|
|
|
Renderer->PushMatrix();
|
|
|
|
Renderer->AddMatrix(mountainTransformation);
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
//RenderUniform4fv("light")
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
TRenderParamsSetter setter(mountain.first);
|
|
|
|
Renderer->DrawTriangleList(mountain.second);
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
Renderer->PopMatrix();
|
|
|
|
}
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < iceTransformations.size(); i++)
|
2018-10-18 16:04:42 +00:00
|
|
|
{
|
2018-10-20 05:56:48 +00:00
|
|
|
Renderer->PushMatrix();
|
|
|
|
Renderer->AddMatrix(iceTransformations[i]);
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
auto& renderPair = ices[iceIndexes[i] - 1];
|
|
|
|
TRenderParamsSetter setter(iceParams[i]);
|
|
|
|
Renderer->DrawTriangleList(ices[iceIndexes[i] - 1]);
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
Renderer->PopMatrix();
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
2018-10-20 05:56:48 +00:00
|
|
|
}
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 08:09:22 +00:00
|
|
|
//Renderer->PopMatrix();
|
|
|
|
Renderer->PopProjectionMatrix();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 08:09:22 +00:00
|
|
|
//if (inv)
|
|
|
|
//{
|
|
|
|
// Renderer->PopMatrix();
|
|
|
|
//}
|
2018-10-20 05:56:48 +00:00
|
|
|
|
|
|
|
Renderer->PopShader();
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TAndroidApplication::DrawSnow()
|
|
|
|
{
|
|
|
|
|
|
|
|
Renderer->PushProjectionMatrix(1,1);
|
|
|
|
|
|
|
|
Renderer->LoadIdentity();
|
|
|
|
|
|
|
|
const float multiply_x = 4;
|
|
|
|
const float multiply_y = 2;
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
Renderer->DrawRect(Vector2f(0, 0), Vector2f(1.f, 1.f), Vector2f(-SkyTexShift, SnowTimer), Vector2f(multiply_x - SkyTexShift, multiply_y + SnowTimer));
|
2018-10-18 16:04:42 +00:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
2018-10-19 05:34:55 +00:00
|
|
|
Renderer->DrawRect(Vector2f(0, 0), Vector2f(1.f, 1.f), Vector2f(SnowTimer*0.7f+0.3f - SkyTexShift, SnowTimer+0.7f), Vector2f(multiply_x - SkyTexShift + SnowTimer*0.7f+0.3f, multiply_y + SnowTimer+0.7f));
|
2018-10-18 16:04:42 +00:00
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
2018-10-19 05:34:55 +00:00
|
|
|
Renderer->DrawRect(Vector2f(0, 0), Vector2f(1.f, 1.f), Vector2f(SnowTimer*0.4f+0.7f - SkyTexShift, SnowTimer+0.3f), Vector2f(multiply_x - SkyTexShift + SnowTimer*0.4f+0.7f, multiply_y + SnowTimer+0.3f));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
Renderer->PopProjectionMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAndroidApplication::DrawAllScene(bool toScreen)
|
|
|
|
{
|
2018-10-20 05:56:48 +00:00
|
|
|
glClearColor(1.f, 0.f, 1.f, 1.0f);
|
2018-10-18 16:04:42 +00:00
|
|
|
//glClearColor(1.f, 1.f, 1.f, 1.0f);
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
Renderer->PushMatrix();
|
|
|
|
Renderer->SetGLCamView();
|
|
|
|
|
|
|
|
Renderer->PushShader("ClipShader");
|
|
|
|
|
|
|
|
|
|
|
|
Renderer->SwitchToFrameBuffer("WaterFrame");
|
|
|
|
Renderer->SetGLCamView();
|
2018-10-19 05:34:55 +00:00
|
|
|
Renderer->ScaleMatrix(Vector3f(1, -1, 1));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
DrawSceneWithoutWater(true);
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
Renderer->ScaleMatrix(Vector3f(1, -1, 1));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
if (toScreen)
|
|
|
|
{
|
|
|
|
Renderer->SwitchToScreen();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Renderer->SwitchToFrameBuffer("ScreenshotFrame");
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer->SetGLCamView();
|
|
|
|
|
|
|
|
Renderer->PushShader("NormShader");
|
|
|
|
RenderUniform1f("Time", WaterTimer);
|
|
|
|
if (Renderer->GetScreenWidth() < 600)
|
|
|
|
{
|
|
|
|
RenderUniform1f("WaterScale", 0.7f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RenderUniform1f("WaterScale", 1.f);
|
|
|
|
}
|
2018-10-29 08:01:19 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0); // THIS IS A NORMAL MAP (UNIFORM IS SETTED BY ENGINE IN Renderer->PushShader() -> SetUnifroms())
|
2018-10-18 16:04:42 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["water_nmap.png"]);
|
2018-10-29 08:01:19 +00:00
|
|
|
glActiveTexture(GL_TEXTURE1); // THIS IS A COLOR MAP (UNIFORM IS SETTED BY ENGINE IN Renderer->PushShader() -> SetUnifroms())
|
2018-10-18 16:04:42 +00:00
|
|
|
if (toScreen)
|
|
|
|
{
|
|
|
|
Renderer->SetFullScreenViewport();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Renderer->SetFrameViewport("ScreenshotFrame");
|
|
|
|
}
|
2018-10-29 08:01:19 +00:00
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
Renderer->DrawFramePartScreen("WaterFrame", Vector2f(0, 0), Vector2f(1.f, 0.54f));
|
2018-10-29 08:01:19 +00:00
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); // return back
|
|
|
|
|
2018-10-18 16:04:42 +00:00
|
|
|
Renderer->PopShader();
|
|
|
|
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
Renderer->SetGLCamView();
|
|
|
|
|
|
|
|
|
|
|
|
DrawSceneWithoutWater(false);
|
|
|
|
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["snow.png"]);
|
|
|
|
|
2018-10-29 08:01:19 +00:00
|
|
|
//if (SnowPref)
|
|
|
|
//{
|
|
|
|
// DrawSnow();
|
|
|
|
//}
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
Renderer->PopShader();
|
|
|
|
|
|
|
|
Renderer->PopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAndroidApplication::InnerInit()
|
|
|
|
{
|
|
|
|
m2.lock();
|
|
|
|
|
|
|
|
CheckGlError();
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
GetConsole() << "Inner init go!\n";
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
#ifdef TARGET_ANDROID
|
|
|
|
ResourceManager->PathToResources = "";
|
|
|
|
#endif
|
|
|
|
#ifdef TARGET_WIN32
|
2018-10-19 05:34:55 +00:00
|
|
|
ST::PathToResources = "../../assets/";
|
2018-10-18 16:04:42 +00:00
|
|
|
#endif
|
|
|
|
ResourceManager->ShaderManager.AddShader("DefaultShader", "gui_transparent.vertex", "gui_transparent.fragment");
|
|
|
|
Renderer->PushShader("DefaultShader");
|
|
|
|
|
|
|
|
LoadingQueue.push_back(boost::function<bool()>(boost::bind(&TShaderManager::AddShader, &(ResourceManager->ShaderManager), "ClipShader", "gui_transparent_clip.vertex", "gui_transparent_clip.fragment")));
|
|
|
|
LoadingQueue.push_back(boost::function<bool()>(boost::bind(&TShaderManager::AddShader, &(ResourceManager->ShaderManager), "NormShader", "test_norm.vertex", "test_norm.fragment")));
|
|
|
|
LoadingQueue.push_back(boost::function<bool()>(boost::bind(&TShaderManager::AddShader, &(ResourceManager->ShaderManager), "ParallaxShader", "test_parallax.vertex", "test_parallax.fragment")));
|
|
|
|
LoadingQueue.push_back(boost::function<bool()>(boost::bind(&TShaderManager::AddShader, &(ResourceManager->ShaderManager), "SimplelightShader", "test_simplelight.vertex", "test_simplelight.fragment")));
|
|
|
|
|
|
|
|
if (IsFileExistsInUserData("file.bmp"))
|
|
|
|
{
|
|
|
|
ResourceManager->TexList.AddTextureFromUserdata("file.bmp", "ScreenshotTexture");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ResourceManager->TexList.AddTexture("file.bmp", "ScreenshotTexture");
|
|
|
|
}
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
LoadingQueue.push_back(boost::function<size_t()>(boost::bind(&TTextureListClass::AddTexture, &(ResourceManager->TexList), "console_bkg.bmp", "")));
|
|
|
|
LoadingQueue.push_back(boost::function<size_t()>(boost::bind(&TTextureListClass::AddTexture, &(ResourceManager->TexList), "water_nmap.png", "")));
|
|
|
|
LoadingQueue.push_back(boost::function<size_t()>(boost::bind(&TTextureListClass::AddTexture, &(ResourceManager->TexList), "sky.png", "")));
|
|
|
|
LoadingQueue.push_back(boost::function<size_t()>(boost::bind(&TTextureListClass::AddTexture, &(ResourceManager->TexList), "sky_night.png", "")));
|
|
|
|
LoadingQueue.push_back(boost::function<size_t()>(boost::bind(&TTextureListClass::AddTexture, &(ResourceManager->TexList), "snow.png", "")));
|
|
|
|
LoadingQueue.push_back(boost::function<size_t()>(boost::bind(&TTextureListClass::AddTexture, &(ResourceManager->TexList), "final_cloud.png", "")));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
LoadingQueue.push_back(boost::function<void()>(boost::bind(&TAndroidApplication::LoadModels, this)));
|
|
|
|
LoadingQueue.push_back(boost::function<void()>(boost::bind(&TAndroidApplication::AddFrameBuffers, this)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//LoadModels();
|
|
|
|
|
|
|
|
CheckGlError();
|
|
|
|
|
2018-10-29 08:01:19 +00:00
|
|
|
boost::get<TPanoramicCamera>(Renderer->Camera).MovePhi(pi / 360.f * 5);
|
|
|
|
mCamera.MovePhi(pi / 360.f * 5);
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (Renderer->GetScreenWidth() > Renderer->GetScreenHeight())
|
|
|
|
{
|
2018-10-20 08:09:22 +00:00
|
|
|
boost::get<TPanoramicCamera>(Renderer->Camera).MoveDist(150.f);
|
2018-10-20 05:56:48 +00:00
|
|
|
mCamera.MoveDist(cameraDistance);
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2018-10-20 08:09:22 +00:00
|
|
|
boost::get<TPanoramicCamera>(Renderer->Camera).MoveDist(150.f);
|
2018-10-20 05:56:48 +00:00
|
|
|
mCamera.MoveDist(cameraDistance);
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::get<TPanoramicCamera>(Renderer->Camera).CalcCamVec();
|
2018-10-20 05:56:48 +00:00
|
|
|
mCamera.CalcCamVec();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
CheckGlError();
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
//ResourceManager->LightManager.SetLightOn();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
//ResourceManager->LightManager.SetLightDirection(Vector3f(1, -1, 0));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-29 08:01:19 +00:00
|
|
|
//AddFrameBuffers();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
//Renderer->SetPerspectiveFullScreenViewport();
|
|
|
|
|
|
|
|
if (Renderer->GetScreenWidth() < Renderer->GetScreenHeight())
|
|
|
|
{
|
|
|
|
Renderer->SetMatrixWidth(480);
|
|
|
|
Renderer->SetMatrixHeight(800);
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer->PushPerspectiveProjectionMatrix(pi/6, Renderer->GetMatrixWidth() / Renderer->GetMatrixHeight(), 1.f, 400.f);
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
GetConsole()<<"Inner init end!\n";
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
m2.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TAndroidApplication::InnerDeinit()
|
|
|
|
{
|
|
|
|
m2.lock();
|
2018-10-19 05:34:55 +00:00
|
|
|
|
2018-10-18 16:04:42 +00:00
|
|
|
Inited = false;
|
|
|
|
Loaded = false;
|
|
|
|
|
|
|
|
makeShot = true;
|
|
|
|
LoadingQueue.clear();
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
//if (LiteModel != NULL)
|
|
|
|
//{
|
|
|
|
// LiteModel->FreeModel();
|
|
|
|
// delete LiteModel;
|
|
|
|
// LiteModel = NULL;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//IceModel.clear();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
//SimpleLand = std::shared_ptr<TSimpleLandClass>();
|
|
|
|
//SimpleLandInv = std::shared_ptr<TSimpleLandClass>();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
m2.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TAndroidApplication::InnerDraw()
|
|
|
|
{
|
|
|
|
m2.lock();
|
|
|
|
if (!Loaded)
|
|
|
|
{
|
2018-10-20 05:56:48 +00:00
|
|
|
//glClearColor(0.f, 0.f, 0.f, 1.0f);
|
|
|
|
//glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
|
|
|
//glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["ScreenshotTexture"]);
|
|
|
|
//Renderer->PushProjectionMatrix(1,1);
|
|
|
|
//Renderer->LoadIdentity();
|
|
|
|
//Renderer->DrawRect(Vector2f(0, 0), Vector2f(1.f, 1.f));
|
|
|
|
//Renderer->PopProjectionMatrix();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
DrawAllScene(true);
|
|
|
|
|
|
|
|
if (makeShot)
|
|
|
|
{
|
2018-10-20 05:56:48 +00:00
|
|
|
//makeShot = false;
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
//Renderer->SwitchToFrameBuffer("ScreenshotFrame");
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
//DrawAllScene(false);
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
//ResourceManager->TexList.SaveTexDataToPlainBmpToUserData("file.bmp", ResourceManager->FrameManager.ReadFromBufferToTexData("ScreenshotFrame"));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
//Renderer->SwitchToScreen();
|
2018-10-18 16:04:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m2.unlock();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
void TAndroidApplication::InnerUpdate(size_t dt)
|
2018-10-18 16:04:42 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (!Loaded)
|
|
|
|
{
|
|
|
|
|
|
|
|
boost::apply_visitor( LoadingQueueVisitor(), *LoadingQueue.begin() );
|
|
|
|
LoadingQueue.erase(LoadingQueue.begin());
|
|
|
|
|
|
|
|
if (LoadingQueue.size() == 0)
|
|
|
|
{
|
|
|
|
Loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (WaveDir)
|
|
|
|
{
|
|
|
|
WaterTimer += dt/1000.f;
|
|
|
|
if (WaterTimer >= 10 * pi)
|
|
|
|
{
|
|
|
|
WaveDir = false;
|
|
|
|
WaterTimer = 10 * pi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WaterTimer -= dt/1000.f;
|
|
|
|
if (WaterTimer < 0)
|
|
|
|
{
|
|
|
|
WaveDir = true;
|
|
|
|
WaterTimer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloudTimer += dt / 60000.f;
|
|
|
|
|
|
|
|
while (CloudTimer >= 1.f)
|
|
|
|
{
|
|
|
|
CloudTimer -= 1.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SnowTimer += dt/3000.f;
|
|
|
|
|
|
|
|
while (SnowTimer > 10.f)
|
|
|
|
{
|
|
|
|
SnowTimer -= 10.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
void TAndroidApplication::InnerOnMove(Vector2f pos, Vector2f shift)
|
2018-10-18 16:04:42 +00:00
|
|
|
{
|
|
|
|
|
2018-10-19 05:34:55 +00:00
|
|
|
shift = Vector2f(shift[0]*Renderer->GetMatrixWidth()/static_cast<float>(Renderer->GetScreenWidth()), shift[1]*Renderer->GetMatrixHeight()/static_cast<float>(Renderer->GetScreenHeight()));
|
2018-10-18 16:04:42 +00:00
|
|
|
|
2018-10-20 05:56:48 +00:00
|
|
|
boost::get<TPanoramicCamera>(Renderer->Camera).MoveAlpha(-pi * shift[0] * 0.01f);
|
|
|
|
mCamera.MoveAlpha(-pi*shift[0]*0.01f);
|
2018-10-18 16:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TAndroidApplication::OnMouseDown(TMouseState& mouseState)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|