SDL_RenderCopy

Dear friends,

I am using SDL 2.0 on Microsoft Windows 7, and I have 2 questions:

I am rendering a texture into a window by using the SDL_RenderCopy() function, but I would like to render it into a memory buffer instead.
Can this be done?
If yes, how?
The SDL_CreateRenderer() function receives a window as a first parameter. Can I apply this function on a memory buffer?
2.
I would like to render 2 textures into the same window (in different places) using the SDL_RenderCopy() or alike, with SDL 2.0.
I understand that this can be done using surfaces as applied in SDL version 1.1, but this method is not as efficient as the SDL_RenderCopy() .
Can this be done?

Thanks,

Avi Tal.

2012/9/23 avi_tal <avi_tal at 012.net.il>

**
Dear friends,

I am using SDL 2.0 on Microsoft Windows 7, and I have 2 questions:

I am rendering a texture into a window by using the SDL_RenderCopy()
function, but I would like to render it into a memory buffer instead.
Can this be done?
If yes, how?
The SDL_CreateRenderer() function receives a window as a first parameter.
Can I apply this function on a memory buffer?

See the documentation for
http://wiki.libsdl.org/moin.cgi/SDL_SetRenderTarget this will let you
render using SDL_RenderCopy to a texture instead of the directly to the
screen buffer.

I would like to render 2 textures into the same window (in different
places) using the SDL_RenderCopy() or alike, with SDL 2.0.
I understand that this can be done using surfaces as applied in SDL
version 1.1, but this method is not as efficient as the SDL_RenderCopy() .
Can this be done?

Yes, just change the destination coordinates to where you want the textures
to go and that’s it. SDL_RenderCopy will resize the texture if the source
and destination rects are of different size.–
Gabriel.

What do you mean by ‘already stretching’?

Hi ,
I’m new with SDL2
first of all please forgive my bad english full of mistakes
If i use
SDL_RenderCopy(renderer,texture,NULL,NULL)
the texture is stretching to fill whole window even if the texture is different size(very good function)
but when i use
SDL_RenderCopy (renderer,texture,&src,&dst)
to reblit only a portion of the background image
and the texture is different as say before
i take a different part of the texture
(in that case library don’t need to make any scaling)
I know, if i repeat SDL_RenderCopy with NULL all is ok
but became very slow
So how i take or copy only a portion of existing texture already stretching and the use this to replace background ?
different advice are welcome.
Many thanks
Luigi

Hi

Given that you’re currently using renderer/texture API (and the platform is HW accelerated), the scaling of texture is done in Hardware. It should be as fast as rendering textures with no scaling.

You can also pre-stretch the texture by render it to another render (using render target), but I don’t think it would be any better than just render directly to the screen.

Are you really sure that the scaling cause the performance drop ?

@Scap_Pato, please don’t apologize , you did nothing wrong :slight_smile:

I’ve just noticed that you’re running on RPi. Well from the read me, RPi actually supports HW acceleration through OpenGL ES 2.

If you’re still find it slow, you might use the RenderTarget API to render a texture to another texture (please check first if it’s supported or not), so the texture is resized/stretched.

Better still, btw, is to resize the file directly before running the program. This requires that the size is known and fixed, which might not be the case of your situation.

I have a question though. How did you work with the RPi ? Are you connecting monitor+mouse/keyboard to the RPi directly or use ssh terminal to the machine ? What is your OS?

I haven’t try running SDL app on RPi yet. When I tried XBMC, which uses OpenGL, it was pretty fast.

Sorry for my late reply
I’ll try to explain , please excuse me
Suppose we have background image bk.jpg 800600
and we have monitor e.g. 1100
700

  1. oursurface=IMG_LoadTexture(renderer,?./bk.jpg?);
  2. ourtexture=SDL_CreateTextureFromSurface (oursurface)
    (of course we can create texture directly from jpg and i don’t know which is better)
    render bk image
  3. SDL_RenderCopy(renderer,ourtexture,NULL,NULL)
    4 ) SDL_RenderPresent(renderer)
    SDL stretch the texture to fill the entire screen(great)
    Now we have to move a little sprite over the background but before this we have to redraw
    the portion over the sprite was and then draw the new sprite.
    Now if i use 3) i redraw all the screen but very slowly (raspberrry pi) and the background is ok
    I want to redraw only rect where sprite was.
    This is the issue
    i.e. suppose the sprite was at x=200 y=200 w=h=100; rect_1
    SDL_RenderCopy(renderer,ourtexture,&rect_1,&rect_1)
    we take from bk.jpg portion at x=200 y=200 but the screen in the same position has different pixels due to scaling
    So how can i redraw the portion of screen from bk.image with the same scale value?
    many thanks
    luigi

thanks for your reply
I believe that raspberry is SW accelerated
when i bring an image and put into screen (fullscreen) SDL make for us all the scaling to fill screen
so SDL stretch or shrink the image to fit screen at better scale
Now i don’t know exactly which conversion SDL set to my image ( w scaling maybe different from h scale value)
and I don’t know before will be the screen .
So i would like to copy the texture modified (and not of course my original eg 800*600 image ) by SDL to fit the screen and use this to redraw the background’s modified part .
I know , i’m very dummy, but i don’t know how get copy of image modified by SDL and use this .
Forgive my english.

Thank for your advice;
first of all i did
window=SDL_CreateWindow{?test?,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
0,0,
SDL_WINDOW_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL
}

but raspberry reply

GLX is not supported (trough SDL_GetError)

without SDL_WINDOW_OPENGL work but as i wrote before
redraw entire window isn’t so fast
I’m working over next advice
you’re right when you say is better to set the back image for the screen but we don’t know before which monitor will be used

I believed that ?SDL resized the image for me now i use that resized image over and over…"
(but i don’t know how)

Wheezy os
Monitor mouse and keyboard
Directly?
We use a lot of gpio for our application
I know XBMC is pretty good but before change I’ll try to fix with Wheezy
Sdl make a conversion to my bk image
Resize the image
My dummy idea was where is the resized image and how
I getReply from mobile