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

progress towards colormap, still debugging

parent 16a23989
......@@ -4,7 +4,53 @@
layout( location = 0 ) out vec4 fragColor;
in vec3 v_Position;
in vec3 v_Normal;
in vec3 v_Parameter;
const int ncolor = 256;
uniform float u_umin;
uniform float u_umax;
uniform samplerBuffer colormap;
void
get_color( float u , out vec3 color ) {
float umin = 0.;//u_umin;
float umax = 7.;//u_umax;
int indx = int(ncolor*(u - umin)/(umax - umin));
if (indx < 0) indx = 0;
if (indx > 255) indx = 255;
float r0 = texelFetch( colormap , 3*(indx) + 0 ).x;
float g0 = texelFetch( colormap , 3*(indx) + 1 ).x;
float b0 = texelFetch( colormap , 3*(indx) + 2 ).x;
color = vec3(r0,g0,b0);
}
void main() {
vec3 color = vec3(.8, .4, .4);
vec3 color = vec3(1.0, 1.0,1.0);//vec3(0.8,0.8,0.2);
int idx = gl_PrimitiveID;
float f = idx;
if (idx == 0) color = vec3(1,0,0);
if (idx == 1) color = vec3(0,1,0);
if (idx == 2) color = vec3(0,0,1);
if (idx == 3) color = vec3(1,1,0);
if (idx == 4) color = vec3(0,1,1);
if (idx == 5) color = vec3(1,0,1);
if (idx == 6) color = vec3(0,0,0);
//get_color(f, color);
fragColor = vec4(color, 1);
}
\ No newline at end of file
......@@ -46,20 +46,44 @@ uniform samplerBuffer seeds;
// render full tetrahedron
void render_square(vec3 pt) {
vec3 bl = pt + vec3(-.2, -.2, 0);
//define all four points of the square
vec3 bl = pt + vec3(-.02, -.02, 0);
vec3 br = pt + vec3(.02, -.02, 0);
vec3 tl = pt + vec3(-.02, .02, 0);
vec3 tr = pt + vec3(.02, .02, 0);
//top triangle
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();
gl_PrimitiveID = 3;
EmitVertex();
EndPrimitive();
gl_Position = u_ModelViewProjectionMatrix*vec4(bl, 1.0);
EmitVertex();
gl_Position = u_ModelViewProjectionMatrix*vec4(tr, 1.0);
EmitVertex();
gl_Position = u_ModelViewProjectionMatrix*vec4(br, 1.0);
EmitVertex();
gl_PrimitiveID = gl_PrimitiveIDIn;
EmitVertex();
EndPrimitive();
}
......@@ -71,7 +95,7 @@ main() {
// lookup the seed points, taking in glPrimitiveIDIn
vec3 p0 = texelFetch( seeds , gl_PrimitiveIDIn ).xyz;
vec3 p0 = vec3(texelFetch( seeds , gl_PrimitiveIDIn ).xy, 0);
render_square(p0);
......
......@@ -12,6 +12,7 @@
// #include "gl.h"
#include "graphics/shader.h"
#include "graphics/colormap.h"
using namespace avro;
......@@ -20,7 +21,7 @@ UT_TEST_SUITE( voronoi_toy )
// set up the view
int width = 500, height = width;
graphics::vec3 eye = {0,0,5};
graphics::vec3 eye = {0,0,1};
graphics::vec3 up = {0,1,0};
graphics::vec3 center = {0.0,0.0,0.0};
......@@ -71,15 +72,23 @@ UT_TEST_CASE( test1 )
GL_CALL( glGenVertexArrays( 1, &vertex_array ) );
GL_CALL( glBindVertexArray(vertex_array) );
//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 , 0.0,
1.0, 1.0 , 0.0,
0.0, -1.0, 0.0,
//generate random seeds desired times 3
int size = 7* 3;
std::vector<graphics::gl_float> seeds;
srand (time(NULL));
for (int i = 0; i < size; i ++){
seeds.push_back(rand() % 10 * 0.01);
};
// 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 , 0.0,
// 1.0, 1.0 , 0.0,
// 0.0, -1.0, 0.0,
// };
graphics::gl_index points_buffer;
GL_CALL( glGenBuffers( 1 , &points_buffer) );
GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , points_buffer ) );
......@@ -89,7 +98,16 @@ UT_TEST_CASE( test1 )
shader.setUniform("u_ModelViewProjectionMatrix",mvp);
graphics::gl_index colormap_buffer;
GL_CALL( glGenBuffers( 1 , &colormap_buffer) );
//get a colormaps and bind it to the colormap buffer
avro::Colormap colormap;
colormap.change_style("giraffe");
index_t ncolor = 256*3;
GL_CALL( glBindBuffer( GL_TEXTURE_BUFFER , colormap_buffer) );
GL_CALL( glBufferData( GL_TEXTURE_BUFFER , sizeof(float) * ncolor , colormap.data() , GL_STATIC_DRAW) );
// generate a texture to hold the seeds
graphics::gl_index seeds_texture;
......@@ -98,6 +116,13 @@ UT_TEST_CASE( test1 )
GL_CALL( glBindTexture( GL_TEXTURE_BUFFER , seeds_texture) );
GL_CALL( glTexBuffer( GL_TEXTURE_BUFFER , GL_RGB32F , points_buffer ) );
// generate a texture to hold the colormap
GLuint colormap_texture;
GL_CALL( glGenTextures( 1 , &colormap_texture) );
GL_CALL( glActiveTexture( GL_TEXTURE0 + 1 ) );
GL_CALL( glBindTexture( GL_TEXTURE_BUFFER , colormap_texture) );
GL_CALL( glTexBuffer( GL_TEXTURE_BUFFER , GL_R32F , colormap_buffer ) );
// ensure we can capture the escape key being pressed
......@@ -116,16 +141,9 @@ UT_TEST_CASE( test1 )
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 );
......@@ -137,8 +155,9 @@ UT_TEST_CASE( test1 )
// draw
GL_CALL( glBindBuffer(GL_ARRAY_BUFFER, points_buffer ) ); // it doesn't really matter which buffer we bind here since it isn't used
GL_CALL( glDrawArrays(GL_POINTS, 0 , 5 ) );
GL_CALL( glDrawArrays(GL_POINTS, 0 , 7 ) );
// swap buffers and wait for user input
......
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