Fixed rendering in the iOS touch demo

This commit is contained in:
Sam Lantinga 2021-11-09 13:36:44 -08:00
parent 7681929cb4
commit a7e2e3a329
1 changed files with 23 additions and 13 deletions

View File

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