gpt4 book ai didi

c++ - OGLFT 在使用 GLStipple 时绘制文本

转载 作者:行者123 更新时间:2023-11-30 05:13:51 25 4
gpt4 key购买 nike

我有一个有趣的错误,现在已经“困扰”了我几天。

我目前正在使用 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 才能正确显示文本。

最佳答案

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

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

关于c++ - OGLFT 在使用 GLStipple 时绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43713407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com