Sprites using GDI+?

This is a discussion on Sprites using GDI+? within the Game Programming forums, part of the General Programming Boards category; Hi everyone, I've managed to use GDI+ to create and rotate/move simple rectangles and shapes like that, but I was ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    Sprites using GDI+?

    Hi everyone,

    I've managed to use GDI+ to create and rotate/move simple rectangles and shapes like that, but I was wondering how I would go about doing the same for images? I've used the TextureBrush option to fill rectangles, but that doesn't seem to work (it doesn't seem to be possible to rotate the texture with the object or move the origin of the image with the object you're putting it onto).

    Which functions/methods do you think I should take a look at please?

    Thankyou!

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    I was trying to do the same thing last night I just read c++ - How to rotate Bitmap in windows GDI? - Stack Overflow a possible solution. I was trying to get a snake head to rotate to the direction it was traveling. I ended up saving 8 bitmaps 4 rotations and 4 masks for transparency. I figured there is a better way so I was looking at work I found that. I won't be able to test it till after work, but if you use it post back here and let me know how it goes.

    On further reading it looks like you can do easy 90 rotations with that library if you use jpeg files. The other method looks like it rotates the entire DC which might not he what you are looking for. I am still looking for further solutions.
    Last edited by Lesshardtofind; 11-05-2012 at 09:34 AM.

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    INFO: Rotating a Bitmap by 90 Degrees found that too. It says there is no function for it and that the accepted solution is to copy the pixels from the row of the source to the columns of a destination. This seems like it could use more memory if working with a large bitmap. Maybe someone who knows memory better than I will tell me if presaving rotated bitmaps and just loading them is more efficient than copying the entire bitmap at runtime. Of course there are some applications where the pre-saved are not an option. Like if you were making an image editor program.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I do not recommend doing sprites in GDI. It is ok for normal non-rotated bitmaps but any rotations become a pain. Rotating bitmaps always has been and is a dark art that eveny many games from the 80's and 90's still did not get right. Thankfully Direct3D and OGL have come along and now we simply texture rotated quads and let the cards do the rasterization. The bitmap itself is not actually rotated which makes the entire rasterization process a simple matter of tracing a line from point A to point B while interpolating texels along the way.

    You will also find that doing transparent sprites in GDI is a huge pain. You will need to blit twice with two distinct pixel blit operations to get it right. Unfortunately I forget what those operations are at the moment.

  5. #5
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Unfortunately I forget what those operations are at the moment.
    Two seperate BitBlt() functions first one using the rastor SRCAND with a mask bmp selected into the memory DC and the second using the rastor SRCPAINT with the sprite bmp selected into the memory DC. It feels clumsy at best, and eventually annoying if you have a lot of sprites.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    GDI+ does allow for rotated sprites via transforms similar to Direct3D and OGL. However even with the power of transforms I still stand by my original advice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sprites in SDL
    By JOsephPataki in forum Game Programming
    Replies: 6
    Last Post: 07-17-2003, 06:08 PM
  2. Sprites, Etc.
    By Krak in forum Game Programming
    Replies: 3
    Last Post: 05-18-2003, 09:08 PM
  3. Sprites
    By Paninaro in forum Game Programming
    Replies: 4
    Last Post: 07-07-2002, 11:37 PM
  4. Where to get sprites?
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 03-16-2002, 05:27 PM
  5. Sprites?!?
    By IcyDeath in forum Game Programming
    Replies: 5
    Last Post: 10-11-2001, 08:42 AM

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