Main Menu

Scaling Error

Started by xindon, June 20, 2006, 18:40:45

Previous topic - Next topic

xindon

OpenGL doesn't like non power of two textures, you all now that.
So I want to resize unsuitable textures while loading them.

Here my code:



       IL.ilGenImages(tmp);
        IL.ilBindImage(tmp.get(0));

        // Load the image
        IL.ilLoadImage(filename)

        // Convert the image to RGBA
        IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);

        // Image attributes
        this.width = IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
        this.height = IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
        int desiredWidth = getNextPowerOfTwo(this.width);
        int desiredHeight = getNextPowerOfTwo(this.height);
        
        
        // Resize image 
        if (desiredWidth != width || desiredHeight != height) {
            
            System.out.println("Resize...");
            ILU.iluImageParameter(ILU.ILU_FILTER, ILU.ILU_BILINEAR);                            
            ILU.iluScale(desiredWidth, desiredHeight, IL.ilGetInteger(IL.IL_IMAGE_DEPTH)); 
        }
        
    
        // Get Image data
        imageData = IL.ilGetData();

        /* create the texture in opengl */ ...


After rescaling, IL.ilGetInteger(IL.IL_IMAGE_WIDTH) and (...HEIGHT) really return a new size (2^n). But in the end OpenGL doenst get a new suitable texture; it still uses the screwed original, which makes OpenGL starve to death. I guess about 1-2FPS.

What's the problem? I don't really understand what's going on.

Thanks very much

Fool Running

I'm not sure if this is the cause of your problems (seems likely if those values create the OpenGL texture), but you aren't updating this.width and this.height with the new values.

If this doesn't help, it might help us if you show the /* create the texture in opengl */ part...

Also, you might try to replace IL.ilGetInteger(IL.IL_IMAGE_DEPTH) with a 1...

All I can think of :lol:
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

xindon

Quote from: "Fool Running"I'm not sure if this is the cause of your problems (seems likely if those values create the OpenGL texture), but you aren't updating this.width and this.height with the new values.

Argh, d'oh :)

That was the problem; I didn't see that they're required in future steps. Now everything works fine.  Thank you very much




       // Resize image 
        if (desiredWidth != width || desiredHeight != height) {
            
            System.out.println("Resize...");
            ILU.iluImageParameter(ILU.ILU_FILTER, ILU.ILU_BILINEAR);                            
            ILU.iluScale(desiredWidth, desiredHeight, IL.ilGetInteger(IL.IL_IMAGE_DEPTH)); 
            
            // Update texture variables
            this.width = desiredWidth;
            this.height = desiredHeight;            
        }