Apartado 4.1 practica 3: Colores con VBO no entrelazados

parent 700e68fb
#version 410 #version 410
in vec4 destinationColor;
out vec4 colorFragmento; out vec4 colorFragmento;
void main() { void main() {
colorFragmento = vec4(1.0, .4, .2, 1.0); colorFragmento = destinationColor;
} }
#version 410 #version 410
layout (location = 0) in vec3 posicion; layout (location = 0) in vec3 posicion;
layout (location = 1) in vec3 color;
out vec4 destinationColor;
void main() { void main() {
destinationColor = vec4(color, 1);
gl_Position = vec4(posicion, 1); gl_Position = vec4(posicion, 1);
} }
...@@ -213,15 +213,29 @@ namespace PAG { ...@@ -213,15 +213,29 @@ namespace PAG {
0.5, -0.5, 0, 0.5, -0.5, 0,
0 , 0.5, 0 0 , 0.5, 0
}; };
GLfloat colores[] = {
1, 0, 0,
0, 1, 0,
0, 0, 1
};
GLuint indices[] = {0, 1, 2}; GLuint indices[] = {0, 1, 2};
glGenVertexArrays(1, &idVAO); glGenVertexArrays(1, &idVAO);
glBindVertexArray(idVAO); glBindVertexArray(idVAO);
glGenBuffers(1, &idVBO); glGenBuffers(2, idVBO);
glBindBuffer(GL_ARRAY_BUFFER, idVBO);
// Vertices
glBindBuffer(GL_ARRAY_BUFFER, idVBO[0]);
glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLfloat), vertices, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), nullptr); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), nullptr);
glEnableVertexAttribArray(0); 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); glGenBuffers(1, &idIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idIBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3*sizeof(GLuint), indices, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3*sizeof(GLuint), indices, GL_STATIC_DRAW);
...@@ -230,23 +244,12 @@ namespace PAG { ...@@ -230,23 +244,12 @@ namespace PAG {
Renderer::Renderer() {}; Renderer::Renderer() {};
Renderer::~Renderer() { Renderer::~Renderer() {
if (idVS) { // OpenGL ignora la llamada si está a 0
glDeleteShader(idVS); glDeleteShader(idVS);
} glDeleteShader(idFS);
if (idFS) { glDeleteProgram(idSP);
glDeleteShader(idFS); glDeleteBuffers(2, idVBO);
} glDeleteBuffers(1, &idIBO);
if (idSP) { glDeleteVertexArrays(1, &idVAO);
glDeleteProgram(idSP);
}
if (idVBO) {
glDeleteBuffers(1, &idVBO);
}
if (idIBO) {
glDeleteBuffers(1, &idIBO);
}
if (idVAO) {
glDeleteVertexArrays(1, &idVAO);
}
}; };
} }
...@@ -39,7 +39,8 @@ namespace PAG { ...@@ -39,7 +39,8 @@ namespace PAG {
GLuint idFS = 0; GLuint idFS = 0;
GLuint idSP = 0; GLuint idSP = 0;
GLuint idVAO = 0; GLuint idVAO = 0;
GLuint idVBO = 0; //GLuint idVBO = 0;
GLuint idVBO[2] = {0, 0};
GLuint idIBO = 0; GLuint idIBO = 0;
Renderer(); Renderer();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment