Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Tried this code, but the texture didnot get any lighter.

    try {
        texture = TextureLoader.getTexture("png",                                
           Game.class.getResourceAsStream("/brick.png"), true, GL_NEAREST);
    } catch (IOException e) {
        e.printStackTrace();
    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());

    glEnable(GL_BLEND);
    glBlendFunc(GL_CONSTANT_ALPHA, GL_CONSTANT_ALPHA);
    GL14.glBlendColor(1.0f, 1.0f, 1.0f, 0.5f);

    glColor4f(1, 1, 1, 0.5f);
    GL11.glBegin(GL11.GL_QUADS);          // Start Drawing Quads
    // Front Face
    GL11.glNormal3f(0.0f, 0.0f, 1.0f);    // Normal Pointing Towards Viewer
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(-1.0f, -1.0f, 1.0f);  // Point 1 (Front)
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex3f(1.0f, -1.0f, 1.0f);   // Point 2 (Front)
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex3f(1.0f, 1.0f, 1.0f);    // Point 3 (Front)
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex3f(-1.0f, 1.0f, 1.0f);   // Point 4 (Front)
    glEnd();
share|improve this question

1 Answer 1

up vote 2 down vote accepted

This is not how blending works, it doesn't work on the same polygon. Blending blends between more polygons (or fragments to be more correct). But you can use blending for lighting or darkening textures of course, its good idea actually.

Simple solution is to draw first quad with texture and then draw quad with blending enabled with blending color on it. But the second quad must be slightly moved to the direction of the camera. Something like this: GL11.glVertex3f(-1.0f, -1.0f, 0.99f);

Much nicer and cleaner solution would be first draw quad with texture and than qaud with color at the same position but setup zBuffer comparison function to equal.

And remember with alpha blending do not forget that you always first render opaque objects and then transparent.

And once you start using shaders this will be trivial operation on fragment/pixel shader with no need of blending.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.