2017-05-01 20 views
1

我有一个有趣的bug,现在已经“困扰”了我几天。OGLFT在使用GLStipple时绘制文字

我目前使用OpenGL在屏幕上绘制文本。我正在使用OGLFT库来协助绘图。这个库实际上使用了freetype2库。我其实没有对文本做任何特别的事情。我只寻找单色文字。

无论如何,在实现库之后,我注意到只有在启用了glStipple的情况下,才会绘制正确的文本。我相信OGLFT库和我所支持的之间存在一些干扰问题。

我想知道是否有人在那里使用OGLFT库的一些经验。我发布了一个我的代码的简约示例,以演示发生了什么事情:

(请注意,有一些变量用于表示我的glCanvas的缩放因子和相机的位置,并且这只是对于2D)

double _zoomX = 1.0; 

double _zoomY = 1.0; 

double _cameraX = 0; 

double _cameraY = 0; 



/* This function gets called everytime a draw routine is needed */ 
void modelDefinition::onPaintCanvas(wxPaintEvent &event) 
{ 
    wxGLCanvas::SetCurrent(*_geometryContext);// This will make sure the the openGL commands are routed to the wxGLCanvas object 
    wxPaintDC dc(this);// This is required for drawing 

     glMatrixMode(GL_MODELVIEW); 
     glClear(GL_COLOR_BUFFER_BIT); 

     updateProjection(); 

    OGLFT::Monochrome *testface = new OGLFT::Monochrome("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 8); 
     testface->draw(0, 0, "test"); 
     glEnable(GL_LINE_STIPPLE);// WHen I comment out this line, the text is unable to be drawn 

     glLineStipple(1, 0b0001100011000110); 
     glBegin(GL_LINES); 
      glVertex2d(_startPoint.x, _startPoint.y); 
      glVertex2d(_endPoint.x, _endPoint.y); 
     glEnd(); 
     glDisable(GL_LINE_STIPPLE); 

    SwapBuffers(); 
} 

void modelDefinition::updateProjection() 
{ 
     // First, load the projection matrix and reset the view to a default view 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 

    glOrtho(-_zoomX, _zoomX, -_zoomY, _zoomY, -1.0, 1.0); 

    //Reset to modelview matrix 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    glViewport(0, 0, (double)this->GetSize().GetWidth(), (double)this->GetSize().GetHeight()); 
    /* This section will handle the translation (panning) and scaled (zooming). 
    * Needs to be called each time a draw occurs in order to update the placement of all the components */ 
    if(_zoomX < 1e-9 || _zoomY < 1e-9) 
    { 
     _zoomX = 1e-9; 
     _zoomY = _zoomX; 
    } 

    if(_zoomX > 1e6 || _zoomY > 1e6) 
    { 
     _zoomX = 1e6; 
     _zoomY = _zoomX; 
    } 

    glTranslated(-_cameraX, -_cameraY, 0.0); 
} 

另外有一点要注意的是,glEnable(GL_LINE_STIPPLE);下面的代码是必需的。就好像glStipple需要正确绘制才能正确显示文本。

回答

1

翻遍你的代码,我相信你的意图是将其渲染为灰度?如果是这样,那么你可以简单地使用OGLFT::Grayscale *testface = new OGLFT::Grayscale("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 8);

这将得到你所需要的,而不必担心你发布的问题。事实上,我也建议这样做。

+0

是的!就是这样,现在一切正常。非常感谢! – codingDude