Commit 5eabbe31 authored by bbguimaraes's avatar bbguimaraes
Browse files

open.gl: framebuffers

parent b5173bd6
CPPFLAGS = -std=c++11 -I..
OBJECTS = common.o transformations_common.o
OBJECTS = common.o transformations_common.o framebuffers_common.o
all: $(OBJECTS)
common.o: common.h common.cpp
.PHONY: clean
......
CPPFLAGS = -std=c++11 -I..
COMMON = \
../common.h ../common.o \
../framebuffers_common.h ../framebuffers_common.o
LIBRARIES = -lSOIL -lglfw -lGLEW -lGLU -lGL
all: blur framebuffers grayscale invert sobel weighted_gray ex1 ex2
blur: blur.cpp ${COMMON} ${LIBRARIES}
framebuffers: framebuffers.cpp ${COMMON} ${LIBRARIES}
invert: invert.cpp ${COMMON} ${LIBRARIES}
grayscale: grayscale.cpp ${COMMON} ${LIBRARIES}
sobel: sobel.cpp ${COMMON} ${LIBRARIES}
weighted_gray: weighted_gray.cpp ${COMMON} ${LIBRARIES}
ex1: ex1.cpp ${COMMON} ${LIBRARIES}
ex2: ex2.cpp ${COMMON} ${LIBRARIES}
.PHONY: clean
clean:
rm -f blur framebuffers grayscale invert sobel weighted_gray ex1 ex2
#include "framebuffers_common.h"
const GLchar * frag_shader_src_2d =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer;\n"
"\n"
"const float blur_size_h = 1.0 / 300.0;\n"
"const float blur_size_v = 1.0 / 200.0;\n"
"\n"
"void main() {\n"
" vec4 sum = vec4(0.0);\n"
" for(int x = -4; x <= 4; x++)\n"
" for(int y = -4; y <= 4; y++)\n"
" sum += texture(\n"
" tex_frame_buffer,\n"
" vec2(\n"
" Texcoord.x + x * blur_size_h,\n"
" Texcoord.y + y * blur_size_v))\n"
" / 81.0;\n"
" outColor = sum;\n"
"}\n";
int main() {
return framebuffers_main(frag_shader_src_2d);
}
#include "framebuffers_common.h"
#include "common.h"
#include <GLFW/glfw3.h>
const GLchar * frag_shader_src_2d_0 =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer_0;\n"
"\n"
"const float s = 1.0 / 300.0;\n"
"\n"
"void main() {\n"
" vec4 sum = vec4(0.0);\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x - 3 * s, Texcoord.y)) * 0.0009258546453264528;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x - 2 * s, Texcoord.y)) * 0.029464011967309193;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x - 1 * s, Texcoord.y)) * 0.23493154005411251;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y)) * 0.4693438592958032;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x + 1 * s, Texcoord.y)) * 0.23493154005411251;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x + 2 * s, Texcoord.y)) * 0.029464011967309193;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x + 3 * s, Texcoord.y)) * 0.0009258546453264528;\n"
" outColor = sum;\n"
"}\n";
const GLchar * frag_shader_src_2d_1 =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer_0;\n"
"\n"
"const float s = 1.0 / 300.0;\n"
"\n"
"void main() {\n"
" vec4 sum = vec4(0.0);\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y - 3 * s)) * 0.0009258546453264528;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y - 2 * s)) * 0.029464011967309193;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y - 1 * s)) * 0.23493154005411251;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y)) * 0.4693438592958032;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y + 1 * s)) * 0.23493154005411251;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y + 2 * s)) * 0.029464011967309193;\n"
" sum += texture(\n"
" tex_frame_buffer_0,\n"
" vec2(Texcoord.x, Texcoord.y + 3 * s)) * 0.0009258546453264528;\n"
" outColor = sum;\n"
"}\n";
int main() {
GLFWwindow * window = init();
GLuint vao = create_vao();
GLuint vbo = create_vbo(
CUBE_VERTICES_COUNT * sizeof(float), CUBE_VERTICES);
GLuint frame_buffer_0, frame_buffer_1;
GLuint tex_frame_buffer_0, tex_frame_buffer_1;
create_frame_buffer_or_exit(
800, 600, &frame_buffer_0, &tex_frame_buffer_0);
create_frame_buffer_or_exit(
800, 600, &frame_buffer_1, &tex_frame_buffer_1);
GLuint vertex_shader = create_shader_or_exit(
FRAMEBUFFERS_VERTEX_SHADER, GL_VERTEX_SHADER);
GLuint frag_shader = create_shader_or_exit(
FRAMEBUFFERS_FRAG_SHADER, GL_FRAGMENT_SHADER);
GLuint program = create_program(vertex_shader, frag_shader);
setup_shader_attrs(program);
GLint tex_kitten = create_texture_from_image("../sample.png", GL_TEXTURE0);
glUniform1i(glGetUniformLocation(program, "texKitten"), 0);
GLint tex_puppy = create_texture_from_image("../sample2.png", GL_TEXTURE1);
glUniform1i(glGetUniformLocation(program, "texPuppy"), 1);
GLint ov_col_uni = glGetUniformLocation(program, "overrideColor");
setup_projection(program);
GLint model_uni = glGetUniformLocation(program, "model");
GLuint vao_2d_0 = create_vao();
GLuint vbo_2d_0 = create_vbo(
VERTICES_COUNT * sizeof(float), VERTICES);
GLuint vertex_shader_2d_0 = create_shader_or_exit(
FRAMEBUFFERS_VERTEX_SHADER_2D, GL_VERTEX_SHADER);
GLuint frag_shader_2d_0 = create_shader_or_exit(
frag_shader_src_2d_0, GL_FRAGMENT_SHADER);
GLuint program_2d_0 = create_program(vertex_shader_2d_0, frag_shader_2d_0);
GLint pos_attr_2d_0 = glGetAttribLocation(program_2d_0, "position");
glEnableVertexAttribArray(pos_attr_2d_0);
glVertexAttribPointer(
pos_attr_2d_0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
GLint tex_attr_2d_0 = glGetAttribLocation(program_2d_0, "texcoord");
glEnableVertexAttribArray(tex_attr_2d_0);
glVertexAttribPointer(
tex_attr_2d_0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
reinterpret_cast<void *>(2 * sizeof(float)));
glUniform1i(
glGetUniformLocation(program, "tex_frame_buffer_0"),
0);
GLuint vao_2d_1 = create_vao();
GLuint vbo_2d_1 = create_vbo(
VERTICES_COUNT * sizeof(float), VERTICES);
GLuint vertex_shader_2d_1 = create_shader_or_exit(
FRAMEBUFFERS_VERTEX_SHADER_2D, GL_VERTEX_SHADER);
GLuint frag_shader_2d_1 = create_shader_or_exit(
frag_shader_src_2d_1, GL_FRAGMENT_SHADER);
GLuint program_2d_1 = create_program(vertex_shader_2d_1, frag_shader_2d_1);
GLint pos_attr_2d_1 = glGetAttribLocation(program_2d_1, "position");
glEnableVertexAttribArray(pos_attr_2d_1);
glVertexAttribPointer(
pos_attr_2d_1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
GLint tex_attr_2d_1 = glGetAttribLocation(program_2d_1, "texcoord");
glEnableVertexAttribArray(tex_attr_2d_1);
glVertexAttribPointer(
tex_attr_2d_1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
reinterpret_cast<void *>(2 * sizeof(float)));
glUniform1i(
glGetUniformLocation(program, "tex_frame_buffer_1"),
0);
while(!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer_0);
glBindVertexArray(vao);
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_kitten);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex_puppy);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float angle = generate_angle(
static_cast<float>(std::clock()),
static_cast<float>(CLOCKS_PER_SEC));
draw_scene(angle, model_uni, ov_col_uni);
glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer_1);
glBindVertexArray(vao_2d_0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_frame_buffer_0);
glUseProgram(program_2d_0);
glBindBuffer(GL_ARRAY_BUFFER, vbo_2d_0);
glDisable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindVertexArray(vao_2d_1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_frame_buffer_1);
glUseProgram(program_2d_1);
glBindBuffer(GL_ARRAY_BUFFER, vbo_2d_1);
glDisable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLES, 0, 6);
exit_on_gl_error();
}
glfwTerminate();
return 0;
}
#include "framebuffers_common.h"
#include "common.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <GLFW/glfw3.h>
const unsigned int vertices_count = 30;
const float vertices[] = {
// pos texcoords
1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
};
const GLchar * framebuffers_vertex_shader_2d =
"#version 150 core\n"
"in vec3 position;\n"
"in vec2 texcoord;\n"
"out vec2 Texcoord;\n"
"uniform mat4 proj;\n"
"uniform mat4 view;\n"
"void main() {\n"
" Texcoord = texcoord;\n"
" gl_Position = proj * view * vec4(position, 1.0);\n"
"}\n";
const GLchar * frag_shader_src_2d =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer;\n"
"\n"
"void main() {\n"
" outColor = texture(tex_frame_buffer, Texcoord);\n"
"}\n";
int main() {
GLFWwindow * window = init();
GLuint vao = create_vao();
GLuint vbo = create_vbo(
CUBE_VERTICES_COUNT * sizeof(float), CUBE_VERTICES);
GLuint frame_buffer, tex_frame_buffer;
create_frame_buffer_or_exit(800, 600, &frame_buffer, &tex_frame_buffer);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLuint vertex_shader = create_shader_or_exit(
FRAMEBUFFERS_VERTEX_SHADER, GL_VERTEX_SHADER);
GLuint frag_shader = create_shader_or_exit(
FRAMEBUFFERS_FRAG_SHADER, GL_FRAGMENT_SHADER);
GLuint program = create_program(vertex_shader, frag_shader);
setup_shader_attrs(program);
GLint tex_kitten = create_texture_from_image("../sample.png", GL_TEXTURE0);
glUniform1i(glGetUniformLocation(program, "texKitten"), 0);
GLint tex_puppy = create_texture_from_image("../sample2.png", GL_TEXTURE1);
glUniform1i(glGetUniformLocation(program, "texPuppy"), 1);
GLint ov_col_uni = glGetUniformLocation(program, "overrideColor");
setup_projection(program);
GLint model_uni = glGetUniformLocation(program, "model");
GLuint view_uni = glGetUniformLocation(program, "view");
GLuint vao_2d = create_vao();
GLuint vbo_2d = create_vbo(
vertices_count * sizeof(float), vertices);
GLuint vertex_shader_2d = create_shader_or_exit(
framebuffers_vertex_shader_2d, GL_VERTEX_SHADER);
GLuint frag_shader_2d = create_shader_or_exit(
frag_shader_src_2d, GL_FRAGMENT_SHADER);
GLuint program_2d = create_program(vertex_shader_2d, frag_shader_2d);
GLint pos_attr_2d = glGetAttribLocation(program_2d, "position");
glEnableVertexAttribArray(pos_attr_2d);
glVertexAttribPointer(
pos_attr_2d, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 0);
GLint tex_attr_2d = glGetAttribLocation(program_2d, "texcoord");
glEnableVertexAttribArray(tex_attr_2d);
glVertexAttribPointer(
tex_attr_2d, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float),
reinterpret_cast<void *>(3 * sizeof(float)));
glUniform1i(
glGetUniformLocation(program, "tex_frame_buffer"),
0);
glm::mat4 proj = glm::perspective(45.0f, 800.0f / 600.0f, 1.0f, 10.0f);
GLint proj_uni = glGetUniformLocation(program_2d, "proj");
glUniformMatrix4fv(proj_uni, 1, GL_FALSE, glm::value_ptr(proj));
glm::mat4 view = glm::lookAt(
glm::vec3(0.0f, 0.0f, 2.0f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
GLuint view_uni_2d = glGetUniformLocation(program_2d, "view");
glUniformMatrix4fv(view_uni_2d, 1, GL_FALSE, glm::value_ptr(view));
while(!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer);
glBindVertexArray(vao);
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_kitten);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex_puppy);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float angle = generate_angle(
static_cast<float>(std::clock()),
static_cast<float>(CLOCKS_PER_SEC));
glm::mat4 view = glm::lookAt(
glm::vec3(2.0f, 2.0f, -0.25f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
glUniformMatrix4fv(view_uni, 1, GL_FALSE, glm::value_ptr(view));
draw_scene(angle, model_uni, ov_col_uni);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
view = glm::lookAt(
glm::vec3(1.2f, 1.2f, 1.2f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
glUniformMatrix4fv(view_uni, 1, GL_FALSE, glm::value_ptr(view));
draw_scene(angle, model_uni, ov_col_uni);
glBindVertexArray(vao_2d);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_frame_buffer);
glUseProgram(program_2d);
glBindBuffer(GL_ARRAY_BUFFER, vbo_2d);
glDisable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLES, 0, 6);
exit_on_gl_error();
}
glfwTerminate();
return 0;
}
#include "framebuffers_common.h"
const GLchar * frag_shader_src_2d =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer;\n"
"\n"
"void main() {\n"
" outColor = texture(tex_frame_buffer, Texcoord);\n"
"}\n";
int main() {
return framebuffers_main(frag_shader_src_2d);
}
#include "framebuffers_common.h"
const GLchar * frag_shader_src_2d =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer;\n"
"\n"
"void main() {\n"
" outColor = texture(tex_frame_buffer, Texcoord);\n"
" float color = (outColor.x + outColor.y + outColor.z) / 3.0;\n"
" outColor = vec4(color, color, color, 1.0);\n"
"}\n";
int main() {
return framebuffers_main(frag_shader_src_2d);
}
#include "framebuffers_common.h"
const GLchar * frag_shader_src_2d =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer;\n"
"\n"
"void main() {\n"
" outColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
" - texture(tex_frame_buffer, Texcoord);\n"
"}\n";
int main() {
return framebuffers_main(frag_shader_src_2d);
}
#include "common.h"
#include "framebuffers_common.h"
const GLchar * frag_shader_src_2d =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer;\n"
"\n"
"void main() {\n"
" vec4 s1 = texture(\n"
" tex_frame_buffer, Texcoord - 1.0 / 300.0 - 1.0 / 200.0);\n"
" vec4 s2 = texture(\n"
" tex_frame_buffer, Texcoord + 1.0 / 300.0 - 1.0 / 200.0);\n"
" vec4 s3 = texture(\n"
" tex_frame_buffer, Texcoord - 1.0 / 300.0 + 1.0 / 200.0);\n"
" vec4 s4 = texture(\n"
" tex_frame_buffer, Texcoord + 1.0 / 300.0 + 1.0 / 200.0);\n"
" vec4 sx = 4.0 * ((s4 + s3) - (s2 + s1));\n"
" vec4 sy = 4.0 * ((s2 + s4) - (s1 + s3));\n"
" vec4 sobel = sqrt(sx * sx + sy * sy);\n"
" outColor = sobel;\n"
"}\n";
int main() {
return framebuffers_main(frag_shader_src_2d);
}
#include "framebuffers_common.h"
const GLchar * frag_shader_src_2d =
"#version 150 core\n"
"\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D tex_frame_buffer;\n"
"\n"
"void main() {\n"
" outColor = texture(tex_frame_buffer, Texcoord);\n"
" float color = 0.2126 * outColor.x\n"
" + 0.7152 * outColor.y\n"
" + 0.0722 * outColor.z;\n"
" outColor = vec4(color, color, color, 1.0);\n"
"}\n";
int main() {
return framebuffers_main(frag_shader_src_2d);
}
#include "framebuffers_common.h"
#include "common.h"
#include <ctime> // clock, CLOCKS_PER_SEC
#include <iostream> // cout, endl
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <SOIL/SOIL.h>
#include <GLFW/glfw3.h>
const GLchar * FRAMEBUFFERS_VERTEX_SHADER =
"#version 150 core\n"
"\n"
"in vec3 position;\n"
"in vec3 color;\n"
"in vec2 texcoord;\n"
"\n"
"out vec3 Color;\n"
"out vec2 Texcoord;\n"
"\n"
"uniform vec3 overrideColor;\n"
"uniform mat4 model;\n"
"uniform mat4 view;\n"
"uniform mat4 proj;\n"
"\n"
"void main() {\n"
" Color = overrideColor * color;\n"
" Texcoord = texcoord;\n"
" gl_Position = proj * view * model * vec4(position, 1.0);\n"
"}\n";
const GLchar * FRAMEBUFFERS_FRAG_SHADER =
"#version 150 core\n"
"\n"
"in vec3 Color;\n"
"in vec2 Texcoord;\n"
"\n"
"out vec4 outColor;\n"
"\n"
"uniform sampler2D texKitten;\n"
"uniform sampler2D texPuppy;\n"
"\n"
"void main() {\n"
" vec4 texColor = mix(\n"
" texture(texKitten, Texcoord),\n"
" texture(texPuppy, Texcoord),\n"
" 0.5);\n"
" outColor = vec4(Color, 1.0) * texColor;\n"
"}\n";
const GLchar * FRAMEBUFFERS_VERTEX_SHADER_2D =
"#version 150 core\n"
"in vec2 position;\n"
"in vec2 texcoord;\n"
"out vec2 Texcoord;\n"
"void main() {\n"
" Texcoord = texcoord;\n"
" gl_Position = vec4(position, 0.0, 1.0);\n"
"}\n";
const unsigned int VERTICES_COUNT = 24;
const float VERTICES[] = {
// pos texcoords
-1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 1.0f,
};
void setup_shader_attrs(GLuint program) {
GLint pos_attr = glGetAttribLocation(program, "position");
glEnableVertexAttribArray(pos_attr);
glVertexAttribPointer(
pos_attr, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), 0);
GLint color_attr = glGetAttribLocation(program, "color");
glEnableVertexAttribArray(color_attr);
glVertexAttribPointer(
color_attr, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
reinterpret_cast<void *>(3 * sizeof(float)));
GLint tex_attr = glGetAttribLocation(program, "texcoord");
glEnableVertexAttribArray(tex_attr);
glVertexAttribPointer(
tex_attr, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
reinterpret_cast<void *>(6 * sizeof(float)));
}
void create_frame_buffer_or_exit(
unsigned int width, unsigned int height, GLuint * id, GLuint *tex) {
create_frame_buffer(width, height, id, tex);
if(check_frame_buffer(*id))
return;
std::cerr << "glCheckFramebufferStatus: not complete" << std::endl;
std::exit(1);
}
void create_frame_buffer(
unsigned int width, unsigned int height, GLuint * id, GLuint *tex) {
glGenFramebuffers(1, id);
glBindFramebuffer(GL_FRAMEBUFFER, *id);
glGenTextures(1, tex);