Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Diego Pérez Peña
/
PAG_p1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
000430f2
authored
Sep 19, 2025
by
Diego Pérez Peña
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Ejercicio tercero completado y funcionando
parent
5493a422
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
176 additions
and
40 deletions
BackgroundWindow.cpp
BackgroundWindow.h
GUI.cpp
GUI.h
GuiElement.cpp
GuiElement.h
Listener.h
LogWindow.cpp
LogWindow.h
Renderer.cpp
main.cpp
BackgroundWindow.cpp
View file @
000430f2
//
// Created by pete on 18/09/25.
//
/**
* @file BackgroundWindow.cpp
* @author dpp00022
*
* @date 2025/08/18
*
* @brief Implementación de la clase BackgroundWindow
*/
#include "BackgroundWindow.h"
#include <imgui.h>
#include <glm/vec3.hpp>
/**
* Constructor de la clase
*/
BackgroundWindow
::
BackgroundWindow
()
{
color_fondo
=
glm
::
vec3
(
0.6
f
,
0.6
f
,
0.6
f
);
}
/**
* @brief Mét0do de aviso a los listeners de este objeto
*
* Esta función pasa el color actual de fondo a los listeners.
*/
void
BackgroundWindow
::
warnListeners
()
{
glm
::
vec3
aux
=
color_fondo
;
...
...
@@ -19,6 +32,9 @@ void BackgroundWindow::warnListeners() {
}
}
/**
* Función de renderizado de la ventana a través de ImGui
*/
void
BackgroundWindow
::
render
()
{
ImGui
::
SetNextWindowPos
(
ImVec2
(
10
,
10
),
ImGuiCond_Once
);
...
...
BackgroundWindow.h
View file @
000430f2
//
// Created by pete on 18/09/25.
//
/**
* @file BackgroundWindow.h
* @author dpp00022
*
* @date 2025/09/18
*
* @brief Declaración de la clase BackgroundWindow
*/
#ifndef BACKGROUNDWINDOW_H
#define BACKGROUNDWINDOW_H
...
...
@@ -8,10 +13,13 @@
#include <glm/vec3.hpp>
#include "GuiElement.h"
/**
* Clase que implementa un elemento de la interfaz con un
* selector de color para el color de fondo de la ventana.
*/
class
BackgroundWindow
:
public
GuiElement
{
glm
::
vec3
color_fondo
;
glm
::
vec3
color_fondo
;
///< String que almacena el color de fondo actual
public:
BackgroundWindow
();
virtual
~
BackgroundWindow
()
=
default
;
...
...
@@ -19,6 +27,4 @@ public:
void
render
()
override
;
};
#endif //BACKGROUNDWINDOW_H
GUI.cpp
View file @
000430f2
...
...
@@ -17,6 +17,9 @@ PAG::GUI* PAG::GUI::instancia = nullptr;
BackgroundWindow
PAG
::
GUI
::
background
=
BackgroundWindow
();
LogWindow
PAG
::
GUI
::
log
=
LogWindow
();
/**
* Constructor de la clase
*/
PAG
::
GUI
::
GUI
()
{
background
.
addListener
(
&
PAG
::
Renderer
::
getInstancia
());
}
...
...
@@ -100,4 +103,13 @@ void PAG::GUI::callback_raton(int button, bool pulsado) {
io
.
AddMouseButtonEvent
(
button
,
pulsado
);
}
/**
* @brief Función para agregar un mensaje al registro
*
* Se pasa la responsabilidad a la clase LogWindow.
*
* @param texto Mensaje que se desea registrar
*/
void
PAG
::
GUI
::
registrarMensaje
(
std
::
string
texto
)
{
log
.
registrarMensaje
(
texto
);
}
\ No newline at end of file
GUI.h
View file @
000430f2
...
...
@@ -11,7 +11,7 @@
#define PAG_P1_GUI_H
#include <imgui_impl_glfw.h>
#include <string>
#include "BackgroundWindow.h"
#include "LogWindow.h"
...
...
@@ -40,6 +40,7 @@ namespace PAG {
void
destruirGUI
();
void
callback_raton
(
int
button
,
bool
pulsado
);
void
registrarMensaje
(
std
::
string
texto
);
};
}
...
...
GuiElement.cpp
View file @
000430f2
//
// Created by pete on 18/09/25.
//
/**
* @file GuiElement.cpp
* @author dpp00022
*
* @date 2025/08/18
*
* @brief Implementación de la clase abstracta GuiElement
*/
#include "GuiElement.h"
/**
* Constructor de la clase
*/
GuiElement
::
GuiElement
()
{
listeners
=
std
::
vector
<
Listener
*>
();
}
/**
* Función para agregar un listener a la lista
* @param listener Puntero al objeto listener que se desea registrar
*/
void
GuiElement
::
addListener
(
Listener
*
listener
)
{
listeners
.
push_back
(
listener
);
}
GuiElement.h
View file @
000430f2
//
// Created by pete on 18/09/25.
//
/**
* @file GuiElement.h
* @author dpp00022
*
* @date 2025/09/18
*
* @brief Declaración de la clase abstracta GuiElement
*/
#ifndef GUIELEMENT_H
#define GUIELEMENT_H
#include <vector>
#include "Listener.h"
/**
* @brief Clase abstracta que implementa el comportamiento de
* un elemento de la interfaz de usuario.
*
* La clase implementa el comportamiento de agregación de objetos
* listener a los que avisar cuando haya actualizaciones. En cambio,
* no implementa cómo avisar a estos Listeners ni cómo se debe
* renderizar el elemento.
*/
class
GuiElement
{
protected
:
std
::
vector
<
Listener
*>
listeners
;
...
...
Listener.h
View file @
000430f2
//
// Created by pete on 18/09/25.
//
/**
* @file Listener.h
* @author dpp00022
*
* @date 2025/09/18
*
* @brief Declaración de la interfaz Listener
*/
#ifndef LISTENER_H
#define LISTENER_H
// TODO: Cuando el profesor añada el showAxis, cambiar Background a 2
/**
* @brief Tipo enumerado para discernir los diferentes tipos de ventanas de la GUI.
*
* El valor es igual al número de argumentos que se pasan en la lista variable.
*/
enum
WindowType
{
Background
=
1
};
/**
* Interfaz que especifica el comportamiento de una clase que escucha
* las actualizaciones de otra clase.
*/
class
Listener
{
public
:
Listener
()
=
default
;
...
...
LogWindow.cpp
View file @
000430f2
//
// Created by pete on 19/09/25.
//
/**
* @file LogWindow.cpp
* @author dpp00022
*
* @date 2025/08/19
*
* @brief Implementación de la clase LogWindow
*/
#include "LogWindow.h"
#include <imgui.h>
/**
* Constructor de la clase
*/
LogWindow
::
LogWindow
()
{
log
=
std
::
string
();
}
/**
* @brief Mét0do de aviso a los listeners de este objeto
*
* Esta clase no avisa a listeners.
*/
void
LogWindow
::
warnListeners
()
{
}
/**
* Función de renderizado de la ventana a través de ImGui
*/
void
LogWindow
::
render
()
{
ImGui
::
SetNextWindowPos
(
ImVec2
(
200
,
10
),
ImGuiCond_Once
);
ImGui
::
SetNextWindowSize
(
ImVec2
(
300
,
200
),
ImGuiCond_Once
);
...
...
@@ -23,3 +38,12 @@ void LogWindow::render() {
}
ImGui
::
End
();
}
/**
* Función para agregar un mensaje al registro
*
* @param texto Mensaje que se desea registrar
*/
void
LogWindow
::
registrarMensaje
(
std
::
string
texto
)
{
log
.
append
(
texto
).
append
(
"
\n
"
);
}
LogWindow.h
View file @
000430f2
//
// Created by pete on 19/09/25.
//
/**
* @file LogWindow.h
* @author dpp00022
*
* @date 2025/09/19
*
* @brief Declaración de la clase LogWindow
*/
#ifndef LOGWINDOW_H
#define LOGWINDOW_H
...
...
@@ -8,14 +13,21 @@
#include <string>
#include "GuiElement.h"
/**
* Clase que implementa un elemento de la interfaz con un
* registro de los mensajes generados durante la ejecución
* del programa.
*/
class
LogWindow
:
public
GuiElement
{
std
::
string
log
;
std
::
string
log
;
///< String que almacena el registro de mensajes
public:
LogWindow
();
virtual
~
LogWindow
()
=
default
;
void
warnListeners
()
override
;
void
render
()
override
;
void
registrarMensaje
(
std
::
string
texto
);
};
#endif //LOGWINDOW_H
Renderer.cpp
View file @
000430f2
...
...
@@ -64,6 +64,12 @@ void PAG::Renderer::refrescar_tamanio_framebuffer(int width, int height) {
glViewport
(
0
,
0
,
width
,
height
);
}
/**
* Función que implementa el mét0do de actualización del Renderer.
*
* @param t Clase de ventana que está avisando a este Listener
* @param ... Lista de argumentos propios de la ventana
*/
void
PAG
::
Renderer
::
wakeUp
(
WindowType
t
,
...)
{
switch
(
t
)
{
case
Background
:
{
...
...
main.cpp
View file @
000430f2
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "GUI.h"
#include "Renderer.h"
// - Esta función callback será llamada cuando GLFW produzca algún error
void
error_callback
(
int
errno
,
const
char
*
desc
)
{
std
::
string
aux
(
desc
);
std
::
cout
<<
"Error de GLFW número "
<<
errno
<<
": "
<<
aux
<<
std
::
endl
;
std
::
string
aux
=
std
::
string
();
aux
.
append
(
"Error de GLFW número "
).
append
(
std
::
to_string
(
errno
)).
append
(
desc
);
std
::
cout
<<
aux
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
aux
);
}
// - Esta función callback será llamada cada vez que el área de dibujo
// OpenGL deba ser redibujada.
void
refresh_window_callback
(
GLFWwindow
*
window
)
{
// Llamada al mét
o
do refrescar del Renderer
// Llamada al mét
0
do refrescar del Renderer
PAG
::
Renderer
::
getInstancia
().
refrescar
();
std
::
cout
<<
"Refresh callback called"
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
"Refresh callback called"
);
}
// - Esta función callback será llamada cada vez que se cambie el tamaño
...
...
@@ -25,6 +27,7 @@ void refresh_window_callback(GLFWwindow *window) {
void
framebuffer_size_callback
(
GLFWwindow
*
window
,
int
width
,
int
height
)
{
PAG
::
Renderer
::
getInstancia
().
refrescar_tamanio_framebuffer
(
width
,
height
);
std
::
cout
<<
"Resize callback called"
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
"Resize callback called"
);
}
// - Esta función callback será llamada cada vez que se pulse una tecla
...
...
@@ -34,17 +37,24 @@ void key_callback(GLFWwindow *window, int key, int scancode, int action, int mod
glfwSetWindowShouldClose
(
window
,
GLFW_TRUE
);
}
std
::
cout
<<
"Key callback called"
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
"Key callback called"
);
}
// - Esta función callback será llamada cada vez que se pulse algún botón
// del ratón sobre el área de dibujo OpenGL.
void
mouse_button_callback
(
GLFWwindow
*
window
,
int
button
,
int
action
,
int
mods
)
{
if
(
action
==
GLFW_PRESS
)
{
std
::
cout
<<
"Pulsado el botón "
<<
button
<<
std
::
endl
;
std
::
string
aux
=
std
::
string
();
aux
.
append
(
"Pulsado el botón "
).
append
(
std
::
to_string
(
button
));
std
::
cout
<<
aux
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
aux
);
PAG
::
GUI
::
getInstancia
().
callback_raton
(
button
,
true
);
}
else
if
(
action
==
GLFW_RELEASE
)
{
std
::
cout
<<
"Soltado el botón "
<<
button
<<
std
::
endl
;
std
::
string
aux
=
std
::
string
();
aux
.
append
(
"Soltado el botón "
).
append
(
std
::
to_string
(
button
));
std
::
cout
<<
aux
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
aux
);
PAG
::
GUI
::
getInstancia
().
callback_raton
(
button
,
false
);
}
refresh_window_callback
(
window
);
...
...
@@ -55,9 +65,13 @@ void mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
void
scroll_callback
(
GLFWwindow
*
window
,
double
xoffset
,
double
yoffset
)
{
refresh_window_callback
(
window
);
std
::
cout
<<
"Movida la rueda del ratón "
<<
xoffset
<<
" unidades en horizontal y "
<<
yoffset
<<
" unidades en vertical"
<<
std
::
endl
;
std
::
string
aux
=
std
::
string
();
aux
.
append
(
"Movida la rueda del ratón "
).
append
(
std
::
to_string
(
xoffset
))
.
append
(
" unidades en horizontal y "
).
append
(
std
::
to_string
(
yoffset
))
.
append
(
" unidades en vertical."
);
std
::
cout
<<
aux
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
aux
);
}
int
main
()
{
...
...
@@ -125,6 +139,12 @@ int main() {
// Inicializamos la GUI a través de ImGui
PAG
::
GUI
::
getInstancia
().
inicializarGUI
(
window
);
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
std
::
string
((
const
char
*
)
glGetString
(
GL_RENDERER
)));
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
std
::
string
((
const
char
*
)
glGetString
(
GL_VENDOR
)));
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
std
::
string
((
const
char
*
)
glGetString
(
GL_VERSION
)));
PAG
::
GUI
::
getInstancia
().
registrarMensaje
(
std
::
string
((
const
char
*
)
glGetString
(
GL_SHADING_LANGUAGE_VERSION
)));
// - Ciclo de eventos de la aplicación. La condición de parada es que la
// ventana principal deba cerrarse. Por ejemplo, si el usuario pulsa el
// botón de cerrar la ventana (la X).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment