Skip to content

Commit

Permalink
examples/pen/01-drawing-lines: Match render target size to renderer o…
Browse files Browse the repository at this point in the history
…utput.

Otherwise, on HiDPI displays (like a retina iPad), the lines you draw don't
match where the pen is touching.
  • Loading branch information
icculus committed Dec 28, 2024
1 parent 0ad3a18 commit c030e6f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/pen/01-drawing-lines/drawing-lines.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static float previous_touch_y = -1.0f;
/* This function runs once at startup. */
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
int w, h;

SDL_SetAppMetadata("Example Pen Drawing Lines", "1.0", "com.example.pen-drawing-lines");

if (!SDL_Init(SDL_INIT_VIDEO)) {
Expand All @@ -37,7 +39,10 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])

/* we make a render target so we can draw lines to it and not have to record and redraw every pen stroke each frame.
Instead rendering a frame for us is a single texture draw. */
render_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 640, 480);

/* make sure the render target matches output size (for hidpi displays, etc) so drawing matches the pen's position on a tablet display. */
SDL_GetRenderOutputSize(renderer, &w, &h);
render_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h);
if (!render_target) {
SDL_Log("Couldn't create render target: %s", SDL_GetError());
return SDL_APP_FAILURE;
Expand Down

0 comments on commit c030e6f

Please sign in to comment.