Problem to display texture correctly

Hi everybody,

I created a SDL_Surface with width=1920 and height=1080,
I want to display it with the following source code but it doesn’t work fine.

 SDL_Texture* video_texture = SDL_CreateTextureFromSurface(m_sdl_renderer,frame_received);

if(video_texture)
{
    SDL_RenderClear(m_sdl_renderer);
    SDL_RenderCopy(m_sdl_renderer, video_texture, NULL,NULL);
    SDL_RenderPresent(m_sdl_renderer);
    SDL_DestroyTexture(video_texture);
}

My windows size are : width=440 and height=445;

After display, my texture is fully displayed but not on total surface of window.
even with the following instruction
SDL_RenderCopy(m_sdl_renderer, video_texture, NULL,NULL);

Could you help me to find the problem ?

Thanks a lot

Cyrille Herlem

PS: I use SDL_CreateWindowFrom() to create my window

Dear Cyrille,

First of all, you should check if the texture is created properly.
if (!video_texture) {
printf(“Creation of video texture failed: %s\n”, SDL_GetError());
SDL_Quit();
exit(1);
}

Next, in stead of calling
SDL_RenderCopy(m_sdl_renderer, video_texture, NULL,NULL);
With NULL, NULL

You may want to pass in two SDL_Rect rectangles to control more precisely the drawing of the texture.
{
SDL_Rect src_rect = { 0, 0, 440, 445 }
SDL_Rect dst_rect = { 0, 0, 440, 445 }
SDL_RenderCopy(m_sdl_renderer, video_texture, &dst_rect, &src_rect);
SDL_RenderPresent(m_sdl_renderer);
}

Finally, it’s going to be very slow if you create and destroy such a big texture all the time
whilst drawing, so I don’t see why you need the SDL_DestroyTexture there, especially if you are in
a drawing loop.

Kind Regards,

B.