hi

here is snippet, which may be helpful:

$vert = $vert->transpose->flat;
my $float_size = 4;
my $data = OpenGL::Array->new_scalar(GL_FLOAT, $vert->get_dataref,
$vert->dim(0)*$float_size);
$data->bind($buf_id);
glBufferSubDataARB_p(GL_ARRAY_BUFFER_ARB, $offset, $data); # offset should
be in number of elements, not bytes


On 17 January 2013 14:58, Frank Boers <[email protected]> wrote:

> Dear PDLs,
>
> how can I copy piddels direct to an opengl vertex buffer without
> converting the piddel to a perl array?
> Please have a look to the example, line 97- 98
>
> best regards
> Frank
>
> #!/usr/bin/perl -w
>
> use strict;
> use OpenGL qw(:all);
>
> use PDL;
>
> my $pending = 0;
> my $t       = pdl(sequence(1000) );
> my $data    = pdl( 10 * sin( $t * 10 * 6.28) )->float;
>
> #-----------------------------**----------------------------#
> #---- setWindow                  -------------------------#
> #-----------------------------**----------------------------#
> sub setWindow{
> my ($l,$r,$b,$t) = @_;
>   glMatrixMode(GL_PROJECTION);
>   glLoadIdentity();
>   gluOrtho2D($l,$r,$b,$t);
> } # end of setWindow
>
> #-----------------------------**----------------------------#
> #---- setViewport                -------------------------#
> #-----------------------------**----------------------------#
> sub setViewport{
> my ($l,$r,$b,$t) = @_;
>   glViewport($l,$b,$r-$l,$t-$b);
> }# end of setViewport
>
> #-----------------------------**----------------------------#
> #---- myReshape                  -------------------------#
> #-----------------------------**----------------------------#
> sub myReshape{
>
> my($w,$h) = @_;
>
>  return if (  $pending );
>
> glViewport(0,0,$w,$h);
> glMatrixMode(GL_PROJECTION);
> glLoadIdentity();
> gluOrtho2D(0.0,$w,0.0,$h);
>
> } # end of reshape
>
> #-----------------------------**----------------------------#
> #---- update_plot        -------------------------#
> #-----------------------------**----------------------------#
> sub update_plot{
> my ($x,$y) = @_;
>
>    return if ( $pending );
>    $pending = 1;
>
> #---
> my $v = pdl( zeroes(2,$data->dim(0) ) )->float();
> my $v0 = $v->slice("(0),:");
> my $v1 = $v->slice("(1),:");
>    $v0.= $t;
> my $size= $v->nelem * 4;
>
>    glClear(GL_COLOR_BUFFER_BIT);
>    glMatrixMode(GL_MODELVIEW);
>    glLoadIdentity();
>    glColor3f(0.0,0.0,1.0);
>
>
> #--- create OGL verts buffer
>    glDisableClientState(GL_**VERTEX_ARRAY);
>
> my $VertexObjID = glGenBuffersARB_p(1);
>    glBindBufferARB(GL_ARRAY_**BUFFER_ARB, $VertexObjID);
>
>
> my $verts = OpenGL::Array->new_list(GL_**FLOAT,$v->list() );
>    $verts->bind($VertexObjID);
>    glBufferDataARB_p(GL_ARRAY_**BUFFER_ARB, $verts, GL_DYNAMIC_DRAW_ARB);
>
>    glVertexPointer_p(2,$verts);
>
>    glEnableClientState(GL_VERTEX_**ARRAY);
>
> #--- plot
> my $w = glutGet( GLUT_WINDOW_WIDTH );
> my $h = glutGet( GLUT_WINDOW_HEIGHT );
>
> my $w0 = 0;
> my $w1 = $w-1;
>
> my $h0 = 0;
>
>    setViewport($w0,$w1,$h0,$h);
>    setWindow($t->min,$t->max,$**data->min,$data->max );
>
>    $v1.= $data;
>
> ### !!!! this is slow  for large data
>    $verts->assign( 0,$v->list() );
>
>    glBufferSubDataARB_p(GL_ARRAY_**BUFFER_ARB,0,$verts);
>
>    glDrawArrays(GL_LINE_STRIP,0,$**t->dim(-1)-1 );
>
>    glDisableClientState(GL_**VERTEX_ARRAY);
>
>    glFlush();
>    glutSwapBuffers();
>
>   $pending = undef;
>
> } # end of update_plot
>
>
> #=== MAIN
> glClearColor(1.0,1.0,1.0,0.0);
> glColor3f(0.0,0.0,1.0);
> glLineWidth(2);
>
> glutInit();
>
> glutInitDisplayMode(GLUT_**DOUBLE | GLUT_RGB | GLUT_ALPHA);
>
> glutInitWindowSize(300,400);
> glutInitWindowPosition(10,10);
>
> my $IDwindow = glutCreateWindow("PDL OGL TEST");
> glutDisplayFunc( sub{ update_plot(@_) } );
> glutReshapeFunc( sub{ myReshape(@_) } );
>
> glutMainLoop();
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> Frank Boers
> Institute of Neuroscience and Medicine - 4
> Medical Imaging Physics
> Forschungszentrum Juelich GmbH
> 52425 Juelich
> phone: +49 - (0)2461-61-6005
> fax  : +49 - (0)2461-61-2820
> email: [email protected]
> http://www.fz-juelich.de/inm/**inm-4/DE/Forschung/MEG-Physik/**_node.html<http://www.fz-juelich.de/inm/inm-4/DE/Forschung/MEG-Physik/_node.html>
>
>
>
>
> ------------------------------**------------------------------**
> ------------------------------**------
> ------------------------------**------------------------------**
> ------------------------------**------
> Forschungszentrum Juelich GmbH
> 52425 Juelich
> Sitz der Gesellschaft: Juelich
> Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
> Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
> Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
> Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
> Prof. Dr. Sebastian M. Schmidt
> ------------------------------**------------------------------**
> ------------------------------**------
> ------------------------------**------------------------------**
> ------------------------------**------
>
> ______________________________**_________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.**edu/mailman/listinfo/perldl<http://mailman.jach.hawaii.edu/mailman/listinfo/perldl>
>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to