diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index fd926db..90e3d0d 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -27,7 +27,7 @@ #define THREADS_UPDATE_CHUNKS 6 #define THREADS_DELETE_CHUNKS 3 -#define VIEW_DISTANCE 512 // Si les chunks arrêtent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre. +#define VIEW_DISTANCE 512 // Si les chunks arr�tent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre. #define TEXTURE_SIZE 512 #define MAX_BULLETS 512 @@ -41,6 +41,8 @@ typedef uint8_t BlockType; typedef uint8_t BoostType; enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST }; enum BOOST_TYPE { BTYPE_SPEED, BTYPE_HEAL, BTYPE_DAMAGE, BTYPE_INVINCIBLE, BTYPE_BOOST_LAST }; +enum ANIM_TYPE { STILL = 0, SHOOTING = 8, JUMPING = 16, JUMPINGSHOOTING = 24, DEAD = 32, TYPE_LAST = 40}; +enum ANIM_POS {FRONT, QUARTER_FRONT_LEFT, QUATER_FRONT_RIGHT, PROFIL_LEFT, PROFIL_RIGHT, QUARTER_BACK_LEFT, QUARTER_BACK_RIGHT, BACK , POS_LAST}; typedef uint64_t Timestamp; #ifdef _WIN32 diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index 4d67655..e268b20 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -28,7 +28,8 @@ #define BASE_WIDTH 640 #define BASE_HEIGHT 480 - +#define ANIME_PATH_JUMP "./media/textures/AssetOtherPlayer/FinalPNGJumping/" +#define ANIME_PATH_STILL "./media/textures/AssetOtherPlayer/FinalPNGStanding/" #define TEXTURE_PATH "./media/textures/" #define SHADER_PATH "./media/shaders/" #define AUDIO_PATH "./media/audio/" diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 9c8b201..ec3d73c 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1,5 +1,7 @@ #include "engine.h" - +#include +#include +#include #include #include #include @@ -453,6 +455,37 @@ void Engine::LoadResource() { TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); + + //AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM + + //JUMP + //TextureAtlas::TextureIndex JumpBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackJumpRight.png"); + //TextureAtlas::TextureIndex JumpFront = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueFrontJumpRight.png"); + //TextureAtlas::TextureIndex JumpQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftBackJumpLeft.png"); + //TextureAtlas::TextureIndex JumpQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBackJumpRight.png"); + //TextureAtlas::TextureIndex JumpProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpLeft.png"); + //TextureAtlas::TextureIndex JumpProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpRight.png"); + //TextureAtlas::TextureIndex JumpQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftFrontJumpLeft.png"); + //TextureAtlas::TextureIndex JumpQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightFrontJumpRight.png"); + + //STILL + //TextureAtlas::TextureIndex StillBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackRight.png"); + TextureAtlas::TextureIndex StillFront = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueFrontRight.png"); + //TextureAtlas::TextureIndex StillQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftBack.png"); + //TextureAtlas::TextureIndex StillQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBack.png"); + //TextureAtlas::TextureIndex StillProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilLeft.png"); + //TextureAtlas::TextureIndex StillProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilRight.png"); + //TextureAtlas::TextureIndex StillQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeft.png"); + //TextureAtlas::TextureIndex StillQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRight.png"); + + //SHOOTINGSTILL + //SHOOTINGJUMP + + if (!m_animeAtlas.Generate(TEXTURE_SIZE, false)) { + std::cout << " Unable to generate texture atlas ..." << std::endl; + abort(); + } + if (!m_textureAtlas.Generate(TEXTURE_SIZE, false)) { std::cout << " Unable to generate texture atlas ..." << std::endl; abort(); @@ -477,6 +510,9 @@ void Engine::LoadResource() { m_boostinfo[BTYPE_INVINCIBLE] = new BoostInfo(BTYPE_INVINCIBLE, "Inv", u, v, s, 1); + + m_animeAtlas.TextureIndexToCoord(0, u, v, s, s); + std::cout << " Loading and compiling shaders ..." << std::endl; if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) { std::cout << " Failed to load shader " << std::endl; @@ -1158,7 +1194,6 @@ void Engine::Render(float elapsedTime) { //m_remotePlayer.ApplyTransformation(remotePlayer, false); m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo); m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); - glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime); m_booster.RenderBillboard({ 120,20,120 }, m_textureAtlas, texBoostHeal, m_shader01, all); @@ -1168,12 +1203,12 @@ void Engine::Render(float elapsedTime) { //m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime); - //if (m_isSkybox) m_skybox.Render(skybox); + if (m_isSkybox) m_skybox.Render(skybox); - if (m_isSkybox) DrawHud(elapsedTime, bloc); - if (m_isSkybox) DisplayPovGun(); + DrawHud(elapsedTime, bloc); + DisplayPovGun(); ProcessNotificationQueue(); if (m_damage) { diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index f5754aa..712cd91 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -72,6 +72,7 @@ private: BlockInfo* m_blockinfo[BTYPE_LAST]; BoostInfo* m_boostinfo[BTYPE_BOOST_LAST]; TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); + TextureAtlas m_animeAtlas = TextureAtlas(TYPE_LAST + POS_LAST); World m_world = World(); Renderer m_renderer = Renderer(); diff --git a/SQCSim2021/media/shaders/shader01.frag b/SQCSim2021/media/shaders/shader01.frag index 8adf697..99b1d70 100644 --- a/SQCSim2021/media/shaders/shader01.frag +++ b/SQCSim2021/media/shaders/shader01.frag @@ -7,7 +7,7 @@ void main() texel = texture2D(tex,gl_TexCoord[0].st); texel *= light; - texel.a = 255.; + gl_FragColor = texel; } diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpLeft.png deleted file mode 100644 index d0dd74f..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpLeft.png and /dev/null differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpLeft.png deleted file mode 100644 index 08420cf..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpLeft.png and /dev/null differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackLeft.png deleted file mode 100644 index c743dec..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackLeft.png and /dev/null differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontLeft.png deleted file mode 100644 index a3f15f1..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontLeft.png and /dev/null differ diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index d8cbdec..c2247ba 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -79,19 +79,13 @@ void RemotePlayer::Feed(const netprot::Output out) { void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime) { - // - //Vector3f playerToQuad = m_player.GetPosition() - m_position; - //playerToQuad.Normalize(); - //Vector3f targetPosition = m_player.GetPosition() + playerToQuad * 10.0f; - //Matrix4f rotationMatrix; - //rotationMatrix.SetLookAt(m_position, targetPosition, Vector3f(0, 1, 0)); - //glMultMatrixf(rotationMatrix.GetInternalValues()); + float x = GetPosition().x; float y = GetPosition().y; float z = GetPosition().z; - float width = 1.7f; - float height = 2.5f; - //Pt override les collisions.. a ce point la je sais pas quoi faire + float width = 1.f; + float height = 1.7f; + //Matrix4 mat4 = tran.GetMatrix(); //mat4 VP = pMatrix * vMatrix; @@ -111,6 +105,10 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr atlas.TextureIndexToCoord(0, u, v, w, h); //glLoadIdentity(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + glLoadMatrixf(tran.GetMatrix().GetInternalValues()); glBegin(GL_QUADS); glTexCoord2f(u, v); glVertex3f(x - width/2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0); @@ -118,6 +116,12 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr glTexCoord2f(u + w, v + h); glVertex3f(x+width/2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0); glTexCoord2f(u, v + h); glVertex3f(x-width/2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0); glEnd(); + + + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); + glDisable(GL_BLEND); + shader.Disable(); //tran.ApplyTranslation(-m_position); //glEnable(GL_DEPTH_TEST); diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h index 36eb275..e782000 100644 --- a/SQCSim2021/remoteplayer.h +++ b/SQCSim2021/remoteplayer.h @@ -12,7 +12,7 @@ class RemotePlayer : public Player { public: - enum Anim: uint8_t { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 }; + enum Anim: uint8_t { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 }; // A REVOIR VOIR DEFINE.H POUR LES ANIMES RemotePlayer(netprot::PlayerInfo pinfo); RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos); diff --git a/SQCSim2021/textureatlas.cpp b/SQCSim2021/textureatlas.cpp index d293c84..ccefd2c 100644 --- a/SQCSim2021/textureatlas.cpp +++ b/SQCSim2021/textureatlas.cpp @@ -40,6 +40,9 @@ TextureAtlas::TextureIndex TextureAtlas::AddTexture(const std::string& fname) { } bool TextureAtlas::Generate(int textureSize, bool mipmap) { + + + // TODO mipmap pas encore 100% parfait... assert(!mipmap); @@ -66,6 +69,8 @@ bool TextureAtlas::Generate(int textureSize, bool mipmap) { ilOriginFunc(IL_ORIGIN_LOWER_LEFT); ilEnable(IL_ORIGIN_SET); + ilEnable(IL_ALPHA); + ilEnable(IL_BLIT_BLEND); if (!ilLoadImage((const ILstring)it->first.c_str())) return false; @@ -170,8 +175,10 @@ bool TextureAtlas::Generate(int textureSize, bool mipmap) { mipmapSize /= 2; } + m_isValid = true; return true; + }