Make controllermap, etc, work on platforms with hardcoded window sizes. This makes sure everything renders correctly, even if, say, an Android device gives you a certain "window" size no matter what you ask for.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/test/controllermap.c b/test/controllermap.c
index f990ff4..e6e9607 100644
--- a/test/controllermap.c
+++ b/test/controllermap.c
@@ -101,7 +101,7 @@ WatchJoystick(SDL_Joystick * joystick)
{
SDL_Window *window = NULL;
SDL_Renderer *screen = NULL;
- SDL_Texture *target, *background, *button, *axis, *marker;
+ SDL_Texture *background, *button, *axis, *marker;
const char *name = NULL;
SDL_bool retval = SDL_FALSE;
SDL_bool done = SDL_FALSE, next=SDL_FALSE;
@@ -152,12 +152,14 @@ WatchJoystick(SDL_Joystick * joystick)
return SDL_FALSE;
}
- target = SDL_CreateTexture(screen, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, MAP_WIDTH, MAP_HEIGHT);
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
SDL_RaiseWindow(window);
+ /* scale for platforms that don't give you the window size you asked for. */
+ SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
+
/* Print info about the joystick we are watching */
name = SDL_JoystickName(joystick);
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
@@ -206,7 +208,9 @@ WatchJoystick(SDL_Joystick * joystick)
dst.y = step->y;
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
next=SDL_FALSE;
-
+
+ SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
+
while (!done && !next) {
if (SDL_GetTicks() - alpha_ticks > 5) {
alpha_ticks = SDL_GetTicks();
@@ -219,13 +223,11 @@ WatchJoystick(SDL_Joystick * joystick)
}
}
- SDL_SetRenderTarget(screen, target);
+ SDL_RenderClear(screen);
SDL_RenderCopy(screen, background, NULL, NULL);
SDL_SetTextureAlphaMod(marker, alpha);
SDL_SetTextureColorMod(marker, 10, 255, 21);
SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
- SDL_SetRenderTarget(screen, NULL);
- SDL_RenderCopy(screen, target, NULL, NULL);
SDL_RenderPresent(screen);
if (SDL_PollEvent(&event)) {
diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c
index e7c1e05..f762ce6 100644
--- a/test/testgamecontroller.c
+++ b/test/testgamecontroller.c
@@ -170,6 +170,9 @@ WatchGameController(SDL_GameController * gamecontroller)
SDL_RenderPresent(screen);
SDL_RaiseWindow(window);
+ /* scale for platforms that don't give you the window size you asked for. */
+ SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
+
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
@@ -191,7 +194,7 @@ WatchGameController(SDL_GameController * gamecontroller)
/* Loop, getting controller events! */
while (!done) {
/* blank screen, set up for drawing this frame. */
- SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
+ SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
SDL_RenderClear(screen);
SDL_RenderCopy(screen, background, NULL, NULL);