fix: android comptatibility
This commit is contained in:
@@ -14,12 +14,19 @@
|
||||
#include "game/GameManager.h"
|
||||
#include "render/Renderer.h"
|
||||
#include "render/WorldRenderer.h"
|
||||
#include "../render/gui/imgui/imgui.h"
|
||||
#include "../render/gui/imgui/imgui_impl_sdl.h"
|
||||
|
||||
#define WINDOW_NAME "Tower Defense"
|
||||
#define WINDOW_WIDTH 800
|
||||
#define WINDOW_HEIGHT 600
|
||||
|
||||
#include <SDL2/SDL_render.h>
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <sstream>
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
namespace Display {
|
||||
|
||||
static SDL_Window* window;
|
||||
@@ -32,10 +39,6 @@ static float aspectRatio;
|
||||
|
||||
static bool shouldClose = false;
|
||||
|
||||
void error_callback(int error, const char* description) {
|
||||
std::cerr << "GLFW Error : " << description << std::endl;
|
||||
}
|
||||
|
||||
void windowResizeEvent(int width, int height) {
|
||||
aspectRatio = (float)width / height;
|
||||
renderer->resize(width, height);
|
||||
@@ -46,14 +49,14 @@ void windowResizeEvent(int width, int height) {
|
||||
bool create() {
|
||||
window = SDL_CreateWindow(WINDOW_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
// Prepare and create context
|
||||
#ifdef __ANDROID__
|
||||
#ifdef ANDROID
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
#else
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
#endif
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
|
||||
@@ -100,16 +103,7 @@ bool create() {
|
||||
<< ", R" << r << "G" << g << "B" << b << "A" << a << ", depth bits: " << depth << std::endl;
|
||||
|
||||
SDL_GL_MakeCurrent(window, glContext);
|
||||
/*Log(LOG_INFO) << "Finished initialization";
|
||||
return ctx;
|
||||
glfwSetErrorCallback(&error_callback);
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_NAME, nullptr, nullptr);
|
||||
glfwMakeContextCurrent(window);*/
|
||||
|
||||
if (!renderer->init()) {
|
||||
exit(1);
|
||||
}
|
||||
@@ -132,6 +126,7 @@ void destroy() {
|
||||
TowerGui::destroy();
|
||||
SDL_GL_DeleteContext(glContext);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
window = NULL;
|
||||
}
|
||||
|
||||
@@ -154,6 +149,7 @@ void pollEvents() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user