problems around GL_POINT_SPRITE_ARB (solved)

Hello!

I downloaded a demo program from : http://www.codesampler.com/oglsrc.htm in the “Point Sprites” demo. code: http://www.codesampler.com/source/ogl_point_sprites.zip

I ported to JOGL, and I don’t see blending with texture.
I modified the particle texture file with alpha chanell, but nothing happened.

My code:
int[] particlePic = new int[0];
particlePic[0] = loadTGAImage(“d:\particle.tga”, false);

gl.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
gl.glBindTexture( GL.GL_TEXTURE_2D, particlePic[0] );
gl.glEnable( GL.GL_TEXTURE_2D );

gl.glEnable( GL.GL_BLEND );
gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE );

float[] maxSize = new float[1];
gl.glGetFloatv( GL.GL_POINT_SIZE_MAX_ARB, maxSize );
if( maxSize[0] > particleSize )
maxSize[0] = particleSize;
gl.glPointSize( maxSize[0] );
gl.glPointParameterfARB( GL.GL_POINT_FADE_THRESHOLD_SIZE_ARB, 60.0f );
gl.glPointParameterfARB( GL.GL_POINT_SIZE_MIN_ARB, 0 );
gl.glPointParameterfARB( GL.GL_POINT_SIZE_MAX_ARB, maxSize[0] );
gl.glTexEnvf( GL.GL_POINT_SPRITE_ARB, GL.GL_COORD_REPLACE_ARB, GL.GL_TRUE );
gl.glEnable( GL.GL_POINT_SPRITE_ARB );
gl.glBegin( GL.GL_POINTS );
for( Particle p : particles ) {
gl.glColor4f( p.color.r, p.color.g, p.color.b, 1.0f );
gl.glVertex3f( p.absolutePos.x, p.absolutePos.y, p.absolutePos.z );
}
gl.glEnd();

    gl.glDisable( GL.GL_POINT_SPRITE_ARB );
    gl.glDisable( GL.GL_BLEND );
    gl.glDisable( GL.GL_TEXTURE_2D );

The code is quite is the same as in the downloaded demo.
(except the difference of the programming alnguages and Opengl environment…)
What did I wrong?

Thanks!

screenshot: http://delfin.klte.hu/~fazekaim/sprite.jpg
quads and no blending :frowning:

Did you turn on textures?

gl.glEnable( GL.GL_TEXTURE_2D );

Did you create a texture ID?

gl.glGenTextures( 1, particlePic );

Did you load it to OpenGL

gl.glTexImage2D( … );

ok, sorry. I have forgatten the texture loader methode:
public static int loadTGAImage( String path, boolean clamping ){
int[] tmp = new int[1];
gl.glGenTextures( 1, tmp );
ExtendedTGATextureLoader loader = new ExtendedTGATextureLoader(gl, glu);
loader.readTextureFromFile( path ); // tga loading
if(loader.isOk()){
gl.glBindTexture( GL.GL_TEXTURE_2D, tmp[0] );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
if( clamping ){
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
}
glu.gluBuild2DMipmaps(
GL.GL_TEXTURE_2D,
getCompressedType( loader.getGLFormat() ),
loader.getImageWidth(), loader.getImageHeight(),
loader.getGLFormat(),
GL.GL_UNSIGNED_BYTE,
loader.getTexture()
);
}
else{ System.out.println(“Error loading tga image” ); System.exit(-1); }

    return tmp[0];
}

volia.
No warning, ne errors :frowning:


    public static int loadTGAImage( String path, boolean clamping ){
        int[] tmp = new int[1];
        gl.glGenTextures( 1, tmp );
        ExtendedTGATextureLoader loader = new ExtendedTGATextureLoader(gl, glu);
        loader.readTextureFromFile( path ); // tga loading
        if(loader.isOk()){
            gl.glBindTexture( GL.GL_TEXTURE_2D, tmp[0] );
            gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
            gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
            if( clamping ){
                gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
                gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
            }
        glu.gluBuild2DMipmaps(
                GL.GL_TEXTURE_2D,
                getCompressedType( loader.getGLFormat() ),
                loader.getImageWidth(), loader.getImageHeight(),
                loader.getGLFormat(),
                GL.GL_UNSIGNED_BYTE,
                loader.getTexture() );

        // check if the texture has been compressed
        int wasCompressed[] = new int[1];
        gl.glGetTexLevelParameteriv( GL.GL_TEXTURE_2D,
                                       0,
                                       GL.GL_TEXTURE_COMPRESSED_ARB,
                                       wasCompressed );

        // Query for the compressed internal format */
        glInternalFormat = new int[1];
        c.gl.glGetTexLevelParameteriv( GL.GL_TEXTURE_2D, 
                                       0, 
                                       GL.GL_TEXTURE_INTERNAL_FORMAT, 
                                       glInternalFormat );

        // check the amount of memory used by the compressed texture
        glCompressedSize = new int[1];
        c.gl.glGetTexLevelParameteriv( GL.GL_TEXTURE_2D,
                                       0,
                                       GL.GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
                                       glCompressedSize );

        System.out.println("Texture Compression: ");
        System.out.println("     Was Compressed: " + wasCompressed[0] );
        System.out.println("             Before: " + (texture.width * texture.height * 4) + " After: " + glCompressedSize[0] );
        System.out.println("    Internal Format:" + glInternalFormat[0] );
        
        } else { 
            System.out.println("Error loading tga image" ); System.exit(-1); 
        }

        return tmp[0];
    }     

What output do you get when you run this modified version?

I think the problem is the compressed format used when calling gluBuild2DMipMaps.

Try a test hard coding the values to GL.GL_COMPRESSED_RGBA_ARB, and GL.GL_RGBA.

That is if the alpha channel was loaded.

Try this as well, given the Width and Height of the texture, multiple that by 4. Does the result of this match the size of the buffer returned by loader.getTexture()?

I replaced my code with yours.
This is the output:
Texture Compression:
Was Compressed: 1
Before: 16384 After: 4096
Internal Format:33779

I tried not to use compression, and then not to use mipmapping, but the result is the same.
Could be a bug in jogl?

StarBuck would say “Frack!”.

Can you post the entire source code?

Also, are you running an ATI video card?

:frowning: Brrrrrr!!!

It was a textureID problem. It’s working now.
Thanks. :slight_smile: