Push - Texte sur écran ajusté au window size. Clean up gun01 image.

This commit is contained in:
Mathieu Duval 2023-09-16 21:38:58 -04:00
parent 54ae0b087a
commit e546de57c9
5 changed files with 48 additions and 34 deletions

View File

@ -33,6 +33,9 @@
#define VIEW_DISTANCE 256
#define TEXTURE_SIZE 128
#define MAX_BULLETS 64
#define BASE_WIDTH 640
#define BASE_HEIGHT 480
#endif
#ifdef NDEBUG

View File

@ -181,13 +181,11 @@ void Engine::DisplayHud() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor3f(1.0f, 1.0f, 1.0f);
unsigned int x = Width() / 20;
unsigned int y = Height() - (Height() - 85);
float scale = 1.5f;
float scale = GetScale();
m_textureFont.Bind();
std::ostringstream ss;
ss << m_player.GetUsername();
PrintText(x, y, scale, ss.str());
PrintText(fPosX, fPosY, scale, ss.str());
}
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
@ -195,26 +193,26 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
m_textureFont.Bind();
std::ostringstream ss;
float scale = 1.0f;
float scale = GetScale();
unsigned int x = Width() / 25;
ss << " Fps : " << GetFps(elapsedTime);
PrintText(x, Height() - 25, scale, ss.str());
PrintText(x, Height() - (Height() / 19.2), scale, ss.str());
ss.str("");
ss << " Rendered Chunks : " << m_renderCount;
PrintText(x, Height() - 35, scale, ss.str());
PrintText(x, Height() - (Height() / 13.7), scale, ss.str());
ss.str("");
ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted();
PrintText(x, Height() - 45, scale, ss.str());
PrintText(x, Height() - (Height() / 10.7), scale, ss.str());
ss.str("");
ss << " Velocity : " << m_player.GetVelocity(); // IMPORTANT : on utilise l operateur << pour afficher la position
PrintText(x, 10, scale, ss.str());
PrintText(x, Height() / 48, scale, ss.str());
ss.str("");
ss << " Direction : " << m_player.GetDirection();
PrintText(x, 20, scale, ss.str());
PrintText(x, Height() / 24, scale, ss.str());
ss.str("");
ss << " Position : " << m_player.GetPosition();
PrintText(x, 30, scale, ss.str());
PrintText(x, Height() / 16, scale, ss.str());
ss.str("");
ss << " Block : ";
@ -222,7 +220,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
ss << "Weapon.";
else ss << (int)bloc;
PrintText(x, 40, scale, ss.str());
PrintText(x, Height() / 12, scale, ss.str());
}
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
@ -269,7 +267,7 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
glPopMatrix();
}
void Engine::PrintText(unsigned int x, unsigned int y, float scale, const std::string& t) {
void Engine::PrintText(float x, float y, float scale, const std::string& t) {
glLoadIdentity();
glTranslated(x, y, 0);
@ -280,15 +278,22 @@ void Engine::PrintText(unsigned int x, unsigned int y, float scale, const std::s
glBegin(GL_QUADS);
glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0);
glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(12, 0);
glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(12, 12);
glTexCoord2f(left, 1.f - top); glVertex2f(0, 12);
glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(12 * scale, 0);
glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(12 * scale, 12 * scale);
glTexCoord2f(left, 1.f - top); glVertex2f(0, 12 * scale);
glEnd();
glTranslated(8, 0, 0);
glTranslated(8 * scale, 0, 0);
}
}
float Engine::GetScale() const {
float widthRatio = Width() / BASE_WIDTH;
float heightRatio = Height() / BASE_HEIGHT;
return (widthRatio + heightRatio) / 2.0f;
}
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
void Engine::Render(float elapsedTime) {
@ -412,7 +417,8 @@ void Engine::KeyPressEvent(unsigned char key) {
}
break;
case 94: // F10 - Plein écran
SetFullscreen(!IsFullscreen());
IsFullscreen() ? SetFullscreen(false) : SetFullscreen(true);
//SetFullscreen(!IsFullscreen());
break;
case 2: // C - Ignorer
break;

View File

@ -1,5 +1,6 @@
#ifndef ENGINE_H__
#define ENGINE_H__
#include "define.h"
#include "openglcontext.h"
#include "texture.h"
@ -31,19 +32,18 @@ public:
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
private:
float GetScale() const;
int GetFps(float elapsedTime) const;
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
void DisplayCrosshair();
void DisplayCurrentItem();
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;
bool m_wireframe = false;
bool m_isSkybox = true;
int m_renderCount = 0;
void PrintText(float x, float y, float scale, const std::string& t);
Shader m_shader01;
BlockInfo* m_blockinfo[BTYPE_LAST];
@ -55,7 +55,7 @@ private:
Texture m_textureFont;
Texture m_textureCrosshair;
Texture m_textureGun;
Skybox m_skybox;
Audio m_audio = Audio(AUDIO_PATH "start.wav");
@ -66,6 +66,18 @@ private:
Bullet* m_bullets[MAX_BULLETS];
float m_scale;
int m_renderCount = 0;
bool m_wireframe = false;
bool m_isSkybox = true;
bool m_block = false;
bool m_flash = true;
bool m_displayCrosshair = true;
bool m_displayHud = true;
bool m_displayInfo = false;
bool m_keyW = false;
bool m_keyA = false;
bool m_keyS = false;
@ -76,13 +88,6 @@ private:
bool m_mouseC = false;
bool m_mouseWU = false;
bool m_mouseWD = false;
bool m_block = false;
bool m_flash = true;
bool m_displayCrosshair = true;
bool m_displayHud = true;
bool m_displayInfo = false;
};
#endif // ENGINE_H__

View File

@ -5,5 +5,5 @@
int main() {
Engine engine;
engine.SetMaxFps(60);
engine.Start("Syndicat Quebecois de la Construction Simulator 2023", 640, 480, false);
engine.Start("Syndicat Quebecois de la Construction Simulator 2023", BASE_WIDTH, BASE_HEIGHT, false);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 76 KiB