首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用GLStipple时OGLFT绘制文本

使用GLStipple时OGLFT绘制文本
EN

Stack Overflow用户
提问于 2017-05-01 02:12:01
回答 1查看 134关注 0票数 1

我有一个有趣的bug,它已经困扰我几天了。

我目前正在使用OpenGL在屏幕上绘制文本。我正在利用OGLFT图书馆协助绘图。这个库实际上使用了freetype2库。实际上,我对这篇文章并没有做什么特别的事情。我只是在找单色文本。

无论如何,在实现库之后,我注意到只有在启用了glStipple之后,文本才是正确的。我相信OGLFT库和我的授权之间存在一些干扰问题。

我想知道有没有人在使用OGLFT库方面有一些经验。我正在发布一个极简主义的代码示例,以演示正在发生的事情:

(请注意,有些变量用于测量我的glCanvas的缩放因子和相机的位置,这仅适用于2D)

代码语言:javascript
复制
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才能正确显示文本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-02 03:35:12

看一看你的代码,我相信你的意图是把它变成灰度?如果是这样,那么您可以简单地使用OGLFT::Grayscale *testface = new OGLFT::Grayscale( "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 8);

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43713407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档