Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Alternatives to FillRect

Alternatives to FillRect

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KellyR
    wrote on last edited by
    #1

    Hi, I'm doing a CPU-intensive program right now (C++ WinAPI, no MFC but I could use it if I had to) that uses some graphics, frequently calling a FillRect function to clear its back-buffered HDC to white. Is there a more efficient way to do this? Maybe by using bitwise operators somehow? Thanks!

    KR

    M C 2 Replies Last reply
    0
    • K KellyR

      Hi, I'm doing a CPU-intensive program right now (C++ WinAPI, no MFC but I could use it if I had to) that uses some graphics, frequently calling a FillRect function to clear its back-buffered HDC to white. Is there a more efficient way to do this? Maybe by using bitwise operators somehow? Thanks!

      KR

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      You could use a DIB section for the back buffer's bitmap and write the bits directly to memory in a loop. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      K N 2 Replies Last reply
      0
      • K KellyR

        Hi, I'm doing a CPU-intensive program right now (C++ WinAPI, no MFC but I could use it if I had to) that uses some graphics, frequently calling a FillRect function to clear its back-buffered HDC to white. Is there a more efficient way to do this? Maybe by using bitwise operators somehow? Thanks!

        KR

        C Offline
        C Offline
        cmk
        wrote on last edited by
        #3

        RECT r = {...}; SetBkColor(dc, your_white); ExtTextOut(dc, r.left, r.top, ETO_OPAQUE, &r, NULL, 0, NULL); [EDIT] Not saying it's faster, just another way. At one point i believe it was the prefered way (don't recall why). [/EDIT]

        ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

        K 1 Reply Last reply
        0
        • M Mark Salsbery

          You could use a DIB section for the back buffer's bitmap and write the bits directly to memory in a loop. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          K Offline
          K Offline
          KellyR
          wrote on last edited by
          #4

          Ok I'll try that, thanks!

          KR

          1 Reply Last reply
          0
          • M Mark Salsbery

            You could use a DIB section for the back buffer's bitmap and write the bits directly to memory in a loop. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #5

            Using BitBlt API with WHITENESS isn't better?

            - NS - [ODBaseBtn]

            K 1 Reply Last reply
            0
            • N Nishad S

              Using BitBlt API with WHITENESS isn't better?

              - NS - [ODBaseBtn]

              K Offline
              K Offline
              KellyR
              wrote on last edited by
              #6

              BitBlt with WHITENESS seems to be the fastest way to do it that I've tried. I guess I might be able to get it a little faster using a straight memcpy but I think BitBlt basically is a memcpy already so I doubt it'll help much.

              KR

              N 1 Reply Last reply
              0
              • C cmk

                RECT r = {...}; SetBkColor(dc, your_white); ExtTextOut(dc, r.left, r.top, ETO_OPAQUE, &r, NULL, 0, NULL); [EDIT] Not saying it's faster, just another way. At one point i believe it was the prefered way (don't recall why). [/EDIT]

                ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

                K Offline
                K Offline
                KellyR
                wrote on last edited by
                #7

                That way seems to be faster than FillRect, but copying directly to memory with BitBlt is slightly faster. Thanks!

                KR

                C 1 Reply Last reply
                0
                • K KellyR

                  That way seems to be faster than FillRect, but copying directly to memory with BitBlt is slightly faster. Thanks!

                  KR

                  C Offline
                  C Offline
                  cmk
                  wrote on last edited by
                  #8

                  You may want to read: http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx[^] However, if BitlBlt accepts hdcSrc = NULL when dwRop is WHITENESS then you may as well stick with that if it's faster. This is a special case (color is set to palette index 1 = usually white). ExtTextOut is still fastest for setting any color.

                  ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

                  1 Reply Last reply
                  0
                  • K KellyR

                    BitBlt with WHITENESS seems to be the fastest way to do it that I've tried. I guess I might be able to get it a little faster using a straight memcpy but I think BitBlt basically is a memcpy already so I doubt it'll help much.

                    KR

                    N Offline
                    N Offline
                    Nishad S
                    wrote on last edited by
                    #9

                    Through BitBlt we can avoid the risk of bugs, since we dont need to handle the DC bitmap directly.

                    - NS - [ODBaseBtn]

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups