Push FIX pour DrawHUD. Toggle (HUD - h) (Crosshair - c) (Infos - i) avec keypress
This commit is contained in:
parent
f8ad857666
commit
8faa67596e
@ -25,20 +25,21 @@ void Engine::Init() {
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
//glEnable(GL_STENCIL_TEST);
|
||||
//glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glEnable(GL_BLEND);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
//glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
|
||||
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
//glShadeModel(GL_SMOOTH);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
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);
|
||||
//
|
||||
// Objet de skybox avec sa propre texture et son propre shader!
|
||||
m_skybox.Init(0.2f);
|
||||
|
||||
@ -97,130 +98,120 @@ void Engine::LoadResource() {
|
||||
|
||||
void Engine::UnloadResource() {}
|
||||
|
||||
void Engine::DrawHud() {
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
float fBarWidth = Width() / 6;
|
||||
float fBarHeight = Height() / 25;
|
||||
float fPosX = Width() / 25;
|
||||
float fPosY = Height() - (Height() - (fPosX + fBarHeight));
|
||||
|
||||
float playerHp = m_player.GetHP();
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(fPosX, fPosY);
|
||||
glVertex2f(fPosX + fBarWidth, fPosY);
|
||||
glVertex2f(fPosX + fBarWidth, fPosY - fBarHeight);
|
||||
glVertex2f(fPosX, fPosY - fBarHeight);
|
||||
glEnd();
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(fPosX, fPosY);
|
||||
glVertex2f(fPosX + fBarWidth * playerHp, fPosY);
|
||||
glVertex2f(fPosX + fBarWidth * playerHp, fPosY - fBarHeight);
|
||||
glVertex2f(fPosX, fPosY - fBarHeight);
|
||||
glEnd();
|
||||
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
/*m_textureCrosshair.Bind();
|
||||
void Engine::DisplayCrosshair() {
|
||||
m_textureCrosshair.Bind();
|
||||
static const int crossSize = 32;
|
||||
glLoadIdentity();
|
||||
glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(crossSize, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(crossSize, crossSize);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, crossSize);
|
||||
glEnd();*/
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
m_textureFont.Bind();
|
||||
std::ostringstream ss;
|
||||
ss << m_player.GetUsername();
|
||||
float scale = 1.5f;
|
||||
PrintText(fPosX, fPosY + fBarHeight, scale, ss.str());
|
||||
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(crossSize, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(crossSize, crossSize);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, crossSize);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void Engine::DrawData(float elapsedTime, BlockType bloc) {
|
||||
// Setter le blend function , tout ce qui sera noir sera transparent
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
void Engine::DisplayHud() {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glDisable(GL_BLEND);
|
||||
float fBarWidth = Width() / 6;
|
||||
float fBarHeight = Height() / 25;
|
||||
float fPosX = Width() / 20;
|
||||
float fPosY = Height() - (Height() - (fBarHeight + fBarHeight + fBarHeight + fBarHeight));
|
||||
float playerHp = m_player.GetHP();
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(fPosX, fPosY - fBarHeight); // Bottom-left
|
||||
glVertex2f(fPosX + fBarWidth, fPosY - fBarHeight); // Bottom-right
|
||||
glVertex2f(fPosX + fBarWidth, fPosY); // Top-right
|
||||
glVertex2f(fPosX, fPosY); // Top-left
|
||||
glEnd();
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(fPosX, fPosY - fBarHeight); // Bottom-left
|
||||
glVertex2f(fPosX + fBarWidth * playerHp, fPosY - fBarHeight); // Bottom-right
|
||||
glVertex2f(fPosX + fBarWidth * playerHp, fPosY); // Top-right
|
||||
glVertex2f(fPosX, fPosY); // Top-left
|
||||
glEnd();
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
m_textureFont.Bind();
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
std::ostringstream ss;
|
||||
float scale = 1.5f;
|
||||
unsigned int x = Width() / 20;
|
||||
unsigned int y = Height() - (Height() - 85);
|
||||
ss << m_player.GetUsername();
|
||||
PrintText(x, y, scale, ss.str());
|
||||
}
|
||||
|
||||
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
// Bind de la texture pour le font
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
m_textureFont.Bind();
|
||||
std::ostringstream ss;
|
||||
float scale = 1.0f;
|
||||
unsigned int x = Width() / 25;
|
||||
ss << " Fps : " << GetFps(elapsedTime);
|
||||
PrintText(10, Height() - 25, scale, ss.str());
|
||||
PrintText(x, Height() - 25, scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " Rendered Chunks : " << m_renderCount;
|
||||
PrintText(10, Height() - 35, scale, ss.str());
|
||||
PrintText(x, Height() - 35, scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted();
|
||||
PrintText(10, Height() - 45, scale, ss.str());
|
||||
PrintText(x, Height() - 45, scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " Velocity : " << m_player.GetVelocity(); // IMPORTANT : on utilise l ’ operateur << pour afficher la position
|
||||
PrintText(10, 10, scale, ss.str());
|
||||
PrintText(x, 10, scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " Direction : " << m_player.GetDirection();
|
||||
PrintText(10, 20, scale, ss.str());
|
||||
PrintText(x, 20, scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " Position : " << m_player.GetPosition();
|
||||
PrintText(10, 30, scale, ss.str());
|
||||
PrintText(x, 30, scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " Block : ";
|
||||
if (bloc == BTYPE_LAST)
|
||||
ss << "Weapon.";
|
||||
else ss << (int)bloc;
|
||||
PrintText(Width() / 25, 40, scale, ss.str());
|
||||
PrintText(x, 40, scale, ss.str());
|
||||
}
|
||||
|
||||
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
||||
// Setter le blend function , tout ce qui sera noir sera transparent
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
if (m_displayHud) {
|
||||
DisplayHud();
|
||||
}
|
||||
|
||||
if (m_displayInfo) {
|
||||
DisplayInfo(elapsedTime, bloc);
|
||||
}
|
||||
|
||||
if (m_displayCrosshair) {
|
||||
DisplayCrosshair();
|
||||
}
|
||||
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@ -328,18 +319,8 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
|
||||
if (m_wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
if (m_displayHud)
|
||||
DrawHud();
|
||||
|
||||
if (m_displayData)
|
||||
DrawData(elapsedTime, bloc);
|
||||
|
||||
if (m_wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
DrawHud(elapsedTime, bloc);
|
||||
|
||||
static bool fell = false;
|
||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
||||
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), 1.f);
|
||||
@ -384,6 +365,8 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
case 94: // F10 - Plein écran
|
||||
SetFullscreen(!IsFullscreen());
|
||||
break;
|
||||
case 2: // C - Ignorer
|
||||
break;
|
||||
case 5: // F - Ignorer
|
||||
break;
|
||||
case 12: // M - Ignorer
|
||||
@ -408,6 +391,10 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
case 0: // A - Stop gauche
|
||||
m_keyA = false;
|
||||
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;
|
||||
break;
|
||||
@ -419,8 +406,8 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
std::cout << "DISPLAY HUD " << (m_displayHud ? "enabled" : "disabled") << std::endl;
|
||||
break;
|
||||
case 8: // I - Toggle render data
|
||||
m_displayData = !m_displayData;
|
||||
std::cout << "DISPLAY DATA " << (m_displayData ? "enabled" : "disabled") << std::endl;
|
||||
m_displayInfo = !m_displayInfo;
|
||||
std::cout << "DISPLAY INFO " << (m_displayInfo ? "enabled" : "disabled") << std::endl;
|
||||
break;
|
||||
case 12: // M - Toggle music
|
||||
m_audio.ToggleMusicState();
|
||||
|
@ -29,12 +29,13 @@ public:
|
||||
virtual void MouseMoveEvent(int x, int y);
|
||||
virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y);
|
||||
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
|
||||
const char* GetGLErrorString(GLenum error);
|
||||
|
||||
private:
|
||||
bool LoadTexture(Texture& texture, const std::string& filename, bool stopOnError = true);
|
||||
void DrawHud();
|
||||
void DrawData(float elapsedTime, BlockType bloc);
|
||||
void DisplayCrosshair();
|
||||
void DisplayHud();
|
||||
void DisplayInfo(float elapsedTime, BlockType bloc);
|
||||
void DrawHud(float elapsedTime, BlockType bloc);
|
||||
void PrintText(unsigned int x, unsigned int y, float scale, const std::string& t);
|
||||
int GetFps(float elapsedTime) const;
|
||||
|
||||
@ -76,8 +77,9 @@ private:
|
||||
|
||||
bool m_block = false;
|
||||
bool m_flash = true;
|
||||
bool m_displayData = false;
|
||||
bool m_displayCrosshair = true;
|
||||
bool m_displayHud = true;
|
||||
bool m_displayInfo = false;
|
||||
};
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(po
|
||||
m_velocity = Vector3f(0, 0, 0);
|
||||
m_airborne = true;
|
||||
m_hp = 0.75f;
|
||||
m_username = "John Doe";
|
||||
m_username = "Zelda Bee-Bop";
|
||||
}
|
||||
|
||||
void Player::TurnLeftRight(float value) {
|
||||
|
Loading…
Reference in New Issue
Block a user