STR #3064

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | Roadmap 2.0 | Post Text | Post File | SVN ⇄ GIT ]

STR #3064

Application:FLTK Library
Status:5 - New
Priority:3 - Moderate, e.g. unable to compile the software
Scope:2 - Specific to an operating system
Subsystem:Unassigned
Summary:[FLTK2] fltk::gldrawtext always draws in white
Version:2.0-current
Created By:greg.ercolano
Assigned To:greg.ercolano
Fix Version:Unassigned
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:

Post File ]
Name/Time/Date Filename/Size top right image
 
#1 greg.ercolano
12:04 Mar 09, 2014
patch.txt
4k
 
bottom left image   bottom right image

Trouble Report Comments:

Post Text ]
Name/Time/Date Text top right image
 
#1 greg.ercolano
12:03 Mar 09, 2014
Reporting this on behalf of Gonzalo.
This may affect 1.3 as well, which is why I'm handling it.

Gonzalo wrote on fltk.general on Feb 21 2014:
---------------------------------------------------------------------
I have a GLWindow that draws a lot of stuff.  I am trying to draw text
using the fltk functions.  I am able to draw the text properly,
but it is always drawn in white.  It does not respect any glColor3f()
or glsetcolor() function.

My code looks like:

   // Turn on Color Buffer and Depth Buffer
   glColorMask(true, true, true, true);

   // Only write to the Stencil Buffer where 1 is not set
   glStencilFunc(GL_NOTEQUAL, 1, 0xFFFFFFFF);
   // Keep the content of the Stencil Buffer
   glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   glDisable(GL_TEXTURE_2D);

   glBegin( GL_BLEND );

   // So compositing works properly
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   glColor4f( r, g, b, a );

   fltk::glsetfont(font(), size() );
   fltk::gldrawtext(text().c_str(), pts[0].x, pts[0].y);

I am able to get colors into the font if I add a glBegin(GL_POLYGON) and glEnd() in between the fltk::gl* calls, but then the text is all garbage.  I looked into gldrawtext() and glsetfont() for clues and nothing is strange.
---------------------------------------------------------------------

..and followed that up with:

---------------------------------------------------------------------
I tried it on Linux (where I get white letters)
and on Windows (where I get nothing at all ).

[..]

I found the Linux code suffers from the texture generation from
GL_LUMINANCE instead of GL_LUMINANCE_ALPHA.

And the glBlendFunc(GL_ONE) instead of GL_SRC_ALPHA.

The Windows part of the code I am still digging.
---------------------------------------------------------------------
 
 
#2 greg.ercolano
12:09 Mar 09, 2014
Attached a patch provided by gonzalo that he says:

----
FLTK2.0 patch to make antialiased text in Linux and aliased text
in Windows
----

There are some extraneous mods included in the patch, but worthy
of note are mods to OpenGL/gl_draw.cxx, in particular this mod
caught my eye:

-    wglUseFontBitmaps(hdc, base, size, listbase+base);
+
+    bool succeed = false;
+    int MAX_TRIES = 5;
+    for ( int i = 0; i < MAX_TRIES && !succeed; ++i )
+    {
+       succeed = wglUseFontBitmaps(hdc, base, len, listbase+base) == TRUE;
+    }
+    if ( !succeed )
+    {
+       fprintf( stderr, "wglUseFontBitmaps error\n" );
+    }

Suggesting we use fltk::warning() in place of the fprintf(),
and I asked gonzalo about the MAX_TRIES loop around wglUseFontBitmaps:

----
erco writes:
    Hmm, can you explain what's up with the for() retry loop..
    Does it actually need several retries to work?

gonzalo answers:
    Yes, the for loop is needed as the wgl function sometimes fails unexpectedly
    (usually after a change in context).

erco follows up:
    Thanks -- I see this on the net too, looks like no one seems to know
    why it fails, but sometimes it does, so they include the retry loop.

    I guess I should make this change in 1.3 as well.

    [..]

    This is some perhaps relevant info on the issue above.

    The MSDN docs for this function:
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd374392%28v=vs.85%29.aspx

    ..includes a "community comment" that sounds like it might be the reason
    it fails on the first try, but succeeds on the second try; it reads:

    ________________________________________________________________________________
_______

    wglUseFontBitmaps fails if any GL_ERROR is set before calling this function.
    We have to call glGetError() before calling this function.

    Example:

        // Forcefully setting an error.
        // Following code is added to demonstrate the problem
        glMatrixMode(GL_TEXTURE_2D); // Set opengl Error since matrix
        bool bReturnValue = wglUseFontBitmaps( m_hDC, 0,256, m_nFontDisplayList );
                                     // bReturnValue returns false, glGetError() return GL_NO_ERROR.

    Here Font display list is not created, and error status is not provided by wglUseFontBitmaps.

    This problem can be solved by calling glGetError() before wglUseFontBitmaps().

        // Forcefully setting an error.
        // Following code is added to demonstrate the problem
        glMatrixMode(GL_TEXTURE_2D);
        int nErr = glGetError();
        bool bReturnValue = wglUseFontBitmaps( m_hDC, 0,256, m_nFontDisplayList );

    bReturnValue is true and bitmap is created.
    ________________________________________________________________________________
_______

    [..] so perhaps doing a glGetError() before the call to wglUseFontBitmaps()
    will ensure it works the first time.
----
 
bottom left image   bottom right image

Return to Bugs & Features | Post Text | Post File ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.