Non power of 2 texture?

I am trying to load textures into JOGL.

Whenever I load pictures in, it finds the nearest power of 2 resolution and uses them instead. What is happening? From what I can read the TextureIO-class should take care of this for me and make it the right resolution :frowning:

I’m usin the following code:


	public static Texture load(String fileName){
		Texture text = null;
		try{
//                                            TextureIO.setTexRectEnabled(true);
			text = TextureIO.newTexture(new File(fileName), true);
			text.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
			text.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
		}catch(Exception e){
			System.out.println(e.getMessage());
			System.out.println("Error loading texture " + fileName);
		}
		return text;
	}

And this is the context:


public class SpriteBuffer {

    Texture spriteSheet;
    int dimX,dimY;
    double memory;
    double frameWidth,frameHeight;
    int rows,cols;
    int[][] frames;
    DisplaylistManager dManager;
    double pixelX,pixelY;
    
    
    public SpriteBuffer(String filename, int rows, int cols){
        
        spriteSheet = TextureLoader.load(filename);
        dimX = spriteSheet.getImageWidth();
        dimY = spriteSheet.getImageHeight();
        memory = spriteSheet.getEstimatedMemorySize();
        this.rows = rows;
        this.cols = cols;
        this.frameHeight = 1/(double)rows;
        this.frameWidth = 1/(double)cols;
        pixelX = spriteSheet.getWidth()/cols;
        pixelY = spriteSheet.getHeight()/rows;
        
        dump(filename);
        this.dManager = DisplaylistManager.getInstance();
        
        frames = dManager.getSpriteList(this);
    }
    
    
    
    public void dump(String filename){
        System.out.println("Filename: "+filename);
        System.out.println("pixelX: "+pixelX+" pixelY: "+pixelY);
        System.out.println("Framewidth: "+frameWidth+ " Frameheight: "+frameHeight);
        System.out.println("rows: "+rows+" cols: "+cols);
        System.out.println("dimX: "+dimX+" dimY: "+dimY);
        System.out.println("1/cols: "+frameWidth);
    }
    

    
    
}

An example is a picture “Attandrunn.png” which is 200x2400. It loads it in as dimX: 256 dimY: 4096. Which is not really the right resolution.

What is going on?

If you have an old graphics card, they can’t support non power of two textures. TextureIO probably detects that and instead of crashing and burning, it makes your image bigger. Of course this isn’t the greatest solution since automated scaling can cause artifacts. It is better, especially when client hardware is unknown and probably limited, to just use power of two textures instead.

Thanks for the fast reply.

It is highly appreciated. Do you know if this is the “standard” approach when creating games? Just sticking to power of 2 textures?

The game i’m making is a 2d RPG for low to midrange computers.

I don’t know if it’s standard, but I heard the advice from somewhere reasonable so I’d stick with it, especially if it’s for low to midrange computers. Also, for a 2D game power of two sprites shouldn’t be very limiting. Keep in mind also that you were using a rectangular texture, which probably won’t be supported on older cards (and can sometimes hurt performance). It’s better to split background images into tiles, so that you only need to draw quads on screen, and the graphics card won’t have to access as large of textures to render the background (sometimes incredibly large textures perform worse).