4
\$\begingroup\$

With SDL2 I created texture1 of 28800 x 28800 which contains a drawing of a grass background all over the texture.

Then I created texture2 of 2880 x 1620.

Then I set the render target to texture2.

The I set the logical size to 2880 x 1620.

The I renderclear texture2.

Then I rendercopy a rectangle of 2880 x 1620 from texture1 to texture2

Then I renderpresent texture2 but my screen is black.

Is that because I am trying to copy from a larger texture to a smaller texture? What are the limits when it comes to copying from texture to texture with SDL2?

Let me know if you need my code and where to put it. Some websites don't like it when you put your code in a post.

\$\endgroup\$
  • 1
    \$\begingroup\$ Have you checked all the return values of SDL functions? \$\endgroup\$ – congusbongus Nov 9 '15 at 0:35
  • \$\begingroup\$ 28800x28800 might be way too large size for a texture. Definitely check your calls with SDL_GetError as suggested. \$\endgroup\$ – Tyyppi_77 Nov 9 '15 at 9:50
  • \$\begingroup\$ Thank you very much! I checked the error and it reported dimensions of a texture cannot exceed 16384 x 16384. I reduced the size of the textures and my program now works as planned. \$\endgroup\$ – Seb0029 Nov 9 '15 at 22:52
1
\$\begingroup\$

28800 x 28800 may be way too big for a texture. When using textures, SDL is basically a shim over OpenGL/DirectX which talks directly with your graphics card. Texture size limits will depend on your hardware - better graphics cards can use larger textures. For example, OpenGL provides an integer variable GL_MAX_TEXTURE_SIZE which represents the maximum width and height supported by the current graphics hardware. According to this crowd-sourced report by Wildfire Games, about 44% of its users' machines support the highest value available, 16384. Those figures may change as new hardware is released.

Keep in mind that if this 28800 x 28800 texture were stored uncompressed, it would be a little over 3 GB, which as of writing requires a mid-level discrete graphics card to even fit in memory. It may be tempting to, for example, use a single mega texture for the entire map, but most games don't do this because this takes up so much memory, which is why techniques like tiling are so common. Whatever your reason for using that giant texture, there's probably a more conventional, memory-efficient alternative.

Finally, for C libraries like SDL2, the convention is to check all return values of functions, since C doesn't have exceptions. Typically, functions return an error code or, in SDL2's case, simply an error indicator like -1, after which you can find out the exact error with a function like SDL_GetError(). Failing to do this means you may experience errors that are difficult to diagnose, as this question shows.

\$\endgroup\$
  • \$\begingroup\$ Thanks! Solved it by making a grid-based map composed of small surfaces (8x8 pixels) converted to textures. \$\endgroup\$ – Seb0029 Dec 4 '17 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.