Compare commits
2 Commits
32d3f96a3d
...
6b30e4c927
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b30e4c927 | |||
| 5d573d51a6 |
@@ -1727,12 +1727,12 @@ void Game::initPlayers(int player_id)
|
||||
const int y = param.game.play_area.rect.h - 30;
|
||||
players_.emplace_back(std::make_unique<Player>(1, param.game.play_area.first_quarter_x - 15, y, demo_.enabled, param.game.play_area.rect, player_textures_[0], player_animations_));
|
||||
players_.back()->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
|
||||
players_.back()->setName(lang::getText("SCOREBOARD_1"));
|
||||
players_.back()->setName(lang::getText("[SCOREBOARD] 1"));
|
||||
players_.back()->setController(getController(players_.back()->getId()));
|
||||
|
||||
players_.emplace_back(std::make_unique<Player>(2, param.game.play_area.third_quarter_x - 15, y, demo_.enabled, param.game.play_area.rect, player_textures_[1], player_animations_));
|
||||
players_.back()->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
|
||||
players_.back()->setName(lang::getText("SCOREBOARD_2"));
|
||||
players_.back()->setName(lang::getText("[SCOREBOARD] 2"));
|
||||
players_.back()->setController(getController(players_.back()->getId()));
|
||||
|
||||
// Activa el jugador que coincide con el "player_id"
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace shader
|
||||
#endif
|
||||
|
||||
// Función para compilar un shader a partir de un std::string
|
||||
GLuint compileShader(const std::string &source, GLuint shaderType)
|
||||
GLuint compileShader(const std::string &source, GLuint shader_type)
|
||||
{
|
||||
if (source.empty())
|
||||
{
|
||||
@@ -76,92 +76,92 @@ namespace shader
|
||||
}
|
||||
|
||||
// Crear identificador del shader
|
||||
GLuint resultado = glCreateShader(shaderType);
|
||||
GLuint shader_id = glCreateShader(shader_type);
|
||||
|
||||
// Agregar una directiva según el tipo de shader
|
||||
std::string directiva = (shaderType == GL_VERTEX_SHADER)
|
||||
std::string directive = (shader_type == GL_VERTEX_SHADER)
|
||||
? "#define VERTEX\n"
|
||||
: "#define FRAGMENT\n";
|
||||
|
||||
const char *sources[2] = {directiva.c_str(), source.c_str()};
|
||||
const char *sources[2] = {directive.c_str(), source.c_str()};
|
||||
|
||||
// Especificar el código fuente del shader
|
||||
glShaderSource(resultado, 2, sources, nullptr);
|
||||
glShaderSource(shader_id, 2, sources, nullptr);
|
||||
|
||||
// Compilar el shader
|
||||
glCompileShader(resultado);
|
||||
glCompileShader(shader_id);
|
||||
|
||||
// Verificar si la compilación fue exitosa
|
||||
GLint compiladoCorrectamente = GL_FALSE;
|
||||
glGetShaderiv(resultado, GL_COMPILE_STATUS, &compiladoCorrectamente);
|
||||
if (compiladoCorrectamente != GL_TRUE)
|
||||
GLint compiled_ok = GL_FALSE;
|
||||
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &compiled_ok);
|
||||
if (compiled_ok != GL_TRUE)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error en la compilación del shader (%d)!", resultado);
|
||||
GLint longitudLog;
|
||||
glGetShaderiv(resultado, GL_INFO_LOG_LENGTH, &longitudLog);
|
||||
if (longitudLog > 0)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error en la compilación del shader (%d)!", shader_id);
|
||||
GLint log_length;
|
||||
glGetShaderiv(shader_id, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if (log_length > 0)
|
||||
{
|
||||
std::vector<GLchar> log(longitudLog);
|
||||
glGetShaderInfoLog(resultado, longitudLog, &longitudLog, log.data());
|
||||
std::vector<GLchar> log(log_length);
|
||||
glGetShaderInfoLog(shader_id, log_length, &log_length, log.data());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Registro de compilación del shader: %s", log.data());
|
||||
}
|
||||
glDeleteShader(resultado);
|
||||
resultado = 0;
|
||||
glDeleteShader(shader_id);
|
||||
shader_id = 0;
|
||||
}
|
||||
return resultado;
|
||||
return shader_id;
|
||||
}
|
||||
|
||||
// Función para compilar un programa de shaders (vertex y fragment) a partir de std::string
|
||||
GLuint compileProgram(const std::string &vertexShaderSource, const std::string &fragmentShaderSource)
|
||||
GLuint compileProgram(const std::string &vertex_shader_source, const std::string &fragment_shader_source)
|
||||
{
|
||||
GLuint idPrograma = glCreateProgram();
|
||||
GLuint program_id = glCreateProgram();
|
||||
|
||||
// Si el fragment shader está vacío, reutilizamos el código del vertex shader
|
||||
GLuint idShaderVertice = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||
GLuint idShaderFragmento = compileShader(fragmentShaderSource.empty() ? vertexShaderSource : fragmentShaderSource, GL_FRAGMENT_SHADER);
|
||||
GLuint vertex_shader_id = compileShader(vertex_shader_source, GL_VERTEX_SHADER);
|
||||
GLuint fragment_shader_id = compileShader(fragment_shader_source.empty() ? vertex_shader_source : fragment_shader_source, GL_FRAGMENT_SHADER);
|
||||
|
||||
if (idShaderVertice && idShaderFragmento)
|
||||
if (vertex_shader_id && fragment_shader_id)
|
||||
{
|
||||
// Asociar los shaders al programa
|
||||
glAttachShader(idPrograma, idShaderVertice);
|
||||
glAttachShader(idPrograma, idShaderFragmento);
|
||||
glLinkProgram(idPrograma);
|
||||
glValidateProgram(idPrograma);
|
||||
glAttachShader(program_id, vertex_shader_id);
|
||||
glAttachShader(program_id, fragment_shader_id);
|
||||
glLinkProgram(program_id);
|
||||
glValidateProgram(program_id);
|
||||
|
||||
// Verificar el estado del enlace
|
||||
GLint longitudLog;
|
||||
glGetProgramiv(idPrograma, GL_INFO_LOG_LENGTH, &longitudLog);
|
||||
if (longitudLog > 0)
|
||||
GLint log_length;
|
||||
glGetProgramiv(program_id, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if (log_length > 0)
|
||||
{
|
||||
std::vector<char> log(longitudLog);
|
||||
glGetProgramInfoLog(idPrograma, longitudLog, &longitudLog, log.data());
|
||||
std::vector<char> log(log_length);
|
||||
glGetProgramInfoLog(program_id, log_length, &log_length, log.data());
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Registro de información del programa:\n%s", log.data());
|
||||
}
|
||||
}
|
||||
if (idShaderVertice)
|
||||
if (vertex_shader_id)
|
||||
{
|
||||
glDeleteShader(idShaderVertice);
|
||||
glDeleteShader(vertex_shader_id);
|
||||
}
|
||||
if (idShaderFragmento)
|
||||
if (fragment_shader_id)
|
||||
{
|
||||
glDeleteShader(idShaderFragmento);
|
||||
glDeleteShader(fragment_shader_id);
|
||||
}
|
||||
return idPrograma;
|
||||
return program_id;
|
||||
}
|
||||
|
||||
bool init(SDL_Window *ventana, SDL_Texture *texturaBackBuffer, const std::string &vertexShader, const std::string &fragmentShader)
|
||||
bool init(SDL_Window *window, SDL_Texture *back_buffer_texture, const std::string &vertex_shader, const std::string &fragment_shader)
|
||||
{
|
||||
shader::win = ventana;
|
||||
shader::renderer = SDL_GetRenderer(ventana);
|
||||
shader::backBuffer = texturaBackBuffer;
|
||||
SDL_GetWindowSize(ventana, &win_size.x, &win_size.y);
|
||||
shader::win = window;
|
||||
shader::renderer = SDL_GetRenderer(window);
|
||||
shader::backBuffer = back_buffer_texture;
|
||||
SDL_GetWindowSize(window, &win_size.x, &win_size.y);
|
||||
|
||||
SDL_GetTextureSize(texturaBackBuffer, &tex_size.x, &tex_size.y);
|
||||
SDL_GetTextureSize(back_buffer_texture, &tex_size.x, &tex_size.y);
|
||||
|
||||
const auto RENDER_NAME = SDL_GetRendererName(renderer);
|
||||
const auto render_name = SDL_GetRendererName(renderer);
|
||||
|
||||
// Verificar que el renderer sea OpenGL
|
||||
if (!strncmp(RENDER_NAME, "opengl", 6))
|
||||
if (!strncmp(render_name, "opengl", 6))
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
if (!initGLExtensions())
|
||||
@@ -172,7 +172,7 @@ namespace shader
|
||||
}
|
||||
#endif
|
||||
// Compilar el programa de shaders utilizando std::string
|
||||
programId = compileProgram(vertexShader, fragmentShader);
|
||||
programId = compileProgram(vertex_shader, fragment_shader);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -139,17 +139,10 @@ void Scoreboard::setPos(SDL_FRect rect)
|
||||
{
|
||||
rect_ = rect;
|
||||
|
||||
// Recalcula las anclas de los elementos
|
||||
recalculateAnchors();
|
||||
|
||||
// Crea la textura de fondo
|
||||
createBackgroundTexture();
|
||||
|
||||
// Crea las texturas de los paneles
|
||||
createPanelTextures();
|
||||
|
||||
// Rellena la textura de fondo
|
||||
fillBackgroundTexture();
|
||||
recalculateAnchors(); // Recalcula las anclas de los elementos
|
||||
createBackgroundTexture(); // Crea la textura de fondo
|
||||
createPanelTextures(); // Crea las texturas de los paneles
|
||||
fillBackgroundTexture(); // Rellena la textura de fondo
|
||||
}
|
||||
|
||||
// Rellena los diferentes paneles del marcador
|
||||
@@ -177,7 +170,7 @@ void Scoreboard::fillPanelTextures()
|
||||
text_scoreboard_->writeCentered(slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]));
|
||||
|
||||
// MULT
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("SCOREBOARD_3"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("[SCOREBOARD] 3"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_[i]).substr(0, 3));
|
||||
break;
|
||||
}
|
||||
@@ -185,13 +178,13 @@ void Scoreboard::fillPanelTextures()
|
||||
case ScoreboardMode::DEMO:
|
||||
{
|
||||
// DEMO MODE
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("SCOREBOARD_6"));
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("[SCOREBOARD] 6"));
|
||||
|
||||
// PRESS START TO PLAY
|
||||
if (time_counter_ % 10 < 8)
|
||||
{
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("SCOREBOARD_8"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText("SCOREBOARD_9"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("[SCOREBOARD] 8"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText("[SCOREBOARD] 9"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -199,13 +192,13 @@ void Scoreboard::fillPanelTextures()
|
||||
case ScoreboardMode::WAITING:
|
||||
{
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("SCOREBOARD_7"));
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("[SCOREBOARD] 7"));
|
||||
|
||||
// PRESS START TO PLAY
|
||||
if (time_counter_ % 10 < 8)
|
||||
{
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("SCOREBOARD_8"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText("SCOREBOARD_9"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("[SCOREBOARD] 8"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText("[SCOREBOARD] 9"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -213,13 +206,13 @@ void Scoreboard::fillPanelTextures()
|
||||
case ScoreboardMode::GAME_OVER:
|
||||
{
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("SCOREBOARD_7"));
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("[SCOREBOARD] 7"));
|
||||
|
||||
// PLEASE WAIT
|
||||
if (time_counter_ % 10 < 8)
|
||||
{
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("SCOREBOARD_12"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText("SCOREBOARD_13"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("[SCOREBOARD] 12"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText("[SCOREBOARD] 13"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -227,7 +220,7 @@ void Scoreboard::fillPanelTextures()
|
||||
case ScoreboardMode::STAGE_INFO:
|
||||
{
|
||||
// STAGE
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y, lang::getText("SCOREBOARD_5") + std::to_string(stage_));
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y, lang::getText("[SCOREBOARD] 5") + std::to_string(stage_));
|
||||
|
||||
// POWERMETER
|
||||
power_meter_sprite_->setSpriteClip(0, 0, 40, 7);
|
||||
@@ -236,7 +229,7 @@ void Scoreboard::fillPanelTextures()
|
||||
power_meter_sprite_->render();
|
||||
|
||||
// HI-SCORE
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("SCOREBOARD_4"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("[SCOREBOARD] 4"));
|
||||
const std::string name = hi_score_name_ == "" ? "" : hi_score_name_ + " - ";
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, name + updateScoreText(hi_score_));
|
||||
break;
|
||||
@@ -249,7 +242,7 @@ void Scoreboard::fillPanelTextures()
|
||||
text_scoreboard_->writeCentered(slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]));
|
||||
|
||||
// CONTINUE
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("SCOREBOARD_10"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("[SCOREBOARD] 10"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_[i]));
|
||||
break;
|
||||
}
|
||||
@@ -262,7 +255,7 @@ void Scoreboard::fillPanelTextures()
|
||||
|
||||
// ENTER NAME
|
||||
{
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("SCOREBOARD_11"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("[SCOREBOARD] 11"));
|
||||
SDL_FRect rect = {enter_name_pos_.x, enter_name_pos_.y, 5.0f, 7.0f};
|
||||
|
||||
// Recorre todos los slots de letras del nombre
|
||||
@@ -298,7 +291,7 @@ void Scoreboard::fillPanelTextures()
|
||||
text_scoreboard_->writeCentered(slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]));
|
||||
|
||||
// NAME
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("SCOREBOARD_11"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText("[SCOREBOARD] 11"));
|
||||
/* TEXTO CENTRADO */
|
||||
// text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[i], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
|
||||
@@ -309,12 +302,12 @@ void Scoreboard::fillPanelTextures()
|
||||
case ScoreboardMode::GAME_COMPLETED:
|
||||
{
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("SCOREBOARD_7"));
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText("[SCOREBOARD] 7"));
|
||||
|
||||
// SCORE
|
||||
if (time_counter_ % 10 < 8)
|
||||
{
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("SCOREBOARD_14"));
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText("[SCOREBOARD] 14"));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_[i]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user