I want to use texture repeat with SDL2 (SDL_RenderCopy), and couldn't find how. by texture repeat I mean to give texture coords twice the size of the texture and have it tiled twice over the surface. like this: http://www.felixgers.de/teaching/jogl/textureClamp.html
anyone knows how to do it in SDL? do I need to access openGL functions myself?
thanks,
It's not an ideal solution but if you don't want to go down the route of using OpenGL functions:
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, DEFAULT_TEXTURE_WRAP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, DEFAULT_TEXTURE_WRAP );
Then you could calculate the source and destination rects on the fly as you draw. For example lets imagine you have a texture that is 100x100 and a screen drawing area 150x150. Starting at the top left you would see you can fit the full texture in on the first call
SDL_Rect dest = {0,0,100,100}
SDL_RenderCopy(renderer, texture, NULL, &dest);
---------
| | |
| | |
------ |
| |
---------
So now you can see that you have to draw only 50 pixels width of the texture but still the full height and starting at the point 100,0
SDL_Rect src = {0,0,50,100}
SDL_Rect dest = {100,0,50,100}
SDL_RenderCopy(renderer, texture, &src, &dest);
---------
| | |
| | |
--------|
| |
---------
You could work that in to a bit of an iteration and tidy up the calculation to get it to work for you. As I say it isn't ideal but it is an alternative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With