|
|
@ -16,81 +16,23 @@ constexpr bool OFFSCREEN = false; |
|
|
|
constexpr const char* OUTPUT_FILENAME = "cube-demo.mkv"; |
|
|
|
constexpr const char* OUTPUT_FILENAME = "cube-demo.mkv"; |
|
|
|
const unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT)); |
|
|
|
const unsigned long DIAG = hypot(double(WIDTH), double(HEIGHT)); |
|
|
|
|
|
|
|
|
|
|
|
const int GLOW_KERNEL_SIZE = std::max(int(DIAG / 138 % 2 == 0 ? DIAG / 138 + 1 : DIAG / 138), |
|
|
|
const int GLOW_KERNEL_SIZE = std::max(int(DIAG / 138 % 2 == 0 ? DIAG / 138 + 1 : DIAG / 138), 1); |
|
|
|
1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::cerr; |
|
|
|
using std::cerr; |
|
|
|
using std::endl; |
|
|
|
using std::endl; |
|
|
|
|
|
|
|
|
|
|
|
cv::Ptr<cv::viz::V4D> v4d = cv::viz::V4D::make(cv::Size(WIDTH, HEIGHT), |
|
|
|
const unsigned int triangles = 12; |
|
|
|
cv::Size(WIDTH, HEIGHT), OFFSCREEN, "Cube Demo"); |
|
|
|
const unsigned int vertices_index = 0; |
|
|
|
|
|
|
|
const unsigned int colors_index = 1; |
|
|
|
GLuint vbo_cube_vertices, vbo_cube_colors; |
|
|
|
unsigned int shader_program; |
|
|
|
GLuint ibo_cube_elements; |
|
|
|
unsigned int vao; |
|
|
|
GLuint program; |
|
|
|
unsigned int uniform_transform; |
|
|
|
GLint attribute_coord3d, attribute_v_color; |
|
|
|
|
|
|
|
GLint uniform_mvp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLuint init_shader(const char* vShader, const char* fShader, const char* outputAttributeName) { |
|
|
|
|
|
|
|
struct Shader { |
|
|
|
|
|
|
|
GLenum type; |
|
|
|
|
|
|
|
const char* source; |
|
|
|
|
|
|
|
} shaders[2] = { { GL_VERTEX_SHADER, vShader }, { GL_FRAGMENT_SHADER, fShader } }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLuint program = glCreateProgram(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) { |
|
|
|
|
|
|
|
Shader& s = shaders[i]; |
|
|
|
|
|
|
|
GLuint shader = glCreateShader(s.type); |
|
|
|
|
|
|
|
glShaderSource(shader, 1, (const GLchar**) &s.source, NULL); |
|
|
|
|
|
|
|
glCompileShader(shader); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLint compiled; |
|
|
|
|
|
|
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); |
|
|
|
|
|
|
|
if (!compiled) { |
|
|
|
|
|
|
|
std::cerr << " failed to compile:" << std::endl; |
|
|
|
|
|
|
|
GLint logSize; |
|
|
|
|
|
|
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logSize); |
|
|
|
|
|
|
|
char* logMsg = new char[logSize]; |
|
|
|
|
|
|
|
glGetShaderInfoLog(shader, logSize, NULL, logMsg); |
|
|
|
|
|
|
|
std::cerr << logMsg << std::endl; |
|
|
|
|
|
|
|
delete[] logMsg; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exit (EXIT_FAILURE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glAttachShader(program, shader); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#ifndef OPENCV_V4D_ES_VERSION |
|
|
|
|
|
|
|
/* Link output */ |
|
|
|
|
|
|
|
glBindFragDataLocation(program, 0, outputAttributeName); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
/* link and error check */ |
|
|
|
|
|
|
|
glLinkProgram(program); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLint linked; |
|
|
|
|
|
|
|
glGetProgramiv(program, GL_LINK_STATUS, &linked); |
|
|
|
|
|
|
|
if (!linked) { |
|
|
|
|
|
|
|
std::cerr << "Shader program failed to link" << std::endl; |
|
|
|
|
|
|
|
GLint logSize; |
|
|
|
|
|
|
|
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logSize); |
|
|
|
|
|
|
|
char* logMsg = new char[logSize]; |
|
|
|
|
|
|
|
glGetProgramInfoLog(program, logSize, NULL, logMsg); |
|
|
|
|
|
|
|
std::cerr << logMsg << std::endl; |
|
|
|
|
|
|
|
delete[] logMsg; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exit (EXIT_FAILURE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* use program object */ |
|
|
|
cv::Ptr<cv::viz::V4D> v4d = cv::viz::V4D::make(cv::Size(WIDTH, HEIGHT), cv::Size(WIDTH, HEIGHT), |
|
|
|
glUseProgram(program); |
|
|
|
OFFSCREEN, "Cube Demo"); |
|
|
|
|
|
|
|
|
|
|
|
return program; |
|
|
|
GLuint load_shader() { |
|
|
|
} |
|
|
|
#ifndef OPENCV_V4D_USE_ES3 |
|
|
|
|
|
|
|
|
|
|
|
//mandelbrot shader code adapted from my own project: https://github.com/kallaballa/FractalDive#after
|
|
|
|
|
|
|
|
void load_shader() { |
|
|
|
|
|
|
|
#ifndef OPENCV_V4D_ES_VERSION |
|
|
|
|
|
|
|
const string shaderVersion = "330"; |
|
|
|
const string shaderVersion = "330"; |
|
|
|
#else |
|
|
|
#else |
|
|
|
const string shaderVersion = "300 es"; |
|
|
|
const string shaderVersion = "300 es"; |
|
|
@ -100,15 +42,15 @@ void load_shader() { |
|
|
|
" #version " + shaderVersion |
|
|
|
" #version " + shaderVersion |
|
|
|
+ R"( |
|
|
|
+ R"( |
|
|
|
precision lowp float; |
|
|
|
precision lowp float; |
|
|
|
layout(location = 0) in vec3 coord3d; |
|
|
|
layout(location = 0) in vec3 pos; |
|
|
|
layout(location = 1) in vec3 v_color; |
|
|
|
layout(location = 1) in vec3 vertex_color; |
|
|
|
|
|
|
|
|
|
|
|
uniform mat4 mvp; |
|
|
|
uniform mat4 transform; |
|
|
|
out vec3 f_color; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main(void) { |
|
|
|
out vec3 color; |
|
|
|
gl_Position = mvp * vec4(coord3d, 1.0); |
|
|
|
void main() { |
|
|
|
f_color = v_color; |
|
|
|
gl_Position = transform * vec4(pos, 1.0); |
|
|
|
|
|
|
|
color = vertex_color; |
|
|
|
} |
|
|
|
} |
|
|
|
)"; |
|
|
|
)"; |
|
|
|
|
|
|
|
|
|
|
@ -116,164 +58,111 @@ void load_shader() { |
|
|
|
" #version " + shaderVersion |
|
|
|
" #version " + shaderVersion |
|
|
|
+ R"( |
|
|
|
+ R"( |
|
|
|
precision lowp float; |
|
|
|
precision lowp float; |
|
|
|
in vec3 f_color; |
|
|
|
in vec3 color; |
|
|
|
out vec4 fragColor; |
|
|
|
|
|
|
|
|
|
|
|
out vec4 frag_color; |
|
|
|
void main(void) { |
|
|
|
|
|
|
|
fragColor = vec4(f_color.r, f_color.g, f_color.b, 1.0); |
|
|
|
void main() { |
|
|
|
|
|
|
|
frag_color = vec4(color, 1.0); |
|
|
|
} |
|
|
|
} |
|
|
|
)"; |
|
|
|
)"; |
|
|
|
|
|
|
|
|
|
|
|
cerr << "##### Cube Vertex Shader #####" << endl; |
|
|
|
return cv::viz::init_shader(vert.c_str(), frag.c_str(), "fragColor"); |
|
|
|
cerr << vert << endl; |
|
|
|
|
|
|
|
cerr << "##### Cube Fragment Shader #####" << endl; |
|
|
|
|
|
|
|
cerr << frag << endl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
program = init_shader(vert.c_str(), frag.c_str(), "fragColor"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int init_resources() { |
|
|
|
void init_scene(const cv::Size& sz) { |
|
|
|
GLfloat cube_vertices[] = { |
|
|
|
glEnable (GL_DEPTH_TEST); |
|
|
|
// front
|
|
|
|
|
|
|
|
-1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, |
|
|
|
float vertices[] = { |
|
|
|
// back
|
|
|
|
// Front face
|
|
|
|
-1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, }; |
|
|
|
0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, |
|
|
|
glGenBuffers(1, &vbo_cube_vertices); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_vertices); |
|
|
|
// Back face
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW); |
|
|
|
0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, }; |
|
|
|
|
|
|
|
|
|
|
|
GLfloat cube_colors[] = { |
|
|
|
float vertex_colors[] = { 1.0, 0.4, 0.6, 1.0, 0.9, 0.2, 0.7, 0.3, 0.8, 0.5, 0.3, 1.0, |
|
|
|
// front colors
|
|
|
|
|
|
|
|
1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, |
|
|
|
0.2, 0.6, 1.0, 0.6, 1.0, 0.4, 0.6, 0.8, 0.8, 0.4, 0.8, 0.8, }; |
|
|
|
// back colors
|
|
|
|
|
|
|
|
1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, }; |
|
|
|
unsigned short triangle_indices[] = { |
|
|
|
glGenBuffers(1, &vbo_cube_colors); |
|
|
|
// Front
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_colors); |
|
|
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_colors), cube_colors, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLushort cube_elements[] = { |
|
|
|
|
|
|
|
// front
|
|
|
|
|
|
|
|
0, 1, 2, 2, 3, 0, |
|
|
|
0, 1, 2, 2, 3, 0, |
|
|
|
// top
|
|
|
|
|
|
|
|
|
|
|
|
// Right
|
|
|
|
|
|
|
|
0, 3, 7, 7, 4, 0, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bottom
|
|
|
|
|
|
|
|
2, 6, 7, 7, 3, 2, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Left
|
|
|
|
1, 5, 6, 6, 2, 1, |
|
|
|
1, 5, 6, 6, 2, 1, |
|
|
|
// back
|
|
|
|
|
|
|
|
7, 6, 5, 5, 4, 7, |
|
|
|
|
|
|
|
// bottom
|
|
|
|
|
|
|
|
4, 0, 3, 3, 7, 4, |
|
|
|
|
|
|
|
// left
|
|
|
|
|
|
|
|
4, 5, 1, 1, 0, 4, |
|
|
|
|
|
|
|
// right
|
|
|
|
|
|
|
|
3, 2, 6, 6, 7, 3, }; |
|
|
|
|
|
|
|
glGenBuffers(1, &ibo_cube_elements); |
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_cube_elements); |
|
|
|
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_elements), cube_elements, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLint link_ok = GL_FALSE; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLuint vs, fs; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
load_shader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* attribute_name; |
|
|
|
|
|
|
|
attribute_name = "coord3d"; |
|
|
|
|
|
|
|
attribute_coord3d = glGetAttribLocation(program, attribute_name); |
|
|
|
|
|
|
|
if (attribute_coord3d == -1) { |
|
|
|
|
|
|
|
fprintf(stderr, "Could not bind attribute %s\n", attribute_name); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
attribute_name = "v_color"; |
|
|
|
|
|
|
|
attribute_v_color = glGetAttribLocation(program, attribute_name); |
|
|
|
|
|
|
|
if (attribute_v_color == -1) { |
|
|
|
|
|
|
|
fprintf(stderr, "Could not bind attribute %s\n", attribute_name); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const char* uniform_name; |
|
|
|
|
|
|
|
uniform_name = "mvp"; |
|
|
|
|
|
|
|
uniform_mvp = glGetUniformLocation(program, uniform_name); |
|
|
|
|
|
|
|
if (uniform_mvp == -1) { |
|
|
|
|
|
|
|
fprintf(stderr, "Could not bind uniform %s\n", uniform_name); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
// Back
|
|
|
|
} |
|
|
|
4, 7, 6, 6, 5, 4, |
|
|
|
|
|
|
|
|
|
|
|
void init_scene(const cv::Size& sz) { |
|
|
|
// Top
|
|
|
|
init_resources(); |
|
|
|
5, 1, 0, 0, 4, 5, }; |
|
|
|
glEnable (GL_BLEND); |
|
|
|
|
|
|
|
glEnable (GL_DEPTH_TEST); |
|
|
|
glGenVertexArrays(1, &vao); |
|
|
|
// glDepthFunc(GL_LESS);
|
|
|
|
glBindVertexArray(vao); |
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
|
|
|
|
|
|
|
|
unsigned int triangles_ebo; |
|
|
|
|
|
|
|
glGenBuffers(1, &triangles_ebo); |
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangles_ebo); |
|
|
|
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof triangle_indices, triangle_indices, |
|
|
|
|
|
|
|
GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int verticies_vbo; |
|
|
|
|
|
|
|
glGenBuffers(1, &verticies_vbo); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, verticies_vbo); |
|
|
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glVertexAttribPointer(vertices_index, 3, GL_FLOAT, GL_FALSE, 0, NULL); |
|
|
|
|
|
|
|
glEnableVertexAttribArray(vertices_index); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int colors_vbo; |
|
|
|
|
|
|
|
glGenBuffers(1, &colors_vbo); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); |
|
|
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof vertex_colors, vertex_colors, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glVertexAttribPointer(colors_index, 3, GL_FLOAT, GL_FALSE, 0, NULL); |
|
|
|
|
|
|
|
glEnableVertexAttribArray(colors_index); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Unbind to prevent accidental modification
|
|
|
|
|
|
|
|
glBindVertexArray(0); |
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shader_program = load_shader(); |
|
|
|
|
|
|
|
uniform_transform = glGetUniformLocation(shader_program, "transform"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void render_scene(const cv::Size& sz) { |
|
|
|
void render_scene(const cv::Size& sz) { |
|
|
|
glClearColor(1.0, 1.0, 1.0, 1.0); |
|
|
|
glClearColor(0.1, 0.12, 0.2, 1); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(program); |
|
|
|
glUseProgram(shader_program); |
|
|
|
|
|
|
|
|
|
|
|
float angle = fmod(double(cv::getTickCount()) / double(cv::getTickFrequency()), 2 * M_PI); |
|
|
|
float angle = fmod(double(cv::getTickCount()) / double(cv::getTickFrequency()), 2 * M_PI); |
|
|
|
float scale = 0.25; |
|
|
|
float scale = 0.25; |
|
|
|
|
|
|
|
|
|
|
|
cv::Matx44f rotXMat( |
|
|
|
cv::Matx44f scaleMat(scale, 0.0, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, |
|
|
|
1.0, 0.0, 0.0, 0.0, |
|
|
|
0.0, 1.0); |
|
|
|
0.0, cos(angle), -sin(angle), 0.0, |
|
|
|
|
|
|
|
0.0, sin(angle), cos(angle), 0.0, |
|
|
|
cv::Matx44f rotXMat(1.0, 0.0, 0.0, 0.0, 0.0, cos(angle), -sin(angle), 0.0, 0.0, sin(angle), |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
cos(angle), 0.0, 0.0, 0.0, 0.0, 1.0); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
cv::Matx44f rotYMat(cos(angle), 0.0, sin(angle), 0.0, 0.0, 1.0, 0.0, 0.0, -sin(angle), 0.0, |
|
|
|
cv::Matx44f rotYMat( |
|
|
|
cos(angle), 0.0, 0.0, 0.0, 0.0, 1.0); |
|
|
|
cos(angle), 0.0, sin(angle), 0.0, |
|
|
|
|
|
|
|
0.0, 1.0, 0.0, 0.0, |
|
|
|
cv::Matx44f rotZMat(cos(angle), -sin(angle), 0.0, 0.0, sin(angle), cos(angle), 0.0, 0.0, 0.0, |
|
|
|
-sin(angle), 0.0, cos(angle), 0.0, |
|
|
|
0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
|
|
|
|
); |
|
|
|
cv::Matx44f transform = scaleMat * rotXMat * rotYMat * rotZMat; |
|
|
|
|
|
|
|
glUniformMatrix4fv(uniform_transform, 1, GL_FALSE, transform.val); |
|
|
|
cv::Matx44f rotZMat( |
|
|
|
glBindVertexArray(vao); |
|
|
|
cos(angle), -sin(angle), 0.0, 0.0, |
|
|
|
glDrawElements(GL_TRIANGLES, triangles * 3, GL_UNSIGNED_SHORT, NULL); |
|
|
|
sin(angle), cos(angle), 0.0, 0.0, |
|
|
|
|
|
|
|
0.0, 0.0, 1.0, 0.0, |
|
|
|
|
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv::Matx44f scaleMat( |
|
|
|
|
|
|
|
scale, 0.0, 0.0, 0.0, |
|
|
|
|
|
|
|
0.0, scale, 0.0, 0.0, |
|
|
|
|
|
|
|
0.0, 0.0, scale, 0.0, |
|
|
|
|
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv::Matx44f trans = scaleMat * rotXMat * rotYMat * rotZMat; |
|
|
|
|
|
|
|
glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, trans.val); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(attribute_coord3d); |
|
|
|
|
|
|
|
// Describe our vertices array to OpenGL (it can't guess its format automatically)
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_vertices); |
|
|
|
|
|
|
|
glVertexAttribPointer(attribute_coord3d, // attribute
|
|
|
|
|
|
|
|
3, // number of elements per vertex, here (x,y,z)
|
|
|
|
|
|
|
|
GL_FLOAT, // the type of each element
|
|
|
|
|
|
|
|
GL_FALSE, // take our values as-is
|
|
|
|
|
|
|
|
0, // no extra data between each position
|
|
|
|
|
|
|
|
0 // offset of first element
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(attribute_v_color); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_colors); |
|
|
|
|
|
|
|
glVertexAttribPointer(attribute_v_color, // attribute
|
|
|
|
|
|
|
|
3, // number of elements per vertex, here (R,G,B)
|
|
|
|
|
|
|
|
GL_FLOAT, // the type of each element
|
|
|
|
|
|
|
|
GL_FALSE, // take our values as-is
|
|
|
|
|
|
|
|
0, // no extra data between each position
|
|
|
|
|
|
|
|
0 // offset of first element
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Push each element in buffer_vertices to the vertex shader */ |
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_cube_elements); |
|
|
|
|
|
|
|
int size; |
|
|
|
|
|
|
|
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); |
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glDisableVertexAttribArray(attribute_coord3d); |
|
|
|
|
|
|
|
glDisableVertexAttribArray(attribute_v_color); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void glow_effect(const cv::UMat& src, cv::UMat& dst, const int ksize) { |
|
|
|
void glow_effect(const cv::UMat& src, cv::UMat& dst, const int ksize) { |
|
|
@ -301,10 +190,10 @@ void glow_effect(const cv::UMat& src, cv::UMat& dst, const int ksize) { |
|
|
|
|
|
|
|
|
|
|
|
bool iteration() { |
|
|
|
bool iteration() { |
|
|
|
using namespace cv::viz; |
|
|
|
using namespace cv::viz; |
|
|
|
|
|
|
|
|
|
|
|
//Render using OpenGL
|
|
|
|
//Render using OpenGL
|
|
|
|
v4d->gl(render_scene); |
|
|
|
v4d->gl(render_scene); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//If we have OpenCL and maybe even CL-GL sharing then this is faster than the glow shader. Without OpenCL this is very slow.
|
|
|
|
//If we have OpenCL and maybe even CL-GL sharing then this is faster than the glow shader. Without OpenCL this is very slow.
|
|
|
|
#ifndef __EMSCRIPTEN__ |
|
|
|
#ifndef __EMSCRIPTEN__ |
|
|
|
//Aquire the frame buffer for use by OpenCL
|
|
|
|
//Aquire the frame buffer for use by OpenCL
|
|
|
@ -314,10 +203,10 @@ bool iteration() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
v4d->write(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateFps(v4d, true); |
|
|
|
updateFps(v4d, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v4d->write(); |
|
|
|
|
|
|
|
|
|
|
|
//If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed.
|
|
|
|
//If onscreen rendering is enabled it displays the framebuffer in the native window. Returns false if the window was closed.
|
|
|
|
if (!v4d->display()) |
|
|
|
if (!v4d->display()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|