gl_draw

29 views
Skip to first unread message

holm.h...@gmail.com

unread,
Apr 9, 2025, 2:14:26 AM4/9/25
to fltk.general

Hello,

I have a issue with gl_graw. if I rotate my model so that gl_draw should draw text outside the visible area, expected action is not happening. the text can then pop up on the position of the last written text.

I therefore try the following code:
void my_gl_draw(const char* str, int n, float x, float y) {
  GLboolean valid;
 
  glRasterPos2f(x, y);
  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
  if (valid)
    gl_draw(str, n);
  return;
}

This code so also have side effects.

Do any out there understand? What is the problem and how to fix ?

Best regards
Håvard

Matthias Melcher

unread,
Apr 9, 2025, 4:14:07 AM4/9/25
to fltk.general
Writing text in OpenGL is a 2d Raster Operation. OpenGL does not support that if the bottom left corner of the drawing rectangle is outside of the drawing area. If that is what you are seeing, It may be possible to write some custom clipping for text that intersects the bottom left corner.

Gonzalo Garramuño

unread,
Apr 9, 2025, 4:42:56 AM4/9/25
to fltkg...@googlegroups.com


On 4/9/2025 5:14 AM, 'Matthias Melcher' via fltk.general wrote:
Writing text in OpenGL is a 2d Raster Operation. OpenGL does not support that if the bottom left corner of the drawing rectangle is outside of the drawing area. If that is what you are seeing, It may be possible to write some custom clipping for text that intersects the bottom left corner. --
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkgeneral/5c17309d-e581-4c53-910a-ba929964741en%40googlegroups.com.

You can usually improve things if you do all of this:


    bool GL2TextShape::setRasterPos(double x, double y, size_t pos)
    {
        GLboolean result = GL_TRUE;

        glRasterPos2d(x, y);
        glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &result);
        if (result == GL_FALSE)
        {
            double width = gl_width(txt.c_str(), pos) / viewZoom;
            double height = (gl_height() / viewZoom);
            double xMove, yMove, bxMove, byMove;
            xMove = width;
            yMove = height;
            bxMove = -xMove * pixels_per_unit * viewZoom;
            byMove = -yMove * pixels_per_unit * viewZoom;
            glRasterPos2d(x + xMove, y + yMove);
            result = GL_TRUE;
            glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &result);
            if (result == GL_FALSE)
            {
                // Probably bottom right corner, don't offset x.
                bxMove = 0;
                glRasterPos2d(x, y + yMove);
                glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &result);
            }
            glBitmap(0, 0, 0, 0, bxMove, byMove, NULL);
        }
        return (bool)result;
    }

    void GL2TextShape::draw()
    {
        double height = gl_height() / viewZoom;

        // Copy text to process it line by line
        txt = text;

        GLboolean result;
        std::size_t pos = txt.find('\n');
        double x = pts[0].x / pixels_per_unit;
        double y = pts[0].y / pixels_per_unit;
        for (; pos != std::string::npos; y -= height, pos = txt.find('\n'))
        {
            result = setRasterPos(x, y, pos);
            if (result)
                gl_draw(txt.c_str(), pos);
            if (txt.size() > pos)
                txt = txt.substr(pos + 1, txt.size());
        }
        if (!txt.empty())
        {
            result = setRasterPos(x, y, txt.size());
            if (result)
                gl_draw(txt.c_str());
        }
    }

-- 
Gonzalo Garramuño
ggar...@gmail.com

Ian MacArthur

unread,
Apr 9, 2025, 7:02:34 AM4/9/25
to fltk.general
Hi Håvard,

As the others have said, GL text rendering is a bit "tricky".
The fltk wrappers make it easier, but even then...

Do you have a minimal, compileable example of what you are doing, that you could post here, just in case there's any "special trick" needed?

That said, Gonzalo's example looks like a good starting point...!

Reply all
Reply to author
Forward
0 new messages