Feb 21, 2017 at 1:48pm
Hello,
in my SDL code the window has a smaller size then
the accompanying windowsurface ? How can this be?
i need them to be the same size
pWindow = SDL_CreateWindow("title",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,windowWidth,windowHeight,SDL_WINDOW_SHOWN);
pWindowSurface = SDL_GetWindowSurface(pWindow);
now pWindowSurface->w is not the same as windowWidth , pWindowSurface->w is much bigger. same for height.
thanks for any help :)
Feb 21, 2017 at 5:10pm
Is the size of the visible window also bigger?
Feb 21, 2017 at 5:45pm
Did you do error checking when you initialized SDL?
Try this code that's basically from lazyfoo.com, does it run correctly and output 640 in the console?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <SDL2/SDL.h>
#include <cstdio>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char** args)
{
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;
if(SDL_Init(SDL_INIT_VIDEO ) < 0)
{
printf( "SDL Init has failed. SDL_ERROR: %s\n", SDL_GetError());
}
else
{
window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(window == NULL)
{
printf( "SDL Window Creation has failed. SDL_ERROR: %s\n", SDL_GetError());
}
else
{
screenSurface = SDL_GetWindowSurface(window);
printf("%d\n", screenSurface->w);
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
SDL_UpdateWindowSurface(window);
SDL_Delay(2000);
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
}
|
I tried breaking the above code, but I couldn't replicate your error. Can you post the full code?
Last edited on Feb 21, 2017 at 6:04pm