Thread: Fastest way to do an SDL_BlitSurface?

  1. #1
    Registered User
    Join Date
    Apr 2007

    Fastest way to do an SDL_BlitSurface?

    I heard that with memcpy it should be faster, and it seems to be, but the result is not good. This is what I'm doing:

    memcpy (screen->pixels, image->pixels, resWidth*resHeight*colorDepth/8); // /8 because the colorDepth is in bits

    instead of:

    SDL_BlitSurface(image, NULL, screen, NULL);

    The result isn't good. It isn't filling the entire screen, and what it does fill is not correct... Any ideas?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > The result isn't good.
    How isn't it good?
    - Colours all wrong
    - Colours "inverted" in some way
    - Some kind of "shear" in the image

    Is there something painfully slow about using the API call?
    memcpy may be quicker, but you're assuming an awful lot about how an image and screen are represented.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2007

    That's what I'm getting. It should be a fullscreen screen capture.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Please, I'm desperate here, you gotta help me. I need to speed up the call to SDL_BlitSurface. Give me a hand.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    If there was a faster way than SDL_BlitSurface, don't you think SDL_BlitSurface would use that way?
    Blitting is one of the fastest operations due to hardware support. Are you sure it's your bottleneck?
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Umeň, Sweden
    Looks like a case of buffer dimension mismatch. IIRC an SDL image does not have pitch like the screen does. You'd have to copy your image line by line to the screen buffer, or just follow CornedBee's advice. It's less painful, prettier and more portable that way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fastest way to search the table ( or array )
    By prayami in forum C++ Programming
    Replies: 5
    Last Post: 03-17-2008, 04:56 PM
  2. Fastest way to draw a vertical line
    By CrazyNorman in forum Game Programming
    Replies: 7
    Last Post: 10-17-2006, 09:59 AM
  3. Replies: 4
    Last Post: 10-16-2006, 12:04 PM
  4. fastest way to read / output strings ??
    By author in forum C Programming
    Replies: 3
    Last Post: 06-15-2005, 05:32 AM
  5. Fastest way to sort strings?
    By criticalerror in forum C++ Programming
    Replies: 11
    Last Post: 03-05-2004, 12:18 PM