Fastest way to do an SDL_BlitSurface?

This is a discussion on Fastest way to do an SDL_BlitSurface? within the C++ Programming forums, part of the General Programming Boards category; I heard that with memcpy it should be faster, and it seems to be, but the result is not good. ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    55

    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:

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

    instead of:


    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,496
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    http://img338.imageshack.us/my.php?image=dibujovf9.jpg


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

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    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
    Posts
    8,893
    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!
    CornedBee

    "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
    Location
    Umeň, Sweden
    Posts
    555
    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, 11:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21