Graphics: Dealing with multi resolutions?

This is a discussion on Graphics: Dealing with multi resolutions? within the Windows Programming forums, part of the Platform Specific Boards category; Hello all. I have a question regarding writing applications involving graphics to support multi resolutions. SUMMARY: Essentially I want to ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    74

    Graphics: Dealing with multi resolutions?

    Hello all. I have a question regarding writing applications involving graphics to support multi resolutions.

    SUMMARY:
    Essentially I want to adjust my application's graphics' sizes depending on the screen resolution.

    DETAILS:
    Specifically I am writing a Solitaire game using the Win32 GDI and I wrote/created the code/graphics under a 1024x768 resolution. It looks perfectly as I had hoped utilizing every inch of the game window while properly being able to display all cards. However, when I switch to a lower resolution, such as 800x600 I now have the problem of my images being a bit too large for the new resolution. I have tried:

    1) Utilizing the StretchBlt() function instead of BitBlt() to draw each card to the screen. By setting the destination rect smaller cards are scaled down.

    Problem: Game now taking up too much CPU as I guess StretchBlt() is just that much slower?!? Instead of 2-5% on card/pile drags I'm getting 75-95%.

    2) Drawing the game (every card) to a back buffer using BitBlt() as usual then using StretchBlt() to draw the back buffer to the screen (shrinking backbuffer from 1024x768 to destination rect of 800x600) hopefully increasing speed by reducing StretchBlt()'s from about 30 cards every repaint to just 1 backbuffer -> screen.

    Problem: Still too much CPU usage. 75-95% instead of 2-5% with pure BitBlt()'s.

    So, uh what can I do to make my application look just as nice on 800x600 -> 1024x768 -> 1600x1200? Do I have to create 3 separate bitmaps of cards? A low resolution one of smaller cards; a medium resolution one; and a high resolution one with bigger card images? Then depending on the resolution load the specific bitmap? (This of course would make my application larger, which I wanted to avoid).

    I noticed the Solitaire game that shipped with windows resolves this problem by designing the game in 800x600 resolution and just uses the same card sizes for 1024x768. While this works at higher resolutions the cards get smaller and smaller and so much of the screen is wasted where bigger cards would be more appropriate.

    Hopefully, the explaination above of what I'm trying to do isn't too confusing.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    Why don't you just StretchBlt() the card you're moving to a back buffer, then BitBlt it to where it's moved to?
    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
    Aug 2006
    Posts
    74
    Yeah, thats what I tried to do. When my game state is changed (ie a card is moved) I attempted to StretchBlt() all my cards to a back buffer then use BitBlt() to copy the back buffer to the screen. Doing this with the BitBlt() function works great never causing CPU usage to go above 5%. When I replaced BitBlt() with StretchBlt() all of these StretchBlt() calls are sucking up CPU usage at 75-95%. I can't really just StretchBlt() the cards that have moved because as they move they cover up and reveal other cards thus needed those new revealed cards to be redrawn. So basically I am clearing the back buffer each redraw and refilling the entire back buffer again with my game... doing this using all StretchBlt()s just seems too much work for my CPU?!?

    Is my game logic faulty? Should I not be clearing my back buffer and redrawing my entire game every repaint()?

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    Oops nevermind.. after tinkering I found a solution to my problem. Since I cannot delete this thread I might as well make it useful by posting my solution.

    1) Create a device context.
    2) Select my bitmap image/object into it that contains 52 card images.
    3) Create another device context.
    4) Load a compatible bitmap into it for drawing.
    5) StretchBlt() first device context (1) into the second device context (3) scaling it as desired. (ie to convert my 1024x768 bitmap for use in 800x600 resolution scale down to 80%)
    6) Use the second device context for BitBlt()'ing to a back buffer instead of the first device context.

    Summary: Achieves the effect of StretchBlt()'ing an image while keeping the speed of BitBlt().


    P.S. sorry if my whole thread was confusing.. its kinda hard to write into words what I was trying to achieve.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turtle Graphics, how does it work?
    By freddyvorhees in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 09:57 AM
  2. Dealing With Multi Dim Char Arrays
    By mike_g in forum C Programming
    Replies: 8
    Last Post: 06-15-2007, 01:52 PM
  3. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  4. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  5. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM

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