2011-09-26 13 views
8

के साथ किनेक्ट प्वाइंट क्लाउड प्रस्तुत करना मैं गतिशील बिंदु क्लाउड विज़ुअलाइज़र बनाने की कोशिश कर रहा हूं। अंक कोनेक्ट सेंसर के साथ हर फ्रेम को अद्यतन किया जाता है। फ्रेम को पकड़ने के लिए मैं ओपनसीवी और जीएलयूटी का उपयोग कर रहा हूं। ओपनसीवी एपीआई आरजीबी रंग डेटा के लिए अंक xyz स्थिति के लिए 640 x 480 (फ्लोट *), और 640 x 480 (int *) देता है। अधिकतम प्रदर्शन प्राप्त करने के लिए, मैं एक सरल वेरटेक्स ऐरे के बजाय स्ट्रीम मोड में वर्टेक्स बफर ऑब्जेक्ट का उपयोग करने का प्रयास कर रहा हूं। मैं इसे वर्टेक्स ऐरे के साथ प्रस्तुत करने में सक्षम हूं, लेकिन मेरे वीबीओ कार्यान्वयन के साथ कुछ भी नहीं दिया जा रहा है। मैंने घोषणाओं में विभिन्न आदेशों का एक गुच्छा करने की कोशिश की, लेकिन मुझे वह नहीं मिल रहा है जो मुझे याद आ रही है। क्या कोई मुझे सही दिशा में इंगित करने का प्रयास कर सकता है? (के रूप में ईसाई राव से पूछा कि मैंने गलत संस्करण rewrited, इसलिए तुम लोग अपनी गलतियों को समझ सकता हूँ)वर्टेक्स बफर ऑब्जेक्ट (वीबीओ)

int main() 
{ 
    //Delaring variables, inittiating glut, setting camera and checking the compatibility as http://www.songho.ca/opengl/gl_vbo.html 
    glutDisplayFunc(displayCB); 
    glutIdleFunc(displayCB); 
    ... 
    //Inittiating the vertex buffers 
    if(vboSupported) 
    { 
     glGenBuffers(1, &vertex_buffer); 
     glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer); 
     glBufferData(GL_ARRAY_BUFFER_ARB, (sizeof(GLfloat) * 640 * 480 * 3), 0, GL_STREAM_DRAW_ARB); 
     glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(float) * 640 * 480 * 3), point_cloud.points_position); 

     glGenBuffers(2, &color_buffer); 
     glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer); 
     glBufferData(GL_ARRAY_BUFFER_ARB, (sizeof(GLbyte) * 640 * 480 * 3), 0, GL_STREAM_DRAW_ARB); 
     glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(char) * 640 * 480 * 3), point_cloud.points_color); 
    } 
    //glutMainLoop(), cleaning memory, ending main 
    .. 
} 

//Updating the screen 
void displayCB() 
{ 
    point_cloud.update(); 

    // clear buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 

    // save the initial ModelView matrix before modifying ModelView matrix 
    glPushMatrix(); 

     glBindBuffer(GL_ARRAY_BUFFER_ARB, color_buffer); 
     glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(char) * 640 * 480 * 3), point_cloud.points_color); 
     glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); 

     glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buffer); 
     glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(float) * 640 * 480 * 3), point_cloud.points_position); 
     glVertexPointer(3, GL_FLOAT, 0, 0)); 

     // enable vertex arrays 
     glEnableClientState(GL_VERTEX_ARRAY); 
     glEnableClientState(GL_COLOR_ARRAY); 

     glDrawArrays(GL_POINT, 0, 640*480); 

     glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays 
     glDisableClientState(GL_COLOR_ARRAY); 

     glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); 

    glPopMatrix(); 

    glutSwapBuffers(); 
} 
+1

काफी असंबंधित टिप्पणी: बल्कि 'glBufferData' (बजाय' glBufferSubData' की) का उपयोग जब पूरे बफर अद्यतन करने मैं तीन परिवर्तन किया। यह ड्राइवर को चीजों को अनुकूलित करने में मदद कर सकता है, लेकिन अब मैं उस पर विस्तार से नहीं जाऊंगा। कम से कम मुख्य कोड में 'glbufferDubData'' glBufferData' के बाद पूरी तरह से बेकार है। –

+1

आपको प्रत्येक उत्तर या टिप्पणी के बाद प्रश्न कोड को पूरी तरह से बदलने के बजाय, प्रश्न में अपने कोड के ** नए संस्करणों को जोड़ना चाहिए, क्योंकि यह अन्य उत्तरों को अमान्य करता है और प्रश्न और उत्तर पढ़ने वाले लोग पूरी तरह भ्रमित हो जाते हैं। –

+0

क्या मैं इसे एक नए उत्तर के रूप में पोस्टिंट द्वारा करता हूं? –

उत्तर

0

पुनश्च:: यहाँ simpflified कोड है कार्यक्रम और चल रहा है, लेकिन मैं नहीं देख सकते हैं Vertex ऐरे संस्करण की तुलना में औसत प्रदर्शन में कोई सुधार। क्या यह ठीक है? समस्या हल हो गई थी।

1 - I though that glGenBuffers first parameter was the number that 
would be associated to the buffer, instead, its the number of 
buffers that would be allocated. This doesn't matter anyway, because 
now I'm using a single buffer and adding all the data to it. Didn't 
solved the problem, but was going in the right way. 

2 - There are two ways of being able to use OpenGL VBO functions. 
First, you can bind the ARB version functions by yourself OR you 
can add glew.h and use glewInit() after starting an OpenGL context. 
The second option is a LOT cleaner and I changed my code so I don't 
use the ARB versions anymore. Still didn't solved the problem. 

3 - Christian Rau asked me for glErrors in the code, so, I wrote it 
after each OpenGL operation in displayCB. After glDrawArrays I got 
an 0x00500 error, that means there is an invalid enum, so I noticed 
I was using GL_POINT as parameter to glDrawArrays, instead of 
GL_POINTS, so silly that makes me want to kill myself. 

अंतिम कोड:

//EDIT: Added glew.h as a header and I´m not using the ARB version anymore 
#include <glew.h> 

    int main() 
    { 
     //Declaring variables, initiating glut, setting camera and checking the compatibility as http://www.songho.ca/opengl/gl_vbo.html 
     glutDisplayFunc(displayCB); 
     glutIdleFunc(displayCB); 
     ... 

     //EDIT: IS VERY IMPORTANT TO ADD IT AS SOON AS YOU START AN OPENGL CONTEXT. 
     initGlew(); 

     //Inittiating the vertex buffers 
     if(vboSupported) 
     { 
      //EDIT: I was using two buffers, one for color and another for the vertex. I changed the code so I use a single buffer now. 
      //EDIT: Notice that I'm not using the ARB version of the functions anymore. 
      glGenBuffers(1, &buffer); 
      glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer); 
      glBufferData(GL_ARRAY_BUFFER_ARB, (sizeof(GLfloat) * 640 * 480 * 3) + (sizeof(GLbyte) * 640 * 480 * 3), 0, GL_STREAM_DRAW_ARB); 
     } 
     //glutMainLoop(), cleaning memory, ending main 
     .. 
    } 

    //Updating the screen 
    void displayCB() 
    { 
     point_cloud.update(); 

     // clear buffer 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 

     // save the initial ModelView matrix before modifying ModelView matrix 
     glPushMatrix(); 

      glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer); 
      glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(char) * 640 * 480 * 3), point_cloud.points_color); 
      glBufferSubData(GL_ARRAY_BUFFER_ARB, (sizeof(char) * 640 * 480 * 3), (sizeof(float) * 640 * 480 * 3), point_cloud.points_position); 

      // enable vertex arrays 
      glEnableClientState(GL_VERTEX_ARRAY); 
      glEnableClientState(GL_COLOR_ARRAY); 

      glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); 
      //EDIT: Added the right offset at the vertex pointer position 
      glVertexPointer(3, GL_FLOAT, 0, (void*)(sizeof(char) * 640 * 480 * 3)); 

      //EDIT: Was using GL_POINT instead of GL_POINTS 
      glDrawArrays(GL_POINTS, 0, 640*480); 

      glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays 
      glDisableClientState(GL_COLOR_ARRAY); 

      glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); 

     glPopMatrix(); 

     glutSwapBuffers(); 
    } 
संबंधित मुद्दे