Changement dans le splachscreen

This commit is contained in:
Louis-Charles Gaumond 2023-10-23 16:57:19 -04:00
parent f4d4f1eca0
commit f8680a318a
4 changed files with 62 additions and 50 deletions

View File

@ -28,6 +28,56 @@ Engine::~Engine() {
m_world.GetChunks().Get(x, y)->~Chunk();
}
void Engine::DrawSplachScreen()
{
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
// Définir la matrice de projection en mode orthographique
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(-Width() / 2, Width() / 2, -Height() / 2, Height() / 2, -1, 1);
// Définir la matrice de modèle-vue
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// L'image sera centrée autour de l'origine (0, 0, 0)
int imageWidth = Width(); // Remplacez par la largeur de votre image
int imageHeight = Height(); // Remplacez par la hauteur de votre image
// Texture
SplachScreenTexture.Bind();
// Dessiner un quadrilatère centré
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(-imageWidth / 2, -imageHeight / 2);
glTexCoord2f(1, 0);
glVertex2i(imageWidth / 2, -imageHeight / 2);
glTexCoord2f(1, 1);
glVertex2i(imageWidth / 2, imageHeight / 2);
glTexCoord2f(0, 1);
glVertex2i(-imageWidth / 2, imageHeight / 2);
glEnd();
// Activer la transparence
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glEnable(GL_BLEND);
// Restaurer les matrices précédentes
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void Engine::DrawMenu()
{
static const int sTitle = 400;
@ -223,6 +273,8 @@ void Engine::DrawMenu()
}
void Engine::Init() {
GLenum glewErr = glewInit();
if (glewErr != GLEW_OK) {
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
@ -298,6 +350,7 @@ void Engine::LoadResource() {
LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.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");
@ -649,7 +702,10 @@ int Engine::GetCountdown(float elapsedTime) {
void Engine::Render(float elapsedTime) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
if (m_gamestate == GameState::PLAY)
m_time_SplashScreen += elapsedTime;
if(m_time_SplashScreen < 2)
DrawSplachScreen();
else if (m_gamestate == GameState::PLAY)
{
HideCursor();
CenterMouse(); //D<>placement de centermouse dans l'action de jouer

View File

@ -25,6 +25,7 @@ public:
Engine();
virtual ~Engine();
virtual void DrawMenu();
virtual void DrawSplachScreen();
virtual void Init();
virtual void DeInit();
virtual void LoadResource();
@ -87,9 +88,13 @@ private:
Texture MenuStartTexture;
Texture MenuQuitTexture;
Texture MenuOptionsTexture;
Texture SplachScreenTexture;
float m_scale;
float m_time = 0;
float m_time_SplashScreen = 0;
float m_Width = 0;
float m_Height = 0;
int m_renderCount = 0;
int m_countdown = COUNTDOWN;

View File

@ -9,43 +9,12 @@ OpenglContext::~OpenglContext()
{
}
void OpenglContext::RenderSplashScreen()
{
m_textureSplash.Load(TEXTURE_PATH "sc2.png", true);
if (!m_textureSplash.IsValid()) {
std::cerr << "Unable to load texture sc2.png" << std::endl;
}
m_textureSplash.Bind();
glMatrixMode(GL_PROJECTION);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Utilisez une fonction de mélange appropriée
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(1, 0);
glVertex2i(BASE_WIDTH, 0);
glTexCoord2f(1, 1);
glVertex2i(BASE_WIDTH, BASE_HEIGHT);
glTexCoord2f(0, 1);
glVertex2i(0, BASE_HEIGHT);
glEnd();
}
bool OpenglContext::Start(const std::string& title, int width, int height, bool fullscreen)
{
m_title = title;
m_fullscreen = fullscreen;
InitWindow(width, height);
bool showSplashScreen = true;
sf::Clock splashClock;
Init();
LoadResource();
@ -54,21 +23,6 @@ bool OpenglContext::Start(const std::string& title, int width, int height, bool
while (m_app.isOpen())
{
if (showSplashScreen)
{
m_app.setActive();
Render(m_lastFrameTime);
m_app.display();
RenderSplashScreen();
if (splashClock.getElapsedTime().asSeconds() >= 3)
{
showSplashScreen = false;
}
}
else
{
clock.restart();
@ -122,7 +76,6 @@ bool OpenglContext::Start(const std::string& title, int width, int height, bool
m_lastFrameTime = clock.getElapsedTime().asSeconds();
}
}
}
UnloadResource();

View File

@ -31,7 +31,6 @@ public:
virtual void MouseMoveEvent(int x, int y) = 0;
virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y) = 0;
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y) = 0;
virtual void RenderSplashScreen();
bool Start(const std::string& title, int width, int height, bool fullscreen);
bool Stop();
@ -63,7 +62,6 @@ private:
bool m_fullscreen;
std::string m_title;
float m_lastFrameTime;
Texture m_textureSplash;
};
#endif // OPENGLCONTEXT_H__