SDL2 Texture

Started by
7 comments, last by Hanksha 10 years, 3 months ago

Hi,

I've been trying to load large images (like 5000x2000, basically of map back ground) into an SDL_Texture*

Example:


SDL_Texture* image;

image = IMG_LoadTexture(renderer,"data/test.png");

But with a large resolution the image can't be load into the texture, with lower resolution like 1280x720 it works fine.

Is there a limit of size for an SDL_Texture?

Advertisement

Well, since SDL_Texture is a small veneer over OpenGL textures, it is most likely not an SDL issue.

The first an most likely issue is you are running < OpenGl 2.0. In this case, you need to have your texture dimensions be Power of Two in size. Meaning your width or height should be 2,4,8,16,32,64,128,256,512, etc...

The second most common reason is you are exceeding YOUR graphic cards maximum texture size. This is device specific, so it will depend on the machine you run on. 5000 is probably two wide, depending on your card. Try scaling down to 4096 width and see what happens ( A common size limit ).

(Sorry for late answer)

Yes apparently after few test, the limit looks to be 4096x4096.

Is there any documentation about that? (I didn't see anything on wiki of SDL2)

(Sorry for late answer)

Yes apparently after few test, the limit looks to be 4096x4096.

Is there any documentation about that? (I didn't see anything on wiki of SDL2)

The documentation is from the OpenGL spec. Unfortunately all you will see is "driver dependant". Basically meaning its up to the company implementing the drivers.

You may be able to get documentation on this from the device manufacturer, but that wouldn't be fun. There is however a GL call that allows you to query the maximum texture size, SDL may implement it, i am not sure.

So if I put a large background 4096x4096, I might encounter a case of a computer who could not load it? (I've done 5 or 6 test on computers but most of them were not old)

So if I put a large background 4096x4096, I might encounter a case of a computer who could not load it? (I've done 5 or 6 test on computers but most of them were not old)

Yes this is true; you need to establish a baseline machine.

4096x4096 is a reasonable MODERN minimum. If you want to support as many machines as possible, 2048x2048 is a better call.

Intel Integrated graphics are about the baseline of 3D GPUs and as you can see from the documentation some of the HD3000 models have a hard limit of 2048:

Max 2d texture

2K x 2K

4K x 4K

4K x 4K

2K x 2K

4K x 4K

Max 3d texture

2048 x 2048 x 256

8092 x 8092 x 256

8092 x 8092 x 256

2048 x 2048 x 256

8092 x 8092 x 256

That said, the last 2k x 2k GPU was in 2007.

The HD3000 is a good choice of baseline chips, as it is used in a TON of laptops and is also the base chip for most iMacs created in the past 6 or so years.

Interesting! I'll follow your advice. I'll make a function to detect the GPU of the user so it could send a message error if it can't load texture because of that.

Interesting! I'll follow your advice. I'll make a function to detect the GPU of the user so it could send a message error if it can't load texture because of that.

No need for that. SDL_GetRendererInfo will return a pointer to a SDL_RendererInfo object. You can check the max_texture_width and max_texture_height fields to see if your texture will fit.

By make a function I meant use an SDL one : )

This topic is closed to new replies.

Advertisement