fix: android comptatibility
This commit is contained in:
@@ -38,8 +38,7 @@ void init(SDL_Window* sdl_window, SDL_GLContext sdlContext, td::render::Renderer
|
||||
ImGui::CreateContext();
|
||||
ImGui::StyleColorsDark();
|
||||
ImGui_ImplSDL2_InitForOpenGL(sdl_window, gl_context);
|
||||
const char* glslVersion = "#version 130";
|
||||
ImGui_ImplOpenGL3_Init(glslVersion);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
ImFontConfig c;
|
||||
c.SizePixels = 25;
|
||||
ImGui::GetIO().Fonts->AddFontDefault(&c);
|
||||
@@ -320,17 +319,8 @@ void tick() {
|
||||
|
||||
lastTime = td::utils::getTime();
|
||||
}
|
||||
|
||||
void pollEvents(){
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)){
|
||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void render() {
|
||||
tick();
|
||||
pollEvents();
|
||||
beginFrame();
|
||||
client->render();
|
||||
if (client->isConnected())
|
||||
|
||||
@@ -7,15 +7,18 @@
|
||||
|
||||
#include "render/shaders/EntityShader.h"
|
||||
|
||||
static const char vertexSource[] = R"(
|
||||
#version 330
|
||||
#ifdef ANDROID
|
||||
static const char vertexSource[] =
|
||||
R"(#version 300 es
|
||||
|
||||
in vec2 position;
|
||||
in int color;
|
||||
precision mediump float;
|
||||
|
||||
uniform vec2 camPos = vec2(0, 0);
|
||||
uniform float zoom = 1;
|
||||
uniform float aspectRatio = 0;
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 1) in int color;
|
||||
|
||||
uniform vec2 camPos;
|
||||
uniform float zoom;
|
||||
uniform float aspectRatio;
|
||||
uniform vec2 translation;
|
||||
uniform float isometricView;
|
||||
|
||||
@@ -25,7 +28,51 @@ void main(void){
|
||||
float modelX = position.x + translation.x;
|
||||
float modelY = position.y + translation.y;
|
||||
float x = (modelX - camPos.x - (modelY - camPos.y) * isometricView) / aspectRatio * zoom;
|
||||
float y = ((0.5 * (modelX - camPos.x) + 0.5 * (modelY - camPos.y)) * isometricView + (modelY - camPos.y) * (1 - isometricView)) * zoom;
|
||||
float y = ((0.5 * (modelX - camPos.x) + 0.5 * (modelY - camPos.y)) * isometricView + (modelY - camPos.y) * (1.0 - isometricView)) * zoom;
|
||||
pass_color = color;
|
||||
gl_Position = vec4(x, -y, 0.0, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
static const char fragmentSource[] =
|
||||
R"(#version 300 es
|
||||
|
||||
precision mediump float;
|
||||
|
||||
flat in int pass_color;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
|
||||
float r = float(pass_color >> 24 & 0xFF) / 255.0;
|
||||
float g = float(pass_color >> 16 & 0xFF) / 255.0;
|
||||
float b = float(pass_color >> 8 & 0xFF) / 255.0;
|
||||
float a = float(pass_color & 0xFF) / 255.0;
|
||||
out_color = vec4(r, g, b, a);
|
||||
|
||||
}
|
||||
)";
|
||||
#else
|
||||
static const char vertexSource[] = R"(
|
||||
#version 330
|
||||
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 1) in int color;
|
||||
|
||||
uniform vec2 camPos;
|
||||
uniform float zoom;
|
||||
uniform float aspectRatio;
|
||||
uniform vec2 translation;
|
||||
uniform float isometricView;
|
||||
|
||||
flat out int pass_color;
|
||||
|
||||
void main(void){
|
||||
float modelX = position.x + translation.x;
|
||||
float modelY = position.y + translation.y;
|
||||
float x = (modelX - camPos.x - (modelY - camPos.y) * isometricView) / aspectRatio * zoom;
|
||||
float y = ((0.5 * (modelX - camPos.x) + 0.5 * (modelY - camPos.y)) * isometricView + (modelY - camPos.y) * (1.0 - isometricView)) * zoom;
|
||||
pass_color = color;
|
||||
gl_Position = vec4(x, -y, 0.0, 1.0);
|
||||
}
|
||||
@@ -48,6 +95,7 @@ void main(void){
|
||||
|
||||
}
|
||||
)";
|
||||
#endif
|
||||
|
||||
EntityShader::EntityShader() : ShaderProgram() {}
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
ShaderProgram::ShaderProgram() :
|
||||
programID(0), vertexShaderID(0), fragmentShaderID(0) {
|
||||
}
|
||||
@@ -112,6 +116,9 @@ int ShaderProgram::loadShader(const std::string& source, GLenum type) {
|
||||
char error[size];
|
||||
glGetShaderInfoLog(shaderID, size, &size, error);
|
||||
std::cout << error << std::endl;
|
||||
#ifdef ANDROID
|
||||
__android_log_print(ANDROID_LOG_ERROR, "TRACKERS", "Could not compile shader !\n %s", error);
|
||||
#endif
|
||||
}
|
||||
return shaderID;
|
||||
}
|
||||
|
||||
@@ -7,22 +7,66 @@
|
||||
|
||||
#include "render/shaders/WorldShader.h"
|
||||
|
||||
static const char vertexSource[] = R"(
|
||||
#version 330
|
||||
#ifdef ANDROID
|
||||
static const char vertexSource[] =
|
||||
R"(#version 300 es
|
||||
|
||||
precision mediump float;
|
||||
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 1) in int color;
|
||||
|
||||
uniform vec2 camPos = vec2(0, 0);
|
||||
uniform float zoom = 1;
|
||||
uniform float aspectRatio = 0;
|
||||
uniform vec2 camPos;
|
||||
uniform float zoom;
|
||||
uniform float aspectRatio;
|
||||
uniform float isometricView;
|
||||
|
||||
flat out int pass_color;
|
||||
|
||||
void main(void){
|
||||
float x = (position.x - camPos.x - (position.y - camPos.y) * isometricView) / aspectRatio * zoom;
|
||||
float y = ((0.5 * (position.x - camPos.x) + 0.5 * (position.y - camPos.y)) * isometricView + (position.y - camPos.y) * (1 - isometricView)) * zoom;
|
||||
float y = ((0.5 * (position.x - camPos.x) + 0.5 * (position.y - camPos.y)) * isometricView + (position.y - camPos.y) * (1.0 - isometricView)) * zoom;
|
||||
pass_color = color;
|
||||
gl_Position = vec4(x, -y, 0.0, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
static const char fragmentSource[] =
|
||||
R"(#version 300 es
|
||||
|
||||
precision mediump float;
|
||||
|
||||
flat in int pass_color;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
|
||||
float r = float(pass_color >> 24 & 0xFF) / 255.0;
|
||||
float g = float(pass_color >> 16 & 0xFF) / 255.0;
|
||||
float b = float(pass_color >> 8 & 0xFF) / 255.0;
|
||||
float a = float(pass_color & 0xFF) / 255.0;
|
||||
out_color = vec4(r, g, b, a);
|
||||
|
||||
}
|
||||
)";
|
||||
#else
|
||||
static const char vertexSource[] = R"(
|
||||
#version 330
|
||||
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 1) in int color;
|
||||
|
||||
uniform vec2 camPos;
|
||||
uniform float zoom;
|
||||
uniform float aspectRatio;
|
||||
uniform float isometricView;
|
||||
|
||||
flat out int pass_color;
|
||||
|
||||
void main(void){
|
||||
float x = (position.x - camPos.x - (position.y - camPos.y) * isometricView) / aspectRatio * zoom;
|
||||
float y = ((0.5 * (position.x - camPos.x) + 0.5 * (position.y - camPos.y)) * isometricView + (position.y - camPos.y) * (1.0 - isometricView)) * zoom;
|
||||
pass_color = color;
|
||||
gl_Position = vec4(x, -y, 0.0, 1.0);
|
||||
}
|
||||
@@ -45,6 +89,7 @@ void main(void){
|
||||
|
||||
}
|
||||
)";
|
||||
#endif
|
||||
|
||||
WorldShader::WorldShader() : ShaderProgram() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user