Skip to content Skip to sidebar Skip to footer

Draw Rectangle Over Texture Opengl

I'm using python 3 with pygame and OpenGL to try to accomplish what I thought it would be a simple task: Drawing a rectangle. The idea is to have a white rectangle over (or bellow)

Solution 1:

You have to enable two-dimensional texturing before you draw the texture, as you do it (glEnable(GL_TEXTURE_2D)).

But you have to disable two-dimensional texturing again, before you draw the rectangle:

# draw rectangle
glDisable(GL_TEXTURE_2D)
glColor3fv((1, 1, 1))
glRectf(-1, 1, 0, 0.5)

Note, the texture is still bound, when you draw the rectangle. Since you do not provide texture coordinates, when you draw the rectangle. This causes that the current texture coordinate is applied to the rectangle and a single texel is drawn all over the rectangle.

e.g. The last texture coordinate set was glTexCoord2f(1, 0):

issue

Further note, if you would change the color for the rectangle, then the entire texture get tint by this color. If texturing is enabled, then by default the color of the texel is multiplied by the current color, because by default the texture environment mode (GL_TEXTURE_ENV_MODE) is GL_MODULATE. See glTexEnv.

glDisable(GL_TEXTURE_2D)
glColor3fv((1, 0, 0))    # red
glRectf(-1, 1, 0, 0.5)

tint

Set the "white" color before you draw the texture:

glEnable(GL_TEXTURE_2D)
glColor3fv((1, 1, 1))

fix

Post a Comment for "Draw Rectangle Over Texture Opengl"