PDA

View Full Version : Utilizing OGLFT class for rendering text



philm0
05-01-2017, 10:41 AM
Hello all,

I know that I have two different threads running about rendering text. I am looking at a few different options right now to implement text rendering in my application. Which ever one I can get to render properly first is the solution that I am going to be running with. My first post is mainly about creating a solution from scratch. This post is about using a library to render the text.

SO far, this solution is the "best" in the sense that I have gone the furthest. I am able to render some text on screen. However, there seems to be a bug in either my implementation or the libraries implementation.

So, what is happening is that the text is being rendered only when the code glEnable(GL_LINE_STIPPLE) is executed and the glEnable command is executed after I have the OGLFT library code executed. I believe that there is some sort of gl confliction occurring but I can't seem to find out which one. I have attached here a minimalist code of the my application that demonstrates what is occurring (I am assuming that the OGLFT library is already installed). Normally, I would be posting this question on the appropriate mailing list or asking the author. Howver, it seems that the mailing list is non-existent and the two emails that I found concerning this library are non-functionality. I am hoping that there is someone here on the forum that has some experience on using this library and can assist on debugging the code.




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);
}

I would kinda prefer to go with this solution as I do not need to write a vertex shader/fragment shader and this solution here seems to be the more portable.

philm0
05-06-2017, 09:32 PM
Hey all,

I was able to narrow it down to a simple issue. I believe there is an issue with the library. I changed namespaces from monochromatic to greyscale and I was able to draw the text in black without any issues!