feat: add android support
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <glm/glm.hpp>
|
||||
#include <array>
|
||||
|
||||
#include "Mobs.h"
|
||||
#include "Team.h"
|
||||
|
||||
@@ -14,9 +14,9 @@ private:
|
||||
public:
|
||||
WorldClient(ClientGame* game);
|
||||
|
||||
virtual void HandlePacket(protocol::WorldBeginDataPacket* packet);
|
||||
virtual void HandlePacket(protocol::WorldDataPacket* packet);
|
||||
virtual void HandlePacket(protocol::SpawnMobPacket* packet);
|
||||
virtual void HandlePacket(protocol::WorldBeginDataPacket* packet) override;
|
||||
virtual void HandlePacket(protocol::WorldDataPacket* packet) override;
|
||||
virtual void HandlePacket(protocol::SpawnMobPacket* packet) override;
|
||||
|
||||
virtual void OnArrowShot(game::MobPtr target, game::Tower* shooter) override;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include "glbinding/gl/gl.h"
|
||||
using namespace gl;
|
||||
#endif
|
||||
@@ -10,10 +10,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace gl {
|
||||
enum class GLenum : unsigned int;
|
||||
}
|
||||
#include "render/GL.h"
|
||||
|
||||
class ShaderProgram {
|
||||
public:
|
||||
@@ -40,8 +37,8 @@ private:
|
||||
unsigned int programID;
|
||||
unsigned int vertexShaderID;
|
||||
unsigned int fragmentShaderID;
|
||||
int loadShaderFromFile(const std::string& file, gl::GLenum type);
|
||||
int loadShader(const std::string& source, gl::GLenum type);
|
||||
int loadShaderFromFile(const std::string& file, GLenum type);
|
||||
int loadShader(const std::string& source, GLenum type);
|
||||
};
|
||||
|
||||
#endif /* RENDER_SHADERS_SHADERPROGRAM_H_ */
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace td {
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* Author: simon
|
||||
*/
|
||||
|
||||
#ifndef ANDROID
|
||||
#include <glbinding/Binding.h>
|
||||
#endif
|
||||
#include "render/Renderer.h"
|
||||
#include "render/GL.h"
|
||||
#include <glbinding/Binding.h>
|
||||
#include <stdio.h>
|
||||
#include "misc/Time.h"
|
||||
#include "misc/Easing.h"
|
||||
|
||||
using namespace gl;
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
@@ -43,7 +43,9 @@ void Renderer::initShader() {
|
||||
}
|
||||
|
||||
bool Renderer::init() {
|
||||
#ifndef ANDROID
|
||||
glbinding::Binding::initialize();
|
||||
#endif
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
@@ -134,7 +134,7 @@ void WorldRenderer::renderPopups() const {
|
||||
break;
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip(game::getTowerInfo(towerType).getDescription().c_str());
|
||||
ImGui::SetTooltip(game::getTowerInfo(towerType).getDescription().c_str(), "%s");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ void renderMainMenu() {
|
||||
static std::string worldFilePath;
|
||||
|
||||
ImGui::InputInt("Server Port", &port, -1);
|
||||
ImGui::Text(std::string("Fichier de monde sélectionné : " + (worldFilePath.empty() ? std::string("Aucun") : worldFilePath)).c_str());
|
||||
ImGui::Text("%s", std::string("Fichier de monde sélectionné : " + (worldFilePath.empty() ? std::string("Aucun") : worldFilePath)).c_str());
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Ouvrir un fichier")) {
|
||||
ImGui::OpenPopup("WorldFileDialog");
|
||||
@@ -178,7 +178,7 @@ void showPlayers() {
|
||||
for (auto pair : client->getGame().getPlayers()) {
|
||||
const td::game::Player& player = pair.second;
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, getImGuiTeamColor(player.getTeamColor()));
|
||||
ImGui::Text(player.getName().c_str());
|
||||
ImGui::Text("%s", player.getName().c_str());
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
ImGui::TreePop();
|
||||
@@ -321,8 +321,16 @@ 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())
|
||||
|
||||
@@ -107,4 +107,8 @@ namespace ImGui
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef ANDROID
|
||||
#define IMGUI_IMPL_OPENGL_ES3
|
||||
#else
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
|
||||
#endif
|
||||
@@ -9,8 +9,6 @@
|
||||
#include "render/loader/GLLoader.h"
|
||||
#include "render/GL.h"
|
||||
|
||||
using namespace gl;
|
||||
|
||||
namespace GL {
|
||||
|
||||
VertexArray::~VertexArray() {
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "render/loader/stb_image.h"
|
||||
#include <iostream>
|
||||
#include <glbinding/gl/gl.h>
|
||||
|
||||
using namespace gl;
|
||||
#include "render/GL.h"
|
||||
|
||||
namespace TextureLoader {
|
||||
const unsigned int loadGLTexture(const char* fileName) {
|
||||
|
||||
@@ -7,14 +7,11 @@
|
||||
|
||||
#include "render/shaders/ShaderProgram.h"
|
||||
|
||||
#include <glbinding/gl/gl.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
using namespace gl;
|
||||
|
||||
ShaderProgram::ShaderProgram() :
|
||||
programID(0), vertexShaderID(0), fragmentShaderID(0) {
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <iostream>
|
||||
#include "game/GameManager.h"
|
||||
#include "imgui/imgui_impl_sdl.h"
|
||||
#include "render/Renderer.h"
|
||||
#include "render/WorldRenderer.h"
|
||||
#include "../render/gui/imgui/imgui.h"
|
||||
|
||||
#define WINDOW_NAME "Tower Defense"
|
||||
#define WINDOW_WIDTH 800
|
||||
@@ -138,7 +138,6 @@ void destroy() {
|
||||
void pollEvents() {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)){
|
||||
|
||||
if(event.type == SDL_WINDOWEVENT){
|
||||
switch(event.window.event){
|
||||
case SDL_WINDOWEVENT_CLOSE:{
|
||||
@@ -155,7 +154,6 @@ void pollEvents() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
add_rules("mode.debug", "mode.release")
|
||||
|
||||
--add_requires("glbinding", "glfw", "zlib", "glm")
|
||||
--add_requires("SDL2", "glfw", "zlib", "glm")
|
||||
|
||||
target("Tower Defense")
|
||||
target("TowerDefense")
|
||||
set_kind("binary")
|
||||
add_includedirs("include", "src/render/gui")
|
||||
add_files("src/*.cpp", "src/*/*.cpp", "src/*/*/*.cpp", "src/*/*/*/*.cpp")
|
||||
|
||||
Reference in New Issue
Block a user