2016-11-21 73 views
-1

我可以用一种颜色画出3D点,比如说绿色。 但我无法将单独的颜色应用到每个点。个别颜色的点云

bool applyColor = true; 
glPointSize(3); 
glBegin(GL_POINTS); 
glColor3ub(0,255,0); 

for(auto vpMP : vpMPs){ 
    if(applyColor){ 
     cv::Vec3b rgb = vpMP->rgb; 
     glColor3ub(rgb[2], rgb[1], rgb[0]); 
     cout << (int)rgb[0] << ", " << (int)rgb[1] << ", " << (int)rgb[2] << endl; // Prints out right values 
    } 
    cv::Mat pos = vpMP->GetWorldPos(); 
    glVertex3f(pos.at<float>(0),pos.at<float>(1),pos.at<float>(2)); 
} 
glEnd(); 

任何线索?

glVertex3f工作正常,点显示,他们应该是。

With applyColor = false,点显示为绿色。

随着applyColor = TRUE,分显示黑色的时候,他们应该是RGB。顺便说一句,rgb [i]是无符号字符。

谢谢!

+0

那么你在'cout'中看到了什么? 'vpMP-> rgb'中有什么值? – ybungalobill

+0

cout打印这样的行:'244,98,12'全部纠正0到255的rgb值。 –

+0

这意味着问题出现在你没有显示的代码中。请发布[MCVE](http://stackoverflow.com/help/mcve)。 – ybungalobill

回答

0

我不能让我的旧代码的工作,并且,@ybungalobill指出,该代码使用旧过时的固定功能流水线,所以我搬到这个更现代的方式工作的。

仅显示部分码:

bool color = true; 
struct glPunto{ 
    float x; 
    float y; 
    float z; 
    uchar r; 
    uchar g; 
    uchar b; 
    char padding[17]; // Así la estructura es múltiplo de 32 bytes 
}; 
glPunto glPuntos[N]; 


int i = 0; 
for(auto punto : vpMPs){ 
    cv::Mat pos = punto->GetWorldPos(); 
    auto rgb = punto->rgb; 

    glPunto &glp = glPuntos[i++]; 

    glp.x = pos.at<float>(0); 
    glp.y = pos.at<float>(1); 
    glp.z = pos.at<float>(2); 

    if(color){ 
     glp.r = rgb[2]; 
     glp.g = rgb[1]; 
     glp.b = rgb[0]; 
    } else { 
     glp.r = 0; 
     glp.g = 0; 
     glp.b = 0; 
    } 
} 

glPointSize(color?4:2); 
glEnableClientState(GL_VERTEX_ARRAY); 
glVertexPointer(3, GL_FLOAT, sizeof(glPunto), &glPuntos[0].x); 
glEnableClientState (GL_COLOR_ARRAY); 
glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(glPunto), &glPuntos[0].r); 

glDrawArrays(GL_POINTS, 0, i); 

glDisableClientState (GL_COLOR_ARRAY); 
glDisableClientState (GL_VERTEX_ARRAY); 

这仍然没有代表现有技术的状态。如果它使用glVertexAttribPointer会更好。