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
221f238d
authored
Sep 26, 2025
by
José Pardo Madera
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Apartado 4.1 practica 3: Colores con VBO no entrelazados
parent
700e68fb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
22 deletions
pag03-fs.glsl
pag03-vs.glsl
renderer.cpp
renderer.h
pag03-fs.glsl
View file @
221f238d
#version 410
in
vec4
destinationColor
;
out
vec4
colorFragmento
;
void
main
()
{
colorFragmento
=
vec4
(
1
.
0
,
.
4
,
.
2
,
1
.
0
)
;
colorFragmento
=
destinationColor
;
}
pag03-vs.glsl
View file @
221f238d
#version 410
layout
(
location
=
0
)
in
vec3
posicion
;
layout
(
location
=
1
)
in
vec3
color
;
out
vec4
destinationColor
;
void
main
()
{
destinationColor
=
vec4
(
color
,
1
);
gl_Position
=
vec4
(
posicion
,
1
);
}
renderer.cpp
View file @
221f238d
...
...
@@ -213,15 +213,29 @@ namespace PAG {
0.5
,
-
0.5
,
0
,
0
,
0.5
,
0
};
GLfloat
colores
[]
=
{
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
};
GLuint
indices
[]
=
{
0
,
1
,
2
};
glGenVertexArrays
(
1
,
&
idVAO
);
glBindVertexArray
(
idVAO
);
glGenBuffers
(
1
,
&
idVBO
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
idVBO
);
glGenBuffers
(
2
,
idVBO
);
// Vertices
glBindBuffer
(
GL_ARRAY_BUFFER
,
idVBO
[
0
]);
glBufferData
(
GL_ARRAY_BUFFER
,
9
*
sizeof
(
GLfloat
),
vertices
,
GL_STATIC_DRAW
);
glVertexAttribPointer
(
0
,
3
,
GL_FLOAT
,
GL_FALSE
,
3
*
sizeof
(
GLfloat
),
nullptr
);
glEnableVertexAttribArray
(
0
);
// Colores
glBindBuffer
(
GL_ARRAY_BUFFER
,
idVBO
[
1
]);
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
colores
),
colores
,
GL_STATIC_DRAW
);
glVertexAttribPointer
(
1
,
3
,
GL_FLOAT
,
GL_FALSE
,
3
*
sizeof
(
GLfloat
),
nullptr
);
glEnableVertexAttribArray
(
1
);
glGenBuffers
(
1
,
&
idIBO
);
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
idIBO
);
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
3
*
sizeof
(
GLuint
),
indices
,
GL_STATIC_DRAW
);
...
...
@@ -230,23 +244,12 @@ namespace PAG {
Renderer
::
Renderer
()
{};
Renderer
::~
Renderer
()
{
if
(
idVS
)
{
glDeleteShader
(
idVS
);
}
if
(
idFS
)
{
glDeleteShader
(
idFS
);
}
if
(
idSP
)
{
glDeleteProgram
(
idSP
);
}
if
(
idVBO
)
{
glDeleteBuffers
(
1
,
&
idVBO
);
}
if
(
idIBO
)
{
glDeleteBuffers
(
1
,
&
idIBO
);
}
if
(
idVAO
)
{
glDeleteVertexArrays
(
1
,
&
idVAO
);
}
// OpenGL ignora la llamada si está a 0
glDeleteShader
(
idVS
);
glDeleteShader
(
idFS
);
glDeleteProgram
(
idSP
);
glDeleteBuffers
(
2
,
idVBO
);
glDeleteBuffers
(
1
,
&
idIBO
);
glDeleteVertexArrays
(
1
,
&
idVAO
);
};
}
renderer.h
View file @
221f238d
...
...
@@ -39,7 +39,8 @@ namespace PAG {
GLuint
idFS
=
0
;
GLuint
idSP
=
0
;
GLuint
idVAO
=
0
;
GLuint
idVBO
=
0
;
//GLuint idVBO = 0;
GLuint
idVBO
[
2
]
=
{
0
,
0
};
GLuint
idIBO
=
0
;
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