diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 405ab0f..4e7b0b0 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -45,13 +45,6 @@ enum ANIM_TYPE { STILL = 0, SHOOTING = 8, JUMPING = 16, JUMPINGSHOOTING = 24, DE 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; -enum Resolution { - HD = 0, // 1280x720 (High Definition) - FHD, // 1920x1080 (Full HD) - QHD, // 2560x1440 (Quad HD) - UHD // 3840x2160 (Ultra HD) -}; - #ifdef _WIN32 #pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index e268b20..28168bb 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -37,4 +37,11 @@ #define MENU_ITEM_PATH "./media/menu_items/" #define BOOSTER_TEXTURE_PATH "./media/textures/Booster/" +enum Resolution { + HD = 0, // 1280x720 (High Definition) + FHD, // 1920x1080 (Full HD) + QHD, // 2560x1440 (Quad HD) + UHD // 3840x2160 (Ultra HD) +}; + #endif // DEFINE_H__ diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 4f61b3e..de7b994 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -13,7 +13,6 @@ struct Notification { float displayStartTime = 0.0f; }; - // Use a queue to manage notifications //std::queue notificationQueue; // Use a vector to manage notifications @@ -29,6 +28,234 @@ Engine::~Engine() { m_world.GetChunks().Get(x, y)->~Chunk(); } +void Engine::Init() { + + GLenum glewErr = glewInit(); + if (glewErr != GLEW_OK) { + std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl; + abort(); + } + + uint64_t seed = SEED; + + glDisable(GL_FRAMEBUFFER_SRGB); + glEnable(GL_DEPTH_TEST); + glEnable(GL_STENCIL_TEST); + glEnable(GL_POINT_SMOOTH); + glEnable(GL_BLEND); + //glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE); + glShadeModel(GL_SMOOTH); + + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glDisable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_SUBTRACT); + + if (m_istarted) + return; + else m_istarted = true; + + // Objet de skybox avec sa propre texture et son propre shader! + m_skybox.Init(0.2f); + // Objet de musique! + //m_audio.ToggleMusicState(); + + // Array pour les balles. + for (int x = 0; x < MAX_BULLETS; ++x) { + m_bullets[x] = nullptr; + m_whoosh[x] = nullptr; + } + + char* ch = new char[2]; + + std::cout << "Jouer en ligne? [o/N] "; + std::cin.getline(ch, 2); + std::cout << std::endl; + + if (*ch == 'o' || *ch == 'O') { + char* input = new char[32]; + std::string playname, srvname; + + while (playname.size() < 1) { + std::cout << "Veuillez entrer un nom de joueur: "; + std::cin.getline(input, 32); + std::cout << std::endl; + playname = input; + if (playname.size() < 1 || playname.size() > 32) + std::puts("Nom invalide."); + } + while (srvname.size() < 1) { + std::cout << "Veuillez entrer une adresse de serveur: "; + std::cin.getline(input, 32); + std::cout << std::endl; + srvname = input; + if (srvname.size() < 1 || srvname.size() > 32) + std::puts("Adresse serveur invalide."); + } + delete[] input; + + if (!m_conn.Init()) { + if (!m_conn.Connect(srvname.c_str(), playname)) { + // setup jeu en reseau. + std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl; + std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl; + m_player = Player(m_conn.getOrigin().position); + + for (auto& [key, player] : m_conn.m_players) + m_players[key] = new RemotePlayer(player); + + seed = m_conn.getSeed(); + m_networkgame = true; + } + else std::cout << "Erreur de connexion." << std::endl; + } + else std::cout << "Erreur de creation de socket." << std::endl; + } + delete[] ch; + + m_world.SetSeed(seed); + + // Init Chunks + m_world.GetChunks().Reset(nullptr); + + m_startTime = std::chrono::high_resolution_clock::now(); + + m_remotePlayer.SetPosition(Vector3f(.5, CHUNK_SIZE_Y + 10., .5)); + // Gestion de souris. + CenterMouse(); + HideCursor(); +} + +void Engine::DeInit() {} + +void Engine::LoadResource() { + LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true); + //LoadTexture(m_skybox2.GetTexture(), TEXTURE_PATH "skybox.png", true); + LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true); + LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true); + LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false); + LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false); + LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false); + LoadTexture(m_textureSoloText, TEXTURE_PATH "single_player.png", false); + LoadTexture(m_textureMultiText, TEXTURE_PATH "multi_player.png", false); + LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false); + LoadTexture(m_textureTitle, TEXTURE_PATH "title.png", false); + LoadTexture(m_textureOptions, TEXTURE_PATH "Buttons/options.png", false); + LoadTexture(m_textureVolume, TEXTURE_PATH "Buttons/volume.png", false); + LoadTexture(m_textureMusique, TEXTURE_PATH "Buttons/musique.png", false); + LoadTexture(m_textureGraphiques, TEXTURE_PATH "Buttons/graphiques.png", false); + LoadTexture(m_textureSensibilite, TEXTURE_PATH "Buttons/sensibilite.png", false); + LoadTexture(m_textureResolution, TEXTURE_PATH "Buttons/resolution.png", false); + LoadTexture(m_texturePrincipal, TEXTURE_PATH "Buttons/principal.png", false); + LoadTexture(m_textureEffets, TEXTURE_PATH "Buttons/effets.png", false); + LoadTexture(m_textureGameplay, TEXTURE_PATH "Buttons/gameplay.png", false); + LoadTexture(m_textureHd, TEXTURE_PATH "Buttons/hd.png", false); + LoadTexture(m_textureFhd, TEXTURE_PATH "Buttons/fhd.png", false); + LoadTexture(m_textureQhd, TEXTURE_PATH "Buttons/qhd.png", false); + LoadTexture(m_textureUhd, TEXTURE_PATH "Buttons/uhd.png", false); + LoadTexture(m_textureCheck, TEXTURE_PATH "Buttons/check.png", false); + LoadTexture(m_textureChecked, TEXTURE_PATH "Buttons/checked.png", false); + + + // Pourquoi on load 3 fois la meme texture? + LoadTexture(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); + LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); + LoadTexture(MenuBGOptionTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); + LoadTexture(MenuBGFlouTexture, TEXTURE_PATH "BackgroundMenuFlou.png"); + + LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png"); + LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png"); + LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png"); + LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png"); + + TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); + TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); + TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); + TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); + TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png"); + TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); + TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); + 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(); + } + + float u, v, s; + m_textureAtlas.TextureIndexToCoord(texDirtIndex, u, v, s, s); + m_blockinfo[BTYPE_DIRT] = new BlockInfo(BTYPE_DIRT, "Dirt", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texGrassIndex, u, v, s, s); + m_blockinfo[BTYPE_GRASS] = new BlockInfo(BTYPE_GRASS, "Grass", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texMetalIndex, u, v, s, s); + m_blockinfo[BTYPE_METAL] = new BlockInfo(BTYPE_METAL, "Metal", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); + m_blockinfo[BTYPE_ICE] = new BlockInfo(BTYPE_ICE, "Ice", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texGreenGrassIndex, u, v, s, s); + m_blockinfo[BTYPE_GREENGRASS] = new BlockInfo(BTYPE_GREENGRASS, "GreenGrass", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texBoostHeal, u, v, s, s); + m_boostinfo[BTYPE_HEAL] = new BoostInfo(BTYPE_HEAL, "Heal", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texBoostDmg, u, v, s, s); + m_boostinfo[BTYPE_DAMAGE] = new BoostInfo(BTYPE_DAMAGE, "Dmg", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texBoostSpd, u, v, s, s); + m_boostinfo[BTYPE_SPEED] = new BoostInfo(BTYPE_SPEED, "Spd", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); + 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; + exit(1); + } + + if (!m_skybox.GetShader().Load(SHADER_PATH "skybox.vert", SHADER_PATH "skybox.frag", true)) { + std::cout << " Failed to load shader " << std::endl; + exit(1); + } +} + +void Engine::UnloadResource() {} + void Engine::DrawSplachScreen() { glDisable(GL_LIGHTING); @@ -79,8 +306,6 @@ void Engine::DrawSplachScreen() m_gamestate = GameState::MAIN_MENU; } - - void Engine::DrawMenu() { static const int sTitle = 400; @@ -351,6 +576,13 @@ void Engine::DrawOption() glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + if (m_selectedOption == 0) { + DisplayAudioMenu(centerX, centerY); + } + else if (m_selectedOption == 1) { + DisplayGraphicsMenu(centerX, centerY); + } + glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); glEnable(GL_STENCIL_TEST); @@ -363,229 +595,134 @@ void Engine::DrawOption() glPopMatrix(); } -void Engine::Init() { +void Engine::DisplayAudioMenu(float centerX, float centerY) { + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_texturePrincipal.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.025, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.025, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); - GLenum glewErr = glewInit(); - if (glewErr != GLEW_OK) { - std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl; - abort(); - } + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.165); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.3, centerY + Height() * 0.165); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.3, centerY + Height() * 0.2); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.2); + glEnd(); - uint64_t seed = SEED; + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureMusique.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.09); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.05, centerY + Height() * 0.09); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.05, centerY + Height() * 0.125); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.125); + glEnd(); - glDisable(GL_FRAMEBUFFER_SRGB); - glEnable(GL_DEPTH_TEST); - glEnable(GL_STENCIL_TEST); - glEnable(GL_POINT_SMOOTH); - glEnable(GL_BLEND); - //glEnable(GL_CULL_FACE); - glEnable(GL_TEXTURE_2D); + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.04); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.3, centerY + Height() * 0.04); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.3, centerY + Height() * 0.075); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.075); + glEnd(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureEffets.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.035); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.035); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.00001); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.00001); + glEnd(); - gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE); - glShadeModel(GL_SMOOTH); + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.085); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.3, centerY - Height() * 0.085); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.3, centerY - Height() * 0.05); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.05); + glEnd(); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glDisable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_SUBTRACT); - - if (m_istarted) - return; - else m_istarted = true; - - // Objet de skybox avec sa propre texture et son propre shader! - m_skybox.Init(0.2f); - // Objet de musique! - //m_audio.ToggleMusicState(); - - // Array pour les balles. - for (int x = 0; x < MAX_BULLETS; ++x) { - m_bullets[x] = nullptr; - m_whoosh[x] = nullptr; - } - - char* ch = new char[2]; - - std::cout << "Jouer en ligne? [o/N] "; - std::cin.getline(ch, 2); - std::cout << std::endl; - - if (*ch == 'o' || *ch == 'O') { - char* input = new char[32]; - std::string playname, srvname; - - while (playname.size() < 1) { - std::cout << "Veuillez entrer un nom de joueur: "; - std::cin.getline(input, 32); - std::cout << std::endl; - playname = input; - if (playname.size() < 1 || playname.size() > 32) - std::puts("Nom invalide."); - } - while (srvname.size() < 1) { - std::cout << "Veuillez entrer une adresse de serveur: "; - std::cin.getline(input, 32); - std::cout << std::endl; - srvname = input; - if (srvname.size() < 1 || srvname.size() > 32) - std::puts("Adresse serveur invalide."); - } - delete[] input; - - if (!m_conn.Init()) { - if (!m_conn.Connect(srvname.c_str(), playname)) { - // setup jeu en reseau. - std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl; - std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl; - m_player = Player(m_conn.getOrigin().position); - - for (auto& [key, player] : m_conn.m_players) - m_players[key] = new RemotePlayer(player); - - seed = m_conn.getSeed(); - m_networkgame = true; - } - else std::cout << "Erreur de connexion." << std::endl; - } - else std::cout << "Erreur de creation de socket." << std::endl; - } - delete[] ch; - - m_world.SetSeed(seed); - - // Init Chunks - m_world.GetChunks().Reset(nullptr); - - m_startTime = std::chrono::high_resolution_clock::now(); - - m_remotePlayer.SetPosition(Vector3f(.5,CHUNK_SIZE_Y + 10., .5)); - // Gestion de souris. - CenterMouse(); - HideCursor(); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } -void Engine::DeInit() {} +void Engine::DisplayGraphicsMenu(float centerX, float centerY) { + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureResolution.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); -void Engine::LoadResource() { - LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true); - //LoadTexture(m_skybox2.GetTexture(), TEXTURE_PATH "skybox.png", true); - LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true); - LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true); - LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false); - LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false); - LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false); - LoadTexture(m_textureSoloText, TEXTURE_PATH "single_player.png", false); - LoadTexture(m_textureMultiText, TEXTURE_PATH "multi_player.png", false); - LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false); - LoadTexture(m_textureTitle, TEXTURE_PATH "title.png", false); - LoadTexture(m_textureOptions, TEXTURE_PATH "Bouton/options.png", false); - LoadTexture(m_textureVolume, TEXTURE_PATH "Bouton/volume.png", false); - LoadTexture(m_textureMusique, TEXTURE_PATH "Bouton/musique.png", false); - LoadTexture(m_textureGraphiques, TEXTURE_PATH "Bouton/graphiques.png", false); - LoadTexture(m_textureSensibilite, TEXTURE_PATH "Bouton/sensibilite.png", false); - LoadTexture(m_textureResolution, TEXTURE_PATH "Bouton/resolution.png", false); - LoadTexture(m_texturePrincipal, TEXTURE_PATH "Bouton/principal.png", false); - LoadTexture(m_textureEffets, TEXTURE_PATH "Bouton/effets.png", false); - LoadTexture(m_textureGameplay, TEXTURE_PATH "Bouton/gameplay.png", false); + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + m_textureHd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.125); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.05, centerY + Height() * 0.125); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.05, centerY + Height() * 0.15); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.15); + glEnd(); - // Pourquoi on load 3 fois la meme texture? - LoadTexture(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); - LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); - LoadTexture(MenuBGOptionTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); - LoadTexture(MenuBGFlouTexture, TEXTURE_PATH "BackgroundMenuFlou.png"); + m_textureFhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.075); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.075); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.1); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.1); + glEnd(); - LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png"); - LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png"); - LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png"); - LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png"); + m_textureQhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.025); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.025); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.05); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.05); + glEnd(); - TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); - TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); - TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); - TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); - TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png"); - TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); - TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); - TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); - TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); + m_textureUhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.025); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.015, centerY - Height() * 0.025); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.015, centerY); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY); + glEnd(); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - //AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM + float heightRatioBottom = 0.125f; + float heightRatioTop = 0.15; - //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"); + for (int i = 0; i < 4; i++) { + if (static_cast(m_resolution) == i) { + m_textureChecked.Bind(); + } + else { + m_textureCheck.Bind(); + } - //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"); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX + Width() * 0.075, centerY + Height() * heightRatioBottom); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.09, centerY + Height() * heightRatioBottom); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.09, centerY + Height() * heightRatioTop); + glTexCoord2f(0, 1); glVertex2i(centerX + Width() * 0.075, centerY + Height() * heightRatioTop); + glEnd(); - //SHOOTINGSTILL - //SHOOTINGJUMP - - if (!m_animeAtlas.Generate(TEXTURE_SIZE, false)) { - std::cout << " Unable to generate texture atlas ..." << std::endl; - abort(); + heightRatioBottom -= 0.05f; + heightRatioTop -= 0.05f; } - if (!m_textureAtlas.Generate(TEXTURE_SIZE, false)) { - std::cout << " Unable to generate texture atlas ..." << std::endl; - abort(); - } - - float u, v, s; - m_textureAtlas.TextureIndexToCoord(texDirtIndex, u, v, s, s); - m_blockinfo[BTYPE_DIRT] = new BlockInfo(BTYPE_DIRT, "Dirt", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texGrassIndex, u, v, s, s); - m_blockinfo[BTYPE_GRASS] = new BlockInfo(BTYPE_GRASS, "Grass", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texMetalIndex, u, v, s, s); - m_blockinfo[BTYPE_METAL] = new BlockInfo(BTYPE_METAL, "Metal", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); - m_blockinfo[BTYPE_ICE] = new BlockInfo(BTYPE_ICE, "Ice", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texGreenGrassIndex, u, v, s, s); - m_blockinfo[BTYPE_GREENGRASS] = new BlockInfo(BTYPE_GREENGRASS, "GreenGrass", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texBoostHeal, u, v, s, s); - m_boostinfo[BTYPE_HEAL] = new BoostInfo(BTYPE_HEAL, "Heal", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texBoostDmg, u, v, s, s); - m_boostinfo[BTYPE_DAMAGE] = new BoostInfo(BTYPE_DAMAGE, "Dmg", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texBoostSpd, u, v, s, s); - m_boostinfo[BTYPE_SPEED] = new BoostInfo(BTYPE_SPEED, "Spd", u, v, s, 1); - m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); - 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; - exit(1); - } - - if (!m_skybox.GetShader().Load(SHADER_PATH "skybox.vert", SHADER_PATH "skybox.frag", true)) { - std::cout << " Failed to load shader " << std::endl; - exit(1); - } + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } -void Engine::UnloadResource() {} - void Engine::InstantDamage() { m_player.InflictDamage(0.10f); @@ -1022,10 +1159,6 @@ void Engine::DisplaySingleOrMultiplayerMenu() { ShowCursor(); } -void Engine::DisplayAudioMenu() { - -} - void Engine::DrawHud(float elapsedTime, BlockType bloc) { // Setter le blend function, tout ce qui sera noir sera transparent glDisable(GL_STENCIL_TEST); @@ -1459,7 +1592,6 @@ void Engine::KeyReleaseEvent(unsigned char key) { break; case 2: // C - Toggle crosshair m_displayCrosshair = !m_displayCrosshair; - std::cout << "DISPLAY CROSSHAIR " << (m_displayCrosshair ? "enabled" : "disabled") << std::endl; break; case 3: // D - Stop droite m_keyD = false; @@ -1607,8 +1739,33 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { else if (x > leftGameplay && x < rightGameplay && y > bottomGameplay && y < topGameplay) { m_selectedOption = 2; // Gameplay } - else { - m_selectedOption = -1; + + float leftChk = centerX + Width() * 0.075f; + float rightChk = centerX + Width() * 0.09f; + + float topChkHD = centerY - Height() * 0.125f; + float bottomChkHD = centerY - Height() * 0.155f; + + float topChkFHD = centerY - Height() * 0.0725f; + float bottomChkFHD = centerY - Height() * 0.1f; + + float topChkQHD = centerY - Height() * 0.025f; + float bottomChkQHD = centerY - Height() * 0.05f; + + float topChkUHD = centerY + Height() * 0.025f; + float bottomChkUHD = centerY; + + if (leftChk && x < rightChk && y > bottomChkHD && y < topChkHD) { + m_resolution = HD; + } + if (x > leftChk && x < rightChk && y > bottomChkFHD && y < topChkFHD) { + m_resolution = FHD; + } + if (x > leftChk && x < rightChk && y > bottomChkQHD && y < topChkQHD) { + m_resolution = QHD; + } + if (x > leftChk && x < rightChk && y > bottomChkUHD && y < topChkUHD) { + m_resolution = UHD; } } else if (m_gamestate == GameState::SINGLEMULTI) @@ -1629,7 +1786,6 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { if (m_mousemx >= buttonPosX && m_mousemx <= (buttonPosX + buttonWidth) && adjustedMouseY >= buttonSinglePosY && adjustedMouseY <= (buttonSinglePosY + buttonHeight)) { - std::cout << "Single Player button clicked" << std::endl; m_soloMultiChoiceMade = true; m_gamestate = GameState::PLAY; } @@ -1637,7 +1793,6 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { else if (m_mousemx >= buttonPosX && m_mousemx <= (buttonPosX + buttonWidth) && adjustedMouseY >= buttonMultiPosY && adjustedMouseY <= (buttonMultiPosY + buttonHeight)) { - std::cout << "Multiplayer button clicked" << std::endl; m_soloMultiChoiceMade = true; m_gamestate = GameState::PLAY; } diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index a4b778d..bd82167 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -61,7 +61,8 @@ private: void DisplayHud(int timer); void DisplayInfo(float elapsedTime, BlockType bloc); void DisplaySingleOrMultiplayerMenu(); - void DisplayAudioMenu(); + void DisplayAudioMenu(float centerX, float centerY); + void DisplayGraphicsMenu(float centerX, float centerY); void DrawHud(float elapsedTime, BlockType bloc); void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); void ProcessNotificationQueue(); @@ -94,8 +95,13 @@ private: Texture m_textureResolution; Texture m_texturePrincipal; Texture m_textureEffets; - Texture m_textureGameplay - ; + Texture m_textureGameplay; + Texture m_textureHd; + Texture m_textureFhd; + Texture m_textureQhd; + Texture m_textureUhd; + Texture m_textureCheck; + Texture m_textureChecked; TextureAtlas::TextureIndex texBoostHeal; @@ -132,6 +138,7 @@ private: Texture OnOffBtnTexture;//TODO Texture BackBtnTexture;//TODO + Resolution m_resolution = HD; float m_scale; float m_time = 0; diff --git a/SQCSim2021/media/textures/Buttons/check.png b/SQCSim2021/media/textures/Buttons/check.png new file mode 100644 index 0000000..9b3968b Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/check.png differ diff --git a/SQCSim2021/media/textures/Buttons/checked.png b/SQCSim2021/media/textures/Buttons/checked.png new file mode 100644 index 0000000..2debe55 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/checked.png differ diff --git a/SQCSim2021/media/textures/Bouton/effets.png b/SQCSim2021/media/textures/Buttons/effets.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/effets.png rename to SQCSim2021/media/textures/Buttons/effets.png diff --git a/SQCSim2021/media/textures/Buttons/fhd.png b/SQCSim2021/media/textures/Buttons/fhd.png new file mode 100644 index 0000000..0e78428 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/fhd.png differ diff --git a/SQCSim2021/media/textures/Bouton/gameplay.png b/SQCSim2021/media/textures/Buttons/gameplay.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/gameplay.png rename to SQCSim2021/media/textures/Buttons/gameplay.png diff --git a/SQCSim2021/media/textures/Bouton/graphiques.png b/SQCSim2021/media/textures/Buttons/graphiques.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/graphiques.png rename to SQCSim2021/media/textures/Buttons/graphiques.png diff --git a/SQCSim2021/media/textures/Buttons/hd.png b/SQCSim2021/media/textures/Buttons/hd.png new file mode 100644 index 0000000..9594d91 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/hd.png differ diff --git a/SQCSim2021/media/textures/Bouton/musique.png b/SQCSim2021/media/textures/Buttons/musique.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/musique.png rename to SQCSim2021/media/textures/Buttons/musique.png diff --git a/SQCSim2021/media/textures/Bouton/options.png b/SQCSim2021/media/textures/Buttons/options.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/options.png rename to SQCSim2021/media/textures/Buttons/options.png diff --git a/SQCSim2021/media/textures/Bouton/principal.png b/SQCSim2021/media/textures/Buttons/principal.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/principal.png rename to SQCSim2021/media/textures/Buttons/principal.png diff --git a/SQCSim2021/media/textures/Buttons/qhd.png b/SQCSim2021/media/textures/Buttons/qhd.png new file mode 100644 index 0000000..1da6626 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/qhd.png differ diff --git a/SQCSim2021/media/textures/Bouton/resolution.png b/SQCSim2021/media/textures/Buttons/resolution.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/resolution.png rename to SQCSim2021/media/textures/Buttons/resolution.png diff --git a/SQCSim2021/media/textures/Bouton/sensibilite.png b/SQCSim2021/media/textures/Buttons/sensibilite.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/sensibilite.png rename to SQCSim2021/media/textures/Buttons/sensibilite.png diff --git a/SQCSim2021/media/textures/Buttons/uhd.png b/SQCSim2021/media/textures/Buttons/uhd.png new file mode 100644 index 0000000..696a558 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/uhd.png differ diff --git a/SQCSim2021/media/textures/Bouton/volume.png b/SQCSim2021/media/textures/Buttons/volume.png similarity index 100% rename from SQCSim2021/media/textures/Bouton/volume.png rename to SQCSim2021/media/textures/Buttons/volume.png