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
a550f857
authored
Sep 17, 2025
by
José Pardo Madera
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Movido todas la funciones OpenGL que llama main al singleton renderer
parent
c4b78bdc
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
11 deletions
main.cpp
make.sh
renderer.cpp
renderer.h
main.cpp
View file @
a550f857
...
...
@@ -5,6 +5,8 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "renderer.h"
// Helper que muestra un mensaje y cierra el programa
#define panic(message) { \
std::cout << __FILE__ << ":" << __LINE__ << " : panic!" << std::endl;\
...
...
@@ -18,7 +20,7 @@ void error_callback(int errno, const char *desc) {
}
void
window_refresh_callback
(
GLFWwindow
*
window
)
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
PAG
::
Renderer
::
getInstance
().
clear
(
);
glfwSwapBuffers
(
window
);
...
...
@@ -26,7 +28,8 @@ void window_refresh_callback(GLFWwindow *window) {
}
void
framebuffer_size_callback
(
GLFWwindow
*
window
,
int
width
,
int
height
)
{
glViewport
(
0
,
0
,
width
,
height
);
PAG
::
Renderer
::
getInstance
().
setViewport
(
width
,
height
);
std
::
cout
<<
"Resize callback called. New size: "
<<
width
<<
", "
<<
height
<<
std
::
endl
;
}
...
...
@@ -66,7 +69,7 @@ void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) {
double
a
=
(
1
-
position_in_gradient
);
double
b
=
position_in_gradient
;
gl
ClearColor
(
PAG
::
Renderer
::
getInstance
().
set
ClearColor
(
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
,
...
...
@@ -104,10 +107,12 @@ int main() {
panic
(
"GLAD initialization failed"
);
}
std
::
cout
<<
glGetString
(
GL_RENDERER
)
<<
std
::
endl
;
std
::
cout
<<
glGetString
(
GL_VENDOR
)
<<
std
::
endl
;
std
::
cout
<<
glGetString
(
GL_VERSION
)
<<
std
::
endl
;
std
::
cout
<<
glGetString
(
GL_SHADING_LANGUAGE_VERSION
)
<<
std
::
endl
;
auto
&
renderer
=
PAG
::
Renderer
::
getInstance
();
std
::
cout
<<
renderer
.
getRendererName
()
<<
std
::
endl
;
std
::
cout
<<
renderer
.
getVendor
()
<<
std
::
endl
;
std
::
cout
<<
renderer
.
getVersion
()
<<
std
::
endl
;
std
::
cout
<<
renderer
.
getShadingLanguageVersion
()
<<
std
::
endl
;
glfwSetWindowRefreshCallback
(
window
,
window_refresh_callback
);
glfwSetFramebufferSizeCallback
(
window
,
framebuffer_size_callback
);
...
...
@@ -116,12 +121,12 @@ int main() {
glfwSetScrollCallback
(
window
,
scroll_callback
);
gl
ClearColor
(
0.6
,
0.6
,
0.6
,
1.0
);
renderer
.
set
ClearColor
(
0.6
,
0.6
,
0.6
,
1.0
);
glEnable
(
GL_DEPTH_TEST
);
renderer
.
enableDepthTest
(
);
while
(
!
glfwWindowShouldClose
(
window
))
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
renderer
.
clear
(
);
glfwSwapBuffers
(
window
);
...
...
make.sh
View file @
a550f857
...
...
@@ -6,7 +6,7 @@ die() {
PROJECT_NAME
=
pr01
mkdir build
mkdir
-p
build
cmake
-B
build/
.
...
...
renderer.cpp
0 → 100644
View file @
a550f857
#include "renderer.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
namespace
PAG
{
// Basado en https://stackoverflow.com/a/1008289
Renderer
&
Renderer
::
getInstance
()
{
// Inicialización lazy por defecto
static
Renderer
instance
;
return
instance
;
}
void
Renderer
::
clear
()
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
}
void
Renderer
::
setClearColor
(
float
r
,
float
g
,
float
b
,
float
a
)
{
glClearColor
(
r
,
g
,
b
,
a
);
}
void
Renderer
::
setViewport
(
int
width
,
int
height
)
{
glViewport
(
0
,
0
,
width
,
height
);
}
void
Renderer
::
enableDepthTest
()
{
glEnable
(
GL_DEPTH_TEST
);
}
std
::
string
Renderer
::
getRendererName
()
{
return
std
::
string
((
const
char
*
)
glGetString
(
GL_RENDERER
));
}
std
::
string
Renderer
::
getVendor
()
{
return
std
::
string
((
const
char
*
)
glGetString
(
GL_VENDOR
));
}
std
::
string
Renderer
::
getVersion
()
{
return
std
::
string
((
const
char
*
)
glGetString
(
GL_VERSION
));
}
std
::
string
Renderer
::
getShadingLanguageVersion
()
{
return
std
::
string
((
const
char
*
)
glGetString
(
GL_SHADING_LANGUAGE_VERSION
));
}
Renderer
::
Renderer
()
{};
Renderer
::~
Renderer
()
{};
}
renderer.h
0 → 100644
View file @
a550f857
#pragma once
#include <string>
namespace
PAG
{
class
Renderer
{
public
:
static
Renderer
&
getInstance
();
// No hay constructores de copia
Renderer
(
const
Renderer
&
)
=
delete
;
void
operator
=
(
const
Renderer
&
)
=
delete
;
// Funciones de opengl
void
clear
();
void
setClearColor
(
float
,
float
,
float
,
float
);
void
setViewport
(
int
width
,
int
height
);
void
enableDepthTest
();
std
::
string
getRendererName
();
std
::
string
getVendor
();
std
::
string
getVersion
();
std
::
string
getShadingLanguageVersion
();
private
:
Renderer
();
~
Renderer
();
};
};
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