c++ - Can only see a single white point CUDA/OpenGL interop -


i'm trying convert c++ code cuda code program read data external file , draw 3d matrix. i'm converting pieces of code @ time , fail trying draw small 3d matrix made of red points. can see single white point , that's code:

#define buffer_offset(i) ((char *)null + (i))   gluint  bufferobj; cudagraphicsresource *resource;  int size=5*5*7; int window_dim=600;  __global__ void kernel(float4 *ptr, int sizei) {    const unsigned long int blockid = blockidx.x //1d     + blockidx.y * griddim.x //2d     + griddim.x * griddim.y * blockidx.z; //3d    const unsigned long int threadid = (blockid * blockdim.x + threadidx.x);   if(threadid<sizei ) {     ptr[threadid].x=threadidx.x+0.5f;     ptr[threadid+sizei].x=1.0f;     ptr[threadid].y=blockidx.y+0.5f;     ptr[threadid+sizei].y=0.0f;     ptr[threadid].z=blockidx.z+0.5f;     ptr[threadid+sizei].z=0.0f;     ptr[threadid].w=1.0f;     ptr[threadid+sizei].w=1.0f;   } }   static void key_func( unsigned char key, int x, int y ) {   switch (key) {   case 27:     handle_error( cudagraphicsunregisterresource( resource ) );     glbindbuffer( gl_array_buffer, 0 );     gldeletebuffers( 1, &bufferobj );     exit(0);   } }  static void draw_func( void ) {    glclear(gl_color_buffer_bit | gl_depth_buffer_bit);   glloadidentity();   glulookat (2.5f, 2.5f, 10.0f, 2.5f, 2.5f, 3.5f, 0.0f, 1.0f, 0.0f);   glpushmatrix();   glmatrixmode(gl_modelview);     glbindbuffer( gl_array_buffer, bufferobj );   glvertexpointer( 4, gl_float, sizeof(float4), 0 );    glcolorpointer( 4, gl_float, sizeof(float4),   buffer_offset(sizeof(float4)*size) );   glpointsize( 3.0 );    gldrawarrays( gl_points, 0, size);    glflush();    glpopmatrix();   glutswapbuffers(); }  static void reshape_func( int w, int h) {   glviewport(0, 0, (glsizei) w, (glsizei) h);   glmatrixmode (gl_projection);   glloadidentity ();   glfrustum (-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 100.0f);    glmatrixmode (gl_modelview);   glutpostredisplay();  }  int main( int argc, char **argv ) {   cudadeviceprop  prop;   int dev;   float4 *g_vertex_buffer_data = new float4[size*2];    memset( &prop, 0, sizeof( cudadeviceprop ) );    prop.major = 3;   prop.minor = 0;   handle_error( cudachoosedevice( &dev, &prop ) );      handle_error( cudaglsetgldevice( dev ) );       glutinit( &argc, argv );     glutinitdisplaymode (glut_double | glut_rgba | glut_depth);    glutinitwindowsize( window_dim, window_dim );   glutcreatewindow( "interop_test" );    glgenbuffers( 1, &bufferobj );     glbindbuffer( gl_array_buffer, bufferobj );   glbufferdata( gl_array_buffer, sizeof(float4)*2*size, null, gl_dynamic_draw );      handle_error( cudagraphicsglregisterbuffer( &resource, bufferobj, cudagraphicsmapflagsnone ) );   handle_error( cudagraphicsmapresources( 1, &resource, null ) );    float4  *devptr;   size_t  sizeptr;   handle_error( cudagraphicsresourcegetmappedpointer( (void**)&devptr, &sizeptr, resource) );    dim3 dimblock(5,1,1);   dim3 dimgrid(1,5,7);    kernel<<<dimgrid,dimblock>>>( devptr, size );   ////////////don't know if necessary/////////////////   glbuffersubdata(gl_array_buffer, 0, sizeof(float4)*size, &devptr[0].x);   glbuffersubdata(gl_array_buffer, sizeof(float4)*size,              sizeof(float4)*size, &devptr[size].x);   /////////////////////////////////////////////////////////////////   handle_error( cudagraphicsunmapresources( 1, &resource, null ) );   glenable(gl_depth_test);  glutkeyboardfunc( key_func );  glutdisplayfunc( draw_func );  glutreshapefunc( reshape_func);  glutmainloop(); } 

i've tried print out devptr , correct data.

i found problem. answer question can use it. edit draw_func this:

static void draw_func( void ) {    [...]    glbindbuffer( gl_array_buffer, bufferobj );   glenableclientstate( gl_vertex_array );    glenableclientstate( gl_color_array );   glvertexpointer( 4, gl_float, sizeof(float4), 0 );    glcolorpointer( 4, gl_float, sizeof(float4), buffer_offset(sizeof(float4)*size) );    glpointsize( 3.0 );    gldrawarrays( gl_points, 0, size);    gldisableclientstate( gl_vertex_array );   gldisableclientstate( gl_color_array );    [...] }   

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -