Issues with fullscreen

Hi,

My program loads an image. The ENTER key toggles fullscreen mode. I have the following code:

Code:

bool fullscreen = false;

			if (fullscreen == SDL_WINDOW_FULLSCREEN)
				fullscreen = 0;
			else
				fullscreen = SDL_WINDOW_FULLSCREEN;
			SDL_SetWindowFullscreen(window, fullscreen);

The program does go into fullscreen mode, but when leaving fullscreen, the window dimensions are not the same as they were before. Is there a way to actually make it go back to the same window size, or do I have to do it explicitly using SDL_SetWindowSize()?

Also, when going into fullscreen, can I disable the automatic scaling, and display the image in its natural size, or does this also require some manual coding magic?------------------------
Daniel D’Agostino
http://www.programmersranch.com/

What resolution does your program set the window size to before fullscreen? And what resolution is it after? And how are you displaying the image? A more complete source snippet will greatly help in understanding the issue. Specifically, window creation, FS toggling (which you have) and how you are drawing the image to the screen.On Feb 26, 2014, at 1:29 PM, dandago wrote:

Hi,

My program loads an image. The ENTER key toggles fullscreen mode. I have the following code:

Code:

bool fullscreen = false;

        if (fullscreen == SDL_WINDOW_FULLSCREEN)
           fullscreen = 0;
        else
           fullscreen = SDL_WINDOW_FULLSCREEN;
        SDL_SetWindowFullscreen(window, fullscreen);

The program does go into fullscreen mode, but when leaving fullscreen, the window dimensions are not the same as they were before. Is there a way to actually make it go back to the same window size, or do I have to do it explicitly using SDL_SetWindowSize()?

Also, when going into fullscreen, can I disable the automatic scaling, and display the image in its natural size, or does this also require some manual coding magic?

Daniel D’Agostino
http://www.programmersranch.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Here you go (see code further below).

Apart from the issues I mentioned related to full-screen, I also have a problem with displaying images that are very wide. SDL_UpdateTexture() gives me an “Invalid texture” error.

Code:

#include
#include <SDL.h>
#include <SDL_image.h>

using std::stringstream;

//…

int main(int argc, char ** argv)
{
bool fullscreen = false;
bool quit = false;
SDL_Event event;

SDL_Init(SDL_INIT_VIDEO);
IMG_Init(IMG_INIT_JPG);

SDL_DisplayMode displayMode;
SDL_GetCurrentDisplayMode(0, &displayMode);

SDL_Surface * image = IMG_Load("cy4.jpg");
if (image == NULL)
	SDL_ShowSimpleMessageBox(0, "Failed", SDL_GetError(), NULL);

int windowWidth = 0.8f * displayMode.w > image->w ? image->w : 0.8f * displayMode.w;
int windowHeight = 0.8f * displayMode.h > image->h ? image->h : 0.8f * displayMode.h;

SDL_Window * window = SDL_CreateWindow("Image Viewer",
	SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
SDL_Texture * texture = SDL_CreateTexture(renderer,
	SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, image->w, image->h);

if (!(image = SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_ARGB8888, 0)))
	SDL_ShowSimpleMessageBox(0, "Failed", SDL_GetError(), window);

Uint32 * pixels = (Uint32 *) image->pixels;

while (!quit)
{
	if (SDL_UpdateTexture(texture, NULL, image->pixels, image->w * sizeof(Uint32)) != 0)
		SDL_ShowSimpleMessageBox(0, "Failed", SDL_GetError(), window);

	SDL_WaitEvent(&event);

	switch (event.type)
	{
	case SDL_KEYDOWN:
		switch (event.key.keysym.sym)
		{

//…
case SDLK_ESCAPE:
quit = true;
break;
case SDLK_RETURN:
if (fullscreen == SDL_WINDOW_FULLSCREEN)
fullscreen = 0;
else
fullscreen = SDL_WINDOW_FULLSCREEN;
SDL_SetWindowFullscreen(window, fullscreen);
break;
}
break;
case SDL_QUIT:
quit = true;
break;
}

	SDL_RenderCopy(renderer, texture, NULL, NULL);
	SDL_RenderPresent(renderer);
}

SDL_DestroyTexture(texture);
SDL_FreeSurface(image);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
IMG_Quit();
SDL_Quit();

return 0;

}------------------------
Daniel D’Agostino
http://www.programmersranch.com/