Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
int
SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
               SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
    int i;
    int x1, y1;
    int x2, y2;
    SDL_bool draw_end;
    BlendLineFunc func;

    if (!dst) {
        SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
        return -1;
    }

    func = SDL_CalculateBlendLineFunc(dst->format);
    if (!func) {
        SDL_SetError("SDL_BlendLines(): Unsupported surface format");
        return -1;
    }

    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, blendMode, r, g, b, a, draw_end);
    }
    if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
        SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
                       blendMode, r, g, b, a);
    }
    return 0;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
/**
 * @brief Tests the SDL primitives with alpha for rendering.
 */
static void surface_testPrimitivesBlend( SDL_Surface *testsur )
{
   int ret;
   int i, j;
   SDL_Rect rect;

   SDL_ATbegin( "Primitives Blend Test" );

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Create some rectangles for each blend mode. */
   ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;
   rect.x = 10;
   rect.y = 25;
   rect.w = 40;
   rect.h = 25;
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;
   rect.x = 30;
   rect.y = 40;
   rect.w = 45;
   rect.h = 15;
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;
   rect.x = 25;
   rect.y = 25;
   rect.w = 25;
   rect.h = 25;
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_MOD, 10, 10, 240, 125 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;

   /* Draw blended lines, lines for everyone. */
   for (i=0; i<testsur->w; i+=2)  {
      ret = SDL_BlendLine( testsur, 0, 0, i, 59,
            (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
               (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
            60+2*i, 240-2*i, 50, 3*i );
      if (SDL_ATassert( "SDL_BlendLine", ret == 0))
         return;
   }
   for (i=0; i<testsur->h; i+=2)  {
      ret = SDL_BlendLine( testsur, 0, 0, 79, i,
            (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
               (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
            60+2*i, 240-2*i, 50, 3*i );
      if (SDL_ATassert( "SDL_BlendLine", ret == 0))
         return;
   }

   /* Draw points. */
   for (j=0; j<testsur->h; j+=3) {
      for (i=0; i<testsur->w; i+=3) {
      ret = SDL_BlendPoint( testsur, i, j,
            ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
               ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
            j*4, i*3, j*4, i*3 );
      if (SDL_ATassert( "SDL_BlendPoint", ret == 0))
         return;
      }
   }

   /* See if it's the same. */
   if (SDL_ATassert( "Primitives output not the same.",
            surface_compare( testsur, &img_blend )==0 ))
      return;

   SDL_ATend();
}