Want to maintain the same texture size in fullscreen mode


#1

SDL_Window * window = SDL_CreateWindow(“SDL Window”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0,
| SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN );

SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE );

SDL_RenderSetLogicalSize(renderer, 320, 240);

SDL_Texture * texture = SDL_CreateTexture (renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, 160,120);
.
.
.
.
.
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);


from the SDL wiki I came to know that “Use SDL_RenderSetLogicalSize function to set a device independent resolution for rendering.”
But then why my texture is going full-screen even though i am using SDL_RenderSetLogicalSize.

Any help will be warmly appreciated.


#2

Probably because you used NULL,NULL
You should specify the area of the screen where you want the texture displayed. You are telling it to display it full screen.


#3

Thanx a lot…

SDL_Rect SrcR;
** SDL_Rect DestR;**

** SrcR.x = 0;**
** SrcR.y = 0;**
** SrcR.w = 160;**
** SrcR.h = 120;**

** DestR.x = 50;**
** DestR.y = 50;**
** DestR.w = 320;**
** DestR.h = 240;**

SDL_Window * window = SDL_CreateWindow(“SDL Window”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN );

SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE );

**SDL_Texture * texture = SDL_CreateTexture (renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, 160,120); **
.
.
.
.
.

** SDL_RenderClear(renderer);**
** SDL_RenderCopy(renderer, texture, &SrcR, &DestR);**
** SDL_RenderPresent(renderer);**

now its working , but without the SDL_RenderSetLogicalSize only, and the texture is is somehow a little bigger than 320*240.


#4

You probably shouldn’t use constants for the dst rectangle x and y, unless if you make your app specific for one single devices. The x coordinate should be something like (windows_width-320)/2, and the same for y.

The src rectangle you need to modify only if you want to put part of the texture on screen, otherwise leave it NULL.

Anyway, can you be more specific on what you are trying to do?


#5

sorry for the late reply,
I am actually trying to display a (only)video in the screen.


#6

Is your code device specific? Because if you do this on some devices, such as very high DPI phones or laptops 320x240 can be just a few square cm big, so that’s not really ideal.


#7

yes it is device specific, and the resolution of its is 640*480.
And by

only if you want to put part of the texture on screen

did you meant cropping the texture?


#8

Yes, by specifying the src rectangle you can crop the texture. If you pass null instead, it puts the entire texture on screen.


#9

it is giving errror, is it the right way ?


#10

No, I mean make the entire SrcR pointer null.


#11

Also, the way you set up your DestR your video is going to be on the upper left side, not centered.


#12

still not working , is it something has to do with this ->link .
Can you give me a simple example to pass null pointer?


#13

Try: SDL_RenderCopy(renderer, texture, NULL, DestR);
Delete line 83


#14

Thank you, it did worked.