This commit is contained in:
Marc-Eric Martel 2021-09-27 13:56:29 -04:00
parent 8f387d2f34
commit 13b567a03e
4 changed files with 33 additions and 22 deletions

View File

@ -58,6 +58,7 @@ void Engine::Render(float elapsedTime)
gameTime += elapsedTime;
Transformation all;
Transformation skybox;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -67,7 +68,8 @@ void Engine::Render(float elapsedTime)
m_player.Move(m_keyW, m_keyS, m_keyA, m_keyD, elapsedTime);
m_player.ApplyTransformation(all);
all.Use();
m_player.ApplyTransformation(skybox, false);
skybox.Use();
// Skybox
m_textureSkybox.Bind();
@ -75,44 +77,53 @@ void Engine::Render(float elapsedTime)
glBegin(GL_QUADS);
glTexCoord2f(1, 0);
glVertex3f(100.f, 100.f, 100.f);
glVertex3f(10.f, 10.f, 10.f);
glTexCoord2f(0, 0);
glVertex3f(-100.f, 100.f, 100.f);
glVertex3f(-10.f, 10.f, 10.f);
glTexCoord2f(0, 1);
glVertex3f(-100.f, -3.f, 100.f);
glVertex3f(-10.f, -10.f, 10.f);
glTexCoord2f(1, 1);
glVertex3f(100.f, -3.f, 100.f);
glVertex3f(10.f, -10.f, 10.f);
glTexCoord2f(1, 0);
glVertex3f(100.f, -3.f, -100.f);
glVertex3f(10.f, -10.f, -10.f);
glTexCoord2f(0, 0);
glVertex3f(-100.f, -3.f, -100.f);
glVertex3f(-10.f, -10.f, -10.f);
glTexCoord2f(0, 1);
glVertex3f(-100.f, 100.f, -100.f);
glVertex3f(-10.f, 10.f, -10.f);
glTexCoord2f(1, 1);
glVertex3f(100.f, 100.f, -100.f);
glVertex3f(10.f, 10.f, -10.f);
glTexCoord2f(1, 0);
glVertex3f(-100.f, 100.f, 100.f);
glVertex3f(-10.f, 10.f, 10.f);
glTexCoord2f(0, 0);
glVertex3f(-100.f, 100.f, -100.f);
glVertex3f(-10.f, 10.f, -10.f);
glTexCoord2f(0, 1);
glVertex3f(-100.f, -3.f, -100.f);
glVertex3f(-10.f, -10.f, -10.f);
glTexCoord2f(1, 1);
glVertex3f(-100.f, -3.f, 100.f);
glVertex3f(-10.f, -10.f, 10.f);
glTexCoord2f(1, 0);
glVertex3f(100.f, 100.f, -100.f);
glVertex3f(10.f, 10.f, -10.f);
glTexCoord2f(0, 0);
glVertex3f(100.f, 100.f, 100.f);
glVertex3f(10.f, 10.f, 10.f);
glTexCoord2f(0, 1);
glVertex3f(100.f, -3.f, 100.f);
glVertex3f(10.f, -10.f, 10.f);
glTexCoord2f(1, 1);
glVertex3f(100.f, -3.f, -100.f);
glVertex3f(10.f, -10.f, -10.f);
glTexCoord2f(0, 0); // Les coordos de textures sont intentionnellement laissées à 0 pour que l'engine sample 1 pixel et ainsi me fait une couleur unie.
glVertex3f(10.f, 10.f, -10.f);
glTexCoord2f(0, 0);
glVertex3f(10.f, 10.f, 10.f);
glTexCoord2f(0, 0);
glVertex3f(-10.f, 10.f, 10.f);
glTexCoord2f(0, 0);
glVertex3f(-10.f, 10.f, -10.f);
glEnd();
glEnable(GL_DEPTH_TEST);
all.Use();
// Plancher
// Les vertex doivent etre affiches dans le sens anti-horaire (CCW)
m_textureFloor.Bind();

View File

@ -152,7 +152,7 @@ void OpenglContext::ShowCrossCursor() const
void OpenglContext::InitWindow(int width, int height)
{
m_app.create(sf::VideoMode(width, height, 32), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize|sf::Style::Close), sf::ContextSettings(32, 8, 0));
m_app.create(sf::VideoMode(width, height, 32), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize|sf::Style::Close), sf::ContextSettings(32, 8, 4));
}
OpenglContext::MOUSE_BUTTON OpenglContext::ConvertMouseButton(sf::Mouse::Button button) const

View File

@ -40,8 +40,8 @@ void Player::Move(bool front, bool back, bool left, bool right, float elapsedTim
}
}
void Player::ApplyTransformation(Transformation& transformation) const {
void Player::ApplyTransformation(Transformation& transformation, bool rel) const {
transformation.ApplyRotation(-m_rotX, 1.f, 0, 0);
transformation.ApplyRotation(-m_rotY, 0, 1.f, 0);
transformation.ApplyTranslation(-m_position);
if (rel) transformation.ApplyTranslation(-m_position);
}

View File

@ -9,7 +9,7 @@ public:
void TurnLeftRight(float value);
void TurnTopBottom(float value);
void Move(bool front, bool back, bool left, bool right, float elapsedTime);
void ApplyTransformation(Transformation& transformation) const;
void ApplyTransformation(Transformation& transformation, bool rel = true) const;
private:
Vector3f m_position;