1
\$\begingroup\$

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();
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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