Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
José Pardo Madera
/
pag_practicas_2025
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
40028a80
authored
Sep 18, 2025
by
José Pardo Madera
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Implementado ventana de selección de color de fondo
parent
a0c58661
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
23 deletions
main.cpp
renderer.cpp
renderer.h
ventana.h
ventana_color.cpp
ventana_color.h
main.cpp
View file @
40028a80
...
...
@@ -9,6 +9,7 @@
#include "gui.h"
#include "log.h"
#include "ventana_log.h"
#include "ventana_color.h"
// Helper que muestra un mensaje y cierra el programa
#define panic(message) { \
...
...
@@ -53,33 +54,12 @@ void mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
}
}
const
double
gradient_step
=
0.05
;
const
double
gradient_colors
[][
3
]
=
{{
0.6
,
0.6
,
0.6
},
{
1
,
0.65
,
0
}};
void
scroll_callback
(
GLFWwindow
*
window
,
double
xoffset
,
double
yoffset
)
{
static
double
position_in_gradient
=
0
;
PAG
::
log
<<
"Movida la rueda del raton "
<<
xoffset
<<
" unidades en horizontal y "
<<
yoffset
<<
" unidades en vertical"
<<
std
::
endl
;
position_in_gradient
+=
yoffset
*
gradient_step
;
if
(
position_in_gradient
>
1
)
{
position_in_gradient
=
1
;
}
else
if
(
position_in_gradient
<
0
)
{
position_in_gradient
=
0
;
}
double
a
=
(
1
-
position_in_gradient
);
double
b
=
position_in_gradient
;
PAG
::
Renderer
::
getInstance
().
setClearColor
(
gradient_colors
[
0
][
0
]
*
a
+
gradient_colors
[
1
][
0
]
*
b
,
gradient_colors
[
0
][
1
]
*
a
+
gradient_colors
[
1
][
1
]
*
b
,
gradient_colors
[
0
][
2
]
*
a
+
gradient_colors
[
1
][
2
]
*
b
,
1.0
);
}
int
main
()
{
...
...
@@ -115,6 +95,10 @@ int main() {
PAG
::
GUI
::
getInstance
().
init
(
window
);
PAG
::
GUI
::
getInstance
().
addVentana
(
std
::
make_shared
<
PAG
::
VentanaLog
>
(
PAG
::
VentanaLog
()));
auto
ventana_color
=
std
::
make_shared
<
PAG
::
VentanaColor
>
(
PAG
::
VentanaColor
());
ventana_color
->
addListener
(
&
PAG
::
Renderer
::
getInstance
());
PAG
::
GUI
::
getInstance
().
addVentana
(
ventana_color
);
auto
&
renderer
=
PAG
::
Renderer
::
getInstance
();
PAG
::
log
<<
renderer
.
getRendererName
()
<<
std
::
endl
;
...
...
@@ -129,7 +113,7 @@ int main() {
glfwSetScrollCallback
(
window
,
scroll_callback
);
renderer
.
setClearColor
(
0.6
,
0.6
,
0.6
,
1.0
);
renderer
.
setClearColor
(
ventana_color
->
getColor
()
);
renderer
.
enableDepthTest
();
...
...
renderer.cpp
View file @
40028a80
...
...
@@ -3,6 +3,8 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "ventana_color.h"
namespace
PAG
{
// Basado en https://stackoverflow.com/a/1008289
Renderer
&
Renderer
::
getInstance
()
{
...
...
@@ -16,6 +18,10 @@ namespace PAG {
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
}
void
Renderer
::
setClearColor
(
std
::
array
<
float
,
3
>
rgb
)
{
setClearColor
(
rgb
[
0
],
rgb
[
1
],
rgb
[
2
],
1
);
}
void
Renderer
::
setClearColor
(
float
r
,
float
g
,
float
b
,
float
a
)
{
glClearColor
(
r
,
g
,
b
,
a
);
}
...
...
@@ -41,6 +47,13 @@ namespace PAG {
return
std
::
string
((
const
char
*
)
glGetString
(
GL_SHADING_LANGUAGE_VERSION
));
}
void
Renderer
::
wakeUp
(
Ventana
&
ventana
)
{
if
(
dynamic_cast
<
VentanaColor
*>
(
&
ventana
))
{
auto
ventana_color
=
dynamic_cast
<
VentanaColor
&>
(
ventana
);
setClearColor
(
ventana_color
.
getColor
());
}
}
Renderer
::
Renderer
()
{};
Renderer
::~
Renderer
()
{};
...
...
renderer.h
View file @
40028a80
#pragma once
#include <string>
#include <array>
#include "ventana.h"
namespace
PAG
{
class
Renderer
{
class
Renderer
:
public
PAG
::
Ventana
::
Listener
{
public
:
static
Renderer
&
getInstance
();
...
...
@@ -13,6 +16,7 @@ namespace PAG {
// Funciones de opengl
void
clear
();
void
setClearColor
(
std
::
array
<
float
,
3
>
rgb
);
void
setClearColor
(
float
,
float
,
float
,
float
);
void
setViewport
(
int
width
,
int
height
);
...
...
@@ -22,6 +26,8 @@ namespace PAG {
std
::
string
getVendor
();
std
::
string
getVersion
();
std
::
string
getShadingLanguageVersion
();
void
wakeUp
(
Ventana
&
)
override
;
private
:
Renderer
();
~
Renderer
();
...
...
ventana.h
View file @
40028a80
#pragma once
#include <vector>
namespace
PAG
{
class
Ventana
{
public
:
virtual
void
render
()
=
0
;
virtual
~
Ventana
()
=
default
;
class
Listener
{
public
:
virtual
void
wakeUp
(
Ventana
&
)
=
0
;
virtual
~
Listener
()
=
default
;
};
void
addListener
(
Listener
*
listener
)
{
listeners
.
push_back
(
listener
);
};
protected
:
void
notifyListeners
()
{
for
(
auto
listener
:
listeners
)
{
listener
->
wakeUp
(
*
this
);
}
};
std
::
vector
<
Listener
*>
listeners
;
};
}
ventana_color.cpp
0 → 100644
View file @
40028a80
#include "ventana_color.h"
#include <imgui.h>
namespace
PAG
{
void
VentanaColor
::
render
()
{
ImGui
::
SetNextWindowPos
(
ImVec2
(
670
,
110
),
ImGuiCond_FirstUseEver
);
ImGui
::
ColorPicker3
(
"Color"
,
color
.
data
(),
ImGuiColorEditFlags_PickerHueWheel
);
if
(
ImGui
::
IsItemEdited
())
{
notifyListeners
();
}
}
std
::
array
<
float
,
3
>
VentanaColor
::
getColor
()
{
return
color
;
}
}
ventana_color.h
0 → 100644
View file @
40028a80
#pragma once
#include "ventana.h"
#include <array>
namespace
PAG
{
class
VentanaColor
:
public
Ventana
{
public
:
void
render
()
override
;
std
::
array
<
float
,
3
>
getColor
();
private
:
std
::
array
<
float
,
3
>
color
=
{
0
.
6
,
0
.
6
,
0
.
6
};
};
}
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