Increasing the speed with graphics in C

This is a discussion on Increasing the speed with graphics in C within the C Programming forums, part of the General Programming Boards category; Using C, I have loaded some bitmaps of gauges on the screen and now I want to control the rotation ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    7

    Increasing the speed with graphics in C

    Using C, I have loaded some bitmaps of gauges on the screen and now I want to control the rotation of needles on it. The resolution I have used is 1024 * 768.(super VGA mode) the background (the set of gauges) has only 5 colors and the needles has only 1 color.
    each needle is defined as array of points and fillpoly() forms a needle. before rotation of needles, I save the background (using getimage() )and load it after the second rotation (using putimage()) but itís time consuming so not smooth and is blinking. Iím looking for some tricks to solve it or completely change my procedure. help me, please. thanks in advance.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Well since you asked about Turbo C in your other post, I'd say that you should get Dev-C++ and grab the LibSDL library as well.

    Get out of the stone age dude!
    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
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    to get rid of the flickering you need a back buffer. This means a copy of the screen in memory that you can just "blit" onto the screen when its complete. This prevents the period in time when you are drawing the thing from being visible to the user.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    I've never worked in super VGA mode but I'm pretty sure you can implement the following optimizations:

    1) perform all drawing operations on a secondary buffer prior to repainting.
    2) only repaint the areas that have changed.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    If you are BGI mode which you are according to your post....you are screwed. BGI sucks so bad I cannot even begin to describe what obfuscated code would be required to do back buffering under BGI.

    Switch graphic libraries, dump DOS, and use OpenGL or DirectX. They will make your life a lot easier.

    The other option is to get DJGPP but you cannot gain access to the linear frame buffer via a near pointer hack. In other words you must use a farnspokeb or the farnspoke family of functions to plot pixels. This means calling a function per pixel which translates to....it's not even worth it anymore.

    To give you and idea why: in 640x480 mode there are 307200 pixels. Calling a function 307200 times is a fast way to destroy your performance. So what you need to end up doing is blitting to a secondary buffer and then using a stosd to copy the buffer to the screen. This all is still going to be magnitudes slower than using DirectX or OpenGL.
    Last edited by VirtualAce; 01-26-2005 at 07:51 AM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7
    Thanks for your responses. I studied the mails completely and prefer to describe my problem exactly.
    I know all graphics modes like VGA and XGA use a portion of memory that represents the bitmap displayed on the screen.(Video Buffer) foe example for mode 13h, the buffer starts at A000:0000 and ends at A000:F9FF. Knowing this buffer is necessary for direct video access.
    Itís so important to mention I want to have 1024*768 resolution in DOS and high speed for double buffering and page flipping. Now there are two questions:

    1) How can I initialize the graphics? Iíve used BGI mode but What are the other suitable options for this purpose? Can I use something like mode 13h?

    2) What is the portion of memory that represents the bitmap displayed on the screen (Video buffer) for 1024*768 , BGI mode or the mode that you have suggested during answering question 1?

    I really use your applicable guides.
    While answering, Please introduce some references on the web for getting details. Thanks again.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > completely change my procedure.
    We have, but apparently you're not interested in listening to alternative approaches, only fixes to your broken approach.

    > I want to have 1024*768 resolution in DOS
    Do the math - 1024*768 = 0xC0000
    Given the max you can see in a frame buffer at one time in DOS is 0x10000, how many bits of memory do you need to mess about with to get a double buffered screen?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  2. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2006, 11:40 PM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  4. 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