Shared Colors issue

Hello friends,
Im pretty new to OpenGL, however I feel pretty confident using libs like OpenGL, OpenGL GLU, OpenGL GLUT and GLFW in python.
But for some reasons I have really weird issue when I draw text on screen.
For that I’m using GLUT lib and here is my code for that:

def draw_text(self, text: str, x: int, y: int, font=glut.GLUT_BITMAP_9_BY_15) -> None:
    gl.glRasterPos2f(x, y)
    gl.glColor4f(0.0, 1.0, 0.0, 1.0)
    lines = text.split("\n")
    line_height = 24

    for i, line in enumerate(lines):
        y = y - i * line_height / 1.2
        for c in line:
            glut.glutBitmapCharacter(font, ord(c))

And my issue is that if I execute different function to draw something different on screen. Color from draw_text is overwritten by different method and it looks like this (GIF)

Also if I place draw_text function and after that one I add next draw_text function color is taken from second function to the first one…
Can someone please point me out what Im doing wrong in here. I will just add that this issue only happens for that specific function where I use GLUT.

Take a look at this wiki page, especially what it has about to say on glRasterPos.
TLDR: glRasterPos implicitly sets the ‘current raster color’ to the ‘current color’ and bitmap operations use the current raster color, so you need to swap the calls to glColor and glRasterPos.

1 Like

Oh thank you so much bro. Your solution has worked and Im so glad that after hours of learning I couldn’t spot that solution. There is nothing to show, but yeah your solution works great <3