static int SW_RenderPoint(SDL_Renderer * renderer, int x, int y) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; SDL_Rect rect; int status; rect.x = x; rect.y = y; rect.w = 1; rect.h = 1; if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { SDL_AddDirtyRect(&data->dirty, &rect); } if (data->renderer->LockTexture(data->renderer, data->texture[data->current_texture], &rect, 1, &data->surface.pixels, &data->surface.pitch) < 0) { return -1; } data->surface.w = 1; data->surface.h = 1; data->surface.clip_rect.w = 1; data->surface.clip_rect.h = 1; if (renderer->blendMode == SDL_BLENDMODE_NONE || renderer->blendMode == SDL_BLENDMODE_MASK) { Uint32 color = SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, renderer->b, renderer->a); status = SDL_DrawPoint(&data->surface, 0, 0, color); } else { status = SDL_BlendPoint(&data->surface, 0, 0, renderer->blendMode, renderer->r, renderer->g, renderer->b, renderer->a); } data->renderer->UnlockTexture(data->renderer, data->texture[data->current_texture]); return status; }
int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color) { int i; int x1, y1; int x2, y2; SDL_bool draw_end; DrawLineFunc func; if (!dst) { return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); } func = SDL_CalculateDrawLineFunc(dst->format); if (!func) { return SDL_SetError("SDL_DrawLines(): Unsupported surface format"); } for (i = 1; i < count; ++i) { x1 = points[i-1].x; y1 = points[i-1].y; x2 = points[i].x; y2 = points[i].y; /* Perform clipping */ /* FIXME: We don't actually want to clip, as it may change line slope */ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { continue; } /* Draw the end if it was clipped */ draw_end = (x2 != points[i].x || y2 != points[i].y); func(dst, x1, y1, x2, y2, color, draw_end); } if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color); } return 0; }
static int SDL_DUMMY_RenderPoint(SDL_Renderer * renderer, int x, int y) { SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; SDL_Surface *target = data->screens[data->current_screen]; int status; if (renderer->blendMode == SDL_BLENDMODE_NONE || renderer->blendMode == SDL_BLENDMODE_MASK) { Uint32 color = SDL_MapRGBA(target->format, renderer->r, renderer->g, renderer->b, renderer->a); status = SDL_DrawPoint(target, x, y, color); } else { status = SDL_BlendPoint(target, x, y, renderer->blendMode, renderer->r, renderer->g, renderer->b, renderer->a); } return status; }
/** * @brief Tests the SDL primitives for rendering. */ static void surface_testPrimitives( SDL_Surface *testsur ) { int ret; int x, y; SDL_Rect rect; SDL_ATbegin( "Primitives Test" ); /* Clear surface. */ ret = SDL_FillRect( testsur, NULL, SDL_MapRGB( testsur->format, 0, 0, 0 ) ); if (SDL_ATassert( "SDL_FillRect", ret == 0)) return; /* Create the surface. */ testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, RMASK, GMASK, BMASK, AMASK ); if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) return; /* Draw a rectangle. */ rect.x = 40; rect.y = 0; rect.w = 40; rect.h = 80; ret = SDL_FillRect( testsur, &rect, SDL_MapRGB( testsur->format, 13, 73, 200 ) ); if (SDL_ATassert( "SDL_FillRect", ret == 0)) return; /* Draw a rectangle. */ rect.x = 10; rect.y = 10; rect.w = 60; rect.h = 40; ret = SDL_FillRect( testsur, &rect, SDL_MapRGB( testsur->format, 200, 0, 100 ) ); if (SDL_ATassert( "SDL_FillRect", ret == 0)) return; /* Draw some points like so: * X.X.X.X.. * .X.X.X.X. * X.X.X.X.. */ for (y=0; y<3; y++) { x = y % 2; for (; x<80; x+=2) { ret = SDL_DrawPoint( testsur, x, y, SDL_MapRGB( testsur->format, x*y, x*y/2, x*y/3 ) ); if (SDL_ATassert( "SDL_DrawPoint", ret == 0)) return; } } /* Draw some lines. */ ret = SDL_DrawLine( testsur, 0, 30, 80, 30, SDL_MapRGB( testsur->format, 0, 255, 0 ) ); if (SDL_ATassert( "SDL_DrawLine", ret == 0)) return; ret = SDL_DrawLine( testsur, 40, 30, 40, 60, SDL_MapRGB( testsur->format, 55, 55, 5 ) ); if (SDL_ATassert( "SDL_DrawLine", ret == 0)) return; ret = SDL_DrawLine( testsur, 0, 60, 80, 0, SDL_MapRGB( testsur->format, 5, 105, 105 ) ); if (SDL_ATassert( "SDL_DrawLine", ret == 0)) return; /* See if it's the same. */ if (SDL_ATassert( "Primitives output not the same.", surface_compare( testsur, &img_primitives )==0 )) return; SDL_ATend(); }