Créé branche

This commit is contained in:
Louis-Charles Gaumond
2023-10-23 16:10:21 -04:00
parent 793da52871
commit f4d4f1eca0
4 changed files with 73 additions and 22 deletions

View File

@@ -9,11 +9,43 @@ 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<72>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();
@@ -22,13 +54,29 @@ bool OpenglContext::Start(const std::string& title, int width, int height, bool
while (m_app.isOpen())
{
clock.restart();
sf::Event Event;
while (m_app.pollEvent(Event))
if (showSplashScreen)
{
switch(Event.type)
m_app.setActive();
Render(m_lastFrameTime);
m_app.display();
RenderSplashScreen();
if (splashClock.getElapsedTime().asSeconds() >= 3)
{
showSplashScreen = false;
}
}
else
{
clock.restart();
sf::Event Event;
while (m_app.pollEvent(Event))
{
switch (Event.type)
{
case sf::Event::Closed:
m_app.close();
break;
@@ -51,28 +99,29 @@ bool OpenglContext::Start(const std::string& title, int width, int height, bool
MouseReleaseEvent(ConvertMouseButton(Event.mouseButton.button), Event.mouseButton.x, Event.mouseButton.y);
break;
case sf::Event::MouseWheelMoved:
if(Event.mouseWheel.delta > 0)
if (Event.mouseWheel.delta > 0)
MousePressEvent(MOUSE_BUTTON_WHEEL_UP, Event.mouseButton.x, Event.mouseButton.y);
else
MousePressEvent(MOUSE_BUTTON_WHEEL_DOWN, Event.mouseButton.x, Event.mouseButton.y);
break;
default: break;
}
}
}
m_app.setActive();
Render(m_lastFrameTime);
m_app.display();
m_lastFrameTime = clock.getElapsedTime().asSeconds();
// Handle ourself frame rate limit, sf::Window::setFramerateLimit doesn't seems to work
float waitTime = (1.f / m_maxFps) - m_lastFrameTime;
if(waitTime > 0)
{
sf::sleep(sf::seconds(waitTime));
m_app.setActive();
Render(m_lastFrameTime);
m_app.display();
m_lastFrameTime = clock.getElapsedTime().asSeconds();
// Handle ourself frame rate limit, sf::Window::setFramerateLimit doesn't seems to work
float waitTime = (1.f / m_maxFps) - m_lastFrameTime;
if (waitTime > 0)
{
sf::sleep(sf::seconds(waitTime));
m_lastFrameTime = clock.getElapsedTime().asSeconds();
}
}
}