Alpha doesnt work

Using JOGL, and problem is - there is no alpha. I have a PNG file that shows transparency in photoshop.

Loading texture:

	public void LoadTextureFromResource(String res,String type) throws IOException
	{
		
        InputStream stream = getClass().getResourceAsStream(res);
        TextureData data = TextureIO.newTextureData(GLProfile.getDefault(),stream,GL2.GL_RGBA,GL2.GL_RGBA, false, type);
        this.texture = TextureIO.newTexture(data);
        this.loaded = true;
	}

OpenGL init:

        GLCapabilities capabilities = new GLCapabilities(GLProfile.getDefault());
        capabilities.setHardwareAccelerated(true);
        capabilities.setNumSamples(0);
        capabilities.setAlphaBits(8);
        capabilities.setSampleBuffers(true);

        ......
       
        gl.glDisable(GL2.GL_LIGHTING);
	gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);  // <--
	gl.glEnable (GL2.GL_BLEND); 
        gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl.glClearDepth(1.0f);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);


Tried changing blend func, some modes make everything transparent, this one renders fine but without alpha.
And ofcourse, im rendering object with that texture last.

Help??

Don’t know if this will help but here is what I needed to do to get alpha textures in lwjgl.


    glEnable(GL_BLEND)
    glDisable(GL_DITHER)
    glDisable(GL_FOG)
    glDisable(GL_LIGHTING)
    glEnable(GL_LINE_SMOOTH)
    glDisable(GL_TEXTURE_1D)
    glEnable(GL_TEXTURE_2D)

    //glShadeModel(GL_FLAT)
    glShadeModel(GL_SMOOTH)

    //glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_FRONT, GL_FILL)

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)
    glEnableClientState(GL_COLOR_ARRAY)

Almost everything i have ??? :-\

You have depth testing enabled, which will defeat blending. You need to disable it.

still doesn’t work, and i see poligons thru walls.

ok made a progress, removed default color from objects, only texture now.

now on areas where should be transparent, i have red color? :smiley:

EDIT: its not the background, background is blue

ok, found a problem: gl.glTexEnvi (GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_DECAL);

after removing* that transparency works, but everything is red… its red becouse of font rendering.

is there a way to reset opengl color after calling glColor?? and another way to use only texture color no lights?

Seems like R and A are in the wrong place (GL2.GL_RGBA).

Is there an GL_ARGB version?

setting glColor to white, fixes the problem… but the scene is a little brighter.

The following code was causing alpha to fail:

gl.glTexEnvi (GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_DECAL);