Fixed rendering in the iOS touch demo
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
diff --git a/Xcode-iOS/Demos/src/touch.c b/Xcode-iOS/Demos/src/touch.c
index 470b9d1..6f727e4 100644
--- a/Xcode-iOS/Demos/src/touch.c
+++ b/Xcode-iOS/Demos/src/touch.c
@@ -81,6 +81,7 @@ main(int argc, char *argv[])
SDL_Event event;
SDL_Window *window; /* main window */
SDL_Renderer *renderer;
+ SDL_Texture *target;
int done; /* does user want to quit? */
int w, h;
@@ -100,29 +101,38 @@ main(int argc, char *argv[])
initializeTexture(renderer);
/* fill canvass initially with all black */
+ target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h);
+ SDL_SetRenderTarget(renderer, target);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
- SDL_RenderPresent(renderer);
+ SDL_SetRenderTarget(renderer, NULL);
done = 0;
- while (!done && SDL_WaitEvent(&event)) {
- switch (event.type) {
- case SDL_QUIT:
- done = 1;
- break;
- case SDL_MOUSEMOTION:
- state = SDL_GetMouseState(&x, &y); /* get its location */
- SDL_GetRelativeMouseState(&dx, &dy); /* find how much the mouse moved */
- if (state & SDL_BUTTON_LMASK) { /* is the mouse (touch) down? */
- drawLine(renderer, x - dx, y - dy, dx, dy); /* draw line segment */
- SDL_RenderPresent(renderer);
+ while (!done) {
+ while (SDL_PollEvent(&event) == 1) {
+ switch (event.type) {
+ case SDL_QUIT:
+ done = 1;
+ break;
+ case SDL_MOUSEMOTION:
+ state = SDL_GetMouseState(&x, &y); /* get its location */
+ SDL_GetRelativeMouseState(&dx, &dy); /* find how much the mouse moved */
+ if (state & SDL_BUTTON_LMASK) { /* is the mouse (touch) down? */
+ SDL_SetRenderTarget(renderer, target);
+ drawLine(renderer, x - dx, y - dy, dx, dy); /* draw line segment */
+ SDL_SetRenderTarget(renderer, NULL);
+ }
+ break;
}
- break;
}
+
+ SDL_RenderCopy(renderer, target, NULL, NULL);
+ SDL_RenderPresent(renderer);
}
/* cleanup */
SDL_DestroyTexture(brush);
+ SDL_DestroyTexture(target);
SDL_Quit();
return 0;