1

I'm trying to draw a gradient and then draw a transparent texture ontop of it.

This is the code I'm using right now:

GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);

// Draw the gradient
GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glColor4f(1F, 1F, 1F, 0F);
    GL11.glVertex3f(0, 0, 0.0f);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glColor4f(0F, 1F, 1F, 0F);
    GL11.glVertex3f(0 + gameWidth, 0, 0.0f);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glColor4f(0F, 0F, 1F, 0F);
    GL11.glVertex3f(0 + gameWidth, 0 + gameHeight, 0.0f);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glColor4f(1F, 0F, 1F, 0F);
    GL11.glVertex3f(0, 0 + gameHeight, 0.0f);
GL11.glEnd();
GL11.glColor4f(1F, 1F, 1F, 0F);

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);

TexLoader.loadTex("/example.png"); // Loads and binds the texture, also enables GL_TEXTURE_2D
GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(parX, parY, 0.0f);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex3f(parX + parWidth, parY, 0.0f);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex3f(parX + parWidth, parY + parHeight, 0.0f);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex3f(parX, parY + parHeight, 0.0f);
GL11.glEnd();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);

However, instead of drawing the texture and hiding the transparent pixels it just draws a white quad.

What am I doing wrong?

genpfault
  • 51,148
  • 11
  • 85
  • 139
user2102293
  • 53
  • 1
  • 7
  • One problem (possibly not the only one) is that your gradient colors all have a 0 alpha. The alpha should be 1 if you want the gradient to be visible. – user1118321 Mar 22 '13 at 18:04
  • oops, thank you. However, for some reason, the gradient `is` visible? – user2102293 Mar 22 '13 at 18:16
  • Yes, as blending is not enabled for the gradient, the zero alpha is not relevant. It *is* relevant for the textured quad, unless you've set the texture mode to decal (or applied a shader which ignores vertex colours). Are you sure the texture has even been loaded? – JasonD Mar 23 '13 at 07:20
  • Yes, the texture has been loaded. If I remove the gradient and the blend code, it draws the texture completely fine. – user2102293 Mar 23 '13 at 12:58

0 Answers0