OGLFT 在使用 GLStipple 时绘制文本
OGLFT draws text when GLStipple is used
我有一个有趣的错误 "bugging" 我已经困扰了几天了。
我目前正在使用 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);
这将得到您所需要的,而不必担心您发布的问题。其实我也推荐这样做。
我有一个有趣的错误 "bugging" 我已经困扰了几天了。
我目前正在使用 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);
这将得到您所需要的,而不必担心您发布的问题。其实我也推荐这样做。