Commit 53386599 authored by Sabrina Templeton's avatar Sabrina Templeton
Browse files

some progress to something that works

parent d56fd213
......@@ -89,6 +89,12 @@ ShaderProgram::ShaderProgram( const std::string& name , bool with_tess , const s
std::string geo_src = get_shader_src( base + "-geo.glsl" );
avro_assert_msg( compile(name_.c_str(),vtx_src,frg_src,geo_src) , "error compiling raytracer shader" );
}
else if (name == "voronoi") {
std::string vtx_src = get_shader_src( base + "-vtx.glsl" );
std::string frg_src = get_shader_src( base + "-frg.glsl" );
std::string geo_src = get_shader_src( base + "-geo.glsl" );
avro_assert_msg( compile(name_.c_str(),vtx_src,frg_src,geo_src) , "error compiling voronoi shader" );
}
else {
printf("unknown shader %s\n",name.c_str());
avro_assert_not_reached;
......
// the version should be specified by a macro at compile time
// e.g. #version 410 or #version 330
#version 410
layout( location = 0 ) out vec4 fragColor;
void main() {
vec3 color = vec3(.8, .2, .8);
fragColor = vec4(color, 1);
}
\ No newline at end of file
// the version should be specified by a macro at compile time
// e.g. #version 410 or #version 330
#version 410
// layout (points) in;
// uniform mat4 u_ModelViewProjectionMatrix;
// uniform mat4 u_NormalMatrix;
// uniform mat4 u_ModelViewMatrix;
// out vec3 v_Position;
// out vec3 v_Normal;
// out vec3 v_Parameter;
// layout (triangle_strip, max_vertices = 18) out;
// uniform usamplerBuffer connectivity;
// uniform samplerBuffer coordinates;
//test
// the version should be specified by a macro at compile time
// e.g. #version 410 or #version 330
// the version should be specified by a macro at compile time
// e.g. #version 410 or #version 330
layout (points) in;
uniform mat4 u_ModelViewProjectionMatrix;
// uniform mat4 u_NormalMatrix;
// uniform mat4 u_ModelViewMatrix;
// uniform int u_clip;
// uniform vec3 u_clip_center;
// uniform vec3 u_clip_normal;
// uniform int u_render_full;
// out vec3 v_Position;
// out vec3 v_Normal;
// out vec3 v_Parameter;
layout (triangle_strip, max_vertices = 16) out;
//uniform usamplerBuffer connectivity;
uniform samplerBuffer seeds;
// render full tetrahedron
void render_square(vec3 pt) {
vec3 bl = pt + vec3(-.2, -.2, 0);
gl_Position = u_ModelViewProjectionMatrix*vec4(bl, 1.0);
EmitVertex();
vec3 br = pt + vec3(.2, -.2, 0);
gl_Position = u_ModelViewProjectionMatrix*vec4(br, 1.0);
EmitVertex();
vec3 tl = pt + vec3(-.2, .2, 0);
gl_Position = u_ModelViewProjectionMatrix*vec4(tl, 1.0);
EmitVertex();
vec3 tr = pt + vec3(.2, .2, 0);
gl_Position = u_ModelViewProjectionMatrix*vec4(tr, 1.0);
EmitVertex();
EndPrimitive();
}
void
main() {
// lookup the seed points
vec3 p0 = texelFetch( seeds , 0 ).xyz;
// vec3 p1 = texelFetch( seeds , 1 ).xyz;
// vec3 p2 = texelFetch( seeds , 2 ).xyz;
// vec3 p3 = texelFetch( seeds , 3 ).xyz;
render_square(p0);
// render_square(p1);
// render_square(p2);
// render_square(p3);
}
// the version should be specified by a macro at compile time
// e.g. #version 410 or #version 330
#version 410
// this code taken from example of tetrahedron/volume toy by Philip
layout (location = 0 ) in vec3 a_Position;
// nothing is done here because the geometry shader produces and processes the actual vertices
// but we still need to set gl_Position
void main() {
gl_Position = vec4(0.0,0.0,0.0,0.0);
}
......@@ -17,6 +17,7 @@ add_test_files( TEST_FILES "ut" api )
# sandbox files should have _toy.cpp
add_test_files( SBX_FILES "toy" sandbox/philip )
add_test_files( SBX_FILES "toy" sandbox/hiro )
add_test_files( SBX_FILES "toy" sandbox/sabrina )
set( unit_skip mesh/delaunay/vertex_ut.cpp )
......
......@@ -5,22 +5,146 @@
#include "library/ckf.h"
#include "avro_config.h" // we need AVRO_SOURCE_DIR to find shaders
// the following two header files are only part of the avro-extensions repository
// #include "gl.h"
#include "graphics/shader.h"
using namespace avro;
UT_TEST_SUITE( voronoi_toy )
// this is all borrowed from geometry toy
// set up the view
int width = 500, height = width;
graphics::vec3 eye = {0,0,5};
graphics::vec3 up = {0,1,0};
graphics::vec3 center = {0.0,0.0,0.0};
float fov = M_PI/4.0;
float aspect = width/height;
float znear = 0.001;
float zfar = 100;
// define the transformation matrices, and compute MVP matrix
graphics::mat4 perspective_matrix = graphics::glm::perspective( fov , aspect , znear , zfar );
graphics::mat4 view_matrix = graphics::glm::lookAt( eye , center , up );
graphics::mat4 model_matrix = graphics::glm::identity();
graphics::mat4 mv = view_matrix * model_matrix;
graphics::mat4 mvp = perspective_matrix * mv;
UT_TEST_CASE( test1 )
{
std::vector<index_t> dims(2,10);
dims[1] = 5;
//also taken from geometry toy
// initialize OpenGL
avro_assert_msg( glfwInit() , "problem initializing OpenGL!" );
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow( width , height , "tetrahedra" , NULL, NULL);
if (!window) {
const char* description;
int code = glfwGetError(&description);
if (description)
printf("GLFW error (%d): %s\n",code,description);
glfwTerminate();
}
glfwMakeContextCurrent(window);
// load GL functions
gladLoadGL();
graphics::dumpGLInfo(); // this will be dumpGLInfo() in avro (it isn't necessary but prints some info about OpenGL, GLSL and the GPU)
//initialize the shader:
graphics::ShaderProgram shader("voronoi");
shader.use();
//test
std::vector<graphics::gl_float> seeds = {
0.0, 0.0 , 0.0,
1.0, 0.0 , 0.0,
0.0, 1.0 , 0.0,
0.0, 0.0 , 1.0,
1.0, 1.0 , 1.0
};
graphics::gl_index points_buffer;
GL_CALL( glGenBuffers( 1 , &points_buffer) );
GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , points_buffer ) );
GL_CALL( glBufferData( GL_ARRAY_BUFFER , sizeof(graphics::gl_float) * seeds.size() , seeds.data() , GL_STATIC_DRAW ) );
GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , 0 ) );
shader.setUniform("u_ModelViewProjectionMatrix",mvp);
// generate a texture to hold the seeds
graphics::gl_index seeds_texture;
GL_CALL( glGenTextures( 1 , &seeds_texture) );
GL_CALL( glActiveTexture( GL_TEXTURE0 ) );
GL_CALL( glBindTexture( GL_TEXTURE_BUFFER , seeds_texture) );
GL_CALL( glTexBuffer( GL_TEXTURE_BUFFER , GL_RGB32F , points_buffer ) );
// ensure we can capture the escape key being pressed
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwPollEvents();
glfwSetCursorPos(window, width/2, height/2);
glDisable(GL_DEPTH_TEST);
while (true) {
shader.use();
// grey-ish (almost white) background color
float col = 0.9;
glClearColor (col,col,col, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// mv = view_matrix * model_matrix;
// shader.setUniform("u_ModelViewMatrix", mv );
mvp = perspective_matrix * mv;
shader.setUniform("u_ModelViewProjectionMatrix", mvp );
// graphics::mat4 nm = graphics::glm::transpose(graphics::glm::inverse(mv));
// shader.setUniform("u_NormalMatrix", nm );
// enable the coordinates texture
glActiveTexture(GL_TEXTURE0 );
// GLint seeds_location = glGetUniformLocation(shader.handle() , "seeds");
// glUniform1i(seeds_location, 2);
// draw
GL_CALL( glBindBuffer(GL_ARRAY_BUFFER, points_buffer ) ); // it doesn't really matter which buffer we bind here since it isn't used
CKF_Triangulation topology(dims);
//GL_CALL( glDrawArrays(GL_POINTS, 0 , 1 ) );
graphics::Viewer vis;
vis.add( topology );
// swap buffers and wait for user input
glfwSwapBuffers(window);
glfwPollEvents();
vis.run();
// determine if we should exit the render loop
if (glfwWindowShouldClose(window)) break;
if (glfwGetKey(window, GLFW_KEY_ESCAPE ) == GLFW_PRESS) break;
}
}
UT_TEST_CASE_END( test1 )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment