shader - Use index as coordinate in OpenGL -


i want implement timeseries viewer allows user zoom , smoothly pan.

i've done immediate mode opengl before, that's deprecated in favor of vbos. examples of vbos can find store xyz coordinates of each , every point.

i suspect need keep data in vram in order framerate during pan can called "smooth", have y data (the dependent variable). x independent variable can calculated index, , z constant. if have store x , z memory requirements (both buffer size , cpu->gpu block transfer) tripled. , have tens of millions of data points through user can pan, memory usage non-trivial.

is there technique either drawing 1-d vertex array, index used other coordinate, or storing 1-d array (probably in texture?) , using shader program generate xyz? i'm under impression need simple shader anyway under new fixed-feature-less pipeline model implement scaling , translation, if combine generation of x , z coordinates , scaling/translation of y ideal.

is possible? know of sample code this? or can @ least give me pseudocode saying gl functions call in order?

thanks!

edit: make sure clear, here's equivalent immediate-mode code, , vertex array code:

// immediate glbegin(gl_line_strip); for( int = 0; < n; ++i )     glvertex2(i, y[i]); glend();  // vertex array struct { float x, y; } v[n]; for( int = 0; < n; ++i ) {     v[i].x = i;     v[i].y = y[i]; } glvertexpointer(2, gl_float, 0, v); gldrawarrays(gl_line_strip, 0, n); 

note v[] twice size of y[].

that's fine opengl.

vertex buffer objects (vbo) can store information want in 1 of gl supported format. can fill vbo single coordinate:

glgenbuffers( 1, &buf_id); glbindbuffer( gl_array_buffer, buf_id ); glbufferdata( gl_array_buffer, n*sizeof(float), data_ptr, gl_static_draw ); 

and bind proper vertex attribute format draw:

glbindbuffer( gl_array_buffer, buf_id ); glenablevertexattribarray(0);  // hard-coded here sake of example glvertexattribpointer(0, 1, gl_float, false, 0, null); 

in order use you'll need simple shader program. vertex shader can like:

#version 130 in float at_coord_y;  void main() {     float coord_x = float(gl_vertexid);     gl_position = vec4(coord_x,at_coord_y,0.0,1.0); } 

before linking shader program, should bind it's at_coord_y attribute index you'll use (=0 in code):

glbindattriblocation(program_id,0,"at_coord_y"); 

alternatively, can ask program after linking index attribute automatically assigned , use it:

const int attrib_pos = glgetattriblocation(program_id,"at_coord_y"); 

good luck!


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -