Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: TBitmap vs. CreateDIBsection

  1. #1

    TBitmap vs. CreateDIBsection

    Hello fellow coders!

    At couple weeks a go I desided to create quickly a little Asteroids clone by using only Window GDI functions just for own fun.

    But after a couple try I did not achieve as good framerates I liked to so, I begun to study why's that.

    I stripped all extra away and start examining basic things of a game. My Window class was all good, my GameTimer class was also good, so it have to be the backbuffer blitting which slows down.

    First I created a compatible DC and selected compatible bitmap to that. Performance was fairly good on my laptop, BUT my four year old AMD showed me the real situation. Framerate sucked. But not only the rate (which was something near 60fps) also the movement of the Shuttle (polygon) was jerky which it wasn't on laptop (which achieved 400fps).

    I chanced my Backbuffer to TBitmap and voil?. Almost 4000 fps on laptop and 1000 on my gran-ol'-amd machine.

    I tried to study what makes TBitmap so fast to blit (with bitblt). I noticed that it uses device indepented bitmap, so I decided to create one my own with GDI function.

    After a while I learned the use of CreateDIBSection. Performance was littlebit better than with CreateCompatibleBitmap, but when compared to TBitmap it still sucked (something like 300fps). And still the graphics with that own DIB was jerky on my gran-ol'-amd machine.

    And since then I have been studying-trying-testing-creating-implementing-and-you-name-whatever the creation and blitting of DIB but I still can't get more than 300fps no matter how I create DIB or blit it (StrechDIBits, BitBlt and etc.)

    I have even found articles and examples how to tune performance of DIBS (here's the Microsofts own article http://support.microsoft.com/kb/230492) but there's still no go.

    Ofcourse I could use TBitmap on my backbuffer that's no problem at all, but I'm pondering why I can't achieve same speed with my own created backbuffers.

    Does anyone have an clue or idea because I'm out?!?

    I still liked to do my little game by just using Windows GDI functions for drawing.

    ps. sorry my bad, bad, bad and poor english.


    edit: this 'project' continues on here:
    http://www.pascalgamedevelopment.com...p?topic=5967.0
    - In a world without the wall and fences, who will need the Gates and Windows.

  2. #2

    Re: TBitmap vs. CreateDIBsection

    Quote Originally Posted by FusionWolf
    I have even found articles and examples how to tune performance of DIBS (here's the Microsofts own article http://support.microsoft.com/kb/230492) but there's still no go.
    Were you able to correctly translate the C++ source?

  3. #3

    Re: TBitmap vs. CreateDIBsection

    Yes, I am cabable to convert C(++), Object Pascal, Turbo Pascal, Visual Basic and VBA between each to another.

    I can also 'convert' finnish, english, swedish and germany among to each another. Not so good though than programming languages, but somehow anyway.

    I'm currently (right now actually ) building a test application which has a timer that calculates framerate and shows it up on a window among other values like uptime. There will also be an option which kind of back buffer to use or no back buffer at all (direct textout to window canvas). Backbuffer is cleared and displayed on window at each loop.

    No back buffer and TBitmap options are already handled and ready to go. Now I implement DIB backbuffering and after that I will share the application here, so everyone can test it out. I also share the source code so, if someone could point out what's wrong with it.

    I tested those two options already with my laptop and got near 40k (Yup, 40 000 ) frames per second without back buffer at all. And with TBitmap I got nearly 3500 frames per second.

    Back to code and brb!!

    edit: ouh, and I just remembered that I could use CreateCompatibleBitmap() as a one of the options, so there will be three different kind of back buffer and one option for no back buffer at all.
    - In a world without the wall and fences, who will need the Gates and Windows.

  4. #4

    Re: TBitmap vs. CreateDIBsection

    good luck with that

    cheers,
    Paul

  5. #5

    Re: TBitmap vs. CreateDIBsection

    I have now implemented no back buffer, TBitmap and compatible bitmap options of application. I also imported my shuttle object (drawn as polygon) which is controlled with a arrow keys (GetAsyncKeyState).

    I also have two different kind of timer in there now. First one uses QueryPerformanceCounter and second one TimeGetTime from MMSystem unit.

    When TimeGetTime timer is used frame rate locks to 1000fps because the resolution of timer (ResultTime := (TimerStartTime - FrameEndTime) / 1000). And because minimum resolution of timer is 1ms, it's only possible to get 1000 time differences (cap between the frames) per second. Am I right??

    But with that TimeGetTime -timer I achieve very, very, very smooth 'game play' (shuttles velocity) on my laptop, but when I copy executable to a computer wich has a one cpu core at use, game play gets really choppy. Even if there were enough frames per second!?!

    So, at this point, after many emprical test of different computers (I have tested my exe's on couple other computers also, which are not mentioned earlier) I'm not sure what causes that jerky graphics.

    It's obvious that different back buffers gives different framerates, but even in worst case (CompatibleBitmap) frames are so high on my desktop computer that game play should be nice and smooth, but no. Shuttle jumps some pixels ahead from time to time like some frames would be missing between the update of the loop, but that's not the issue. I have to sit down for a while and rethink where problem lies.

    I'm going to continue my test application tomorrow so until then....


    edit: I desided to share the executable of an application. It uses that TimeGetTime timer and has No backbuffer, TBitmap (Blue canvas) and CompatibleBitmap (Green canvas) implemented. On my laptop everything works fine and goes smoothly but in my gran-ol'-amd desktop machine frames drops near to 60 (except with TBitmap) and graphics jitters big time (even with TBitmap).

    Application is very, very, very unfinished and DIB mode is not implemented yet, but one can try if want to. There's also no error checking at all, so if something goes wrong it will propably leak memory and crash things. But, if all is initialized properly then cleanup is done also properly.

    Here it is -> http://www.saunalahti.fi/hag/share/GDIBlitting.exe

    Source coming later when done!


    Edit2: Ouh, and I liked to mentiot that, if I use DirectX to draw things. Even with same game engine as this example uses. Everything goes smooth and fine even with my Gran-ol'-amd machine. It's only the GDI which causes the headache, but that's the joy part of programming. Isn't it?
    - In a world without the wall and fences, who will need the Gates and Windows.

  6. #6

    Re: TBitmap vs. CreateDIBsection

    Hmmm... this is going very weird.

    Now, I noticed that if I had Delphi up and running and I start that my application. I get 1000 fps and everything goes smoothly. But if I close Delphi and try that .exe then I get same results as I get at my desktop computer.

    Graphics jitters and frames are drop near to 100. Even with TBitmap. Why's that? How come it acts like this? very odd!
    - In a world without the wall and fences, who will need the Gates and Windows.

  7. #7

    Re: TBitmap vs. CreateDIBsection

    This is going even more weird now!!

    If I start that application which I shared here and choose a Delphis TBitmap as an back buffer for example. I get littlebit over 100 frames and graphics goes jerky if I don't have any other application running at the moment.

    BUT if I open a Firefox and go to the webpage which has a flash animation on it and miminize it to the taskbar and start the application I get 1000fps and things goes smoothly!!

    WTF!?! I'm so confused right now... And anyhow, if I use DirectX all goes well with decent 4000fps on windowed mode and nearly 8000fps on alt-tabbed to fullscreen mode.

    Can someone else do the same test?? Or can someone raport something at all about how the application works on his/her computer??

    Here's the link again: http://www.saunalahti.fi/hag/share/GDIBlitting.exe


    edit: Ouh, if one ponders if there's something bad things hidden into the executable I can promise that won't be the case!! Go ahead, test and report!!
    javascript:void(0);

    edit2: Here's also very unfinished DirectX version of the engine. It uses bitmap to render the shuttle. Arrws move, LETF-CTRL fires missiles, F enabled/disables rendering statics and ALT-TAB goes between window and fullscreen. DirectX 9 libraries has been used when executable has been build.

    Here you go: http://www.saunalahti.fi/hag/share/Meteors.zip


    edit3: odd, odd, odd, odd and weird!! I tried that flash trick with a IE7, but there's no go. So, only when Firefox is opened application works great (or Delphi of course). This really is mysterious.
    - In a world without the wall and fences, who will need the Gates and Windows.

  8. #8
    PGDCE Developer de_jean_7777's Avatar
    Join Date
    Nov 2006
    Location
    Bosnia and Herzegovina (Herzegovina)
    Posts
    259

    Re: TBitmap vs. CreateDIBsection

    I tried your application. I get pretty much consistent framerates for all cases which is from 90 ~ 150 FPS. With no backbuffer it sometimes jumps up to 900 ~ 1000 FPS but only for a brief moment. The only problem I've encountered(other than the low framerates) is that the DIB backbuffer does not display anything at all.

    As for the game I get around consistent 1000 ~ 1100 FPS in windowed mode, for fullscreen I get 1800 ~ 2100 FPS though it sometimes jumps briefly to less (like 1400 FPS).

    I am not sure why this is happening. It's quite bizzare. I think I've heard of something similar before but cannot remember. If I do remember I will post it. As for your timer, it seems kinda irratic. I'd suggest that you get the framerate once per second, instead of lower times you might be using.

    As for my hardware, I have an AMD Athlon64 3000+ and an ATI Radeon X600 Pro (Catalyst 9.3) with 512 MiB RAM.
    In defeat we learn.

  9. #9

    Re: TBitmap vs. CreateDIBsection

    Quote Originally Posted by de_jean_7777
    I tried your application. I get pretty much consistent framerates for all cases which is from 90 ~ 150 FPS...<clip>
    Yeah, but does the shuttle move smoothly? In my computers when I get those framerates shuttle jumps ahed from time to time and moves jerky!!

    And as I said at my earlier posts that DIB back buffer is not implemented yet! And if you read my later posts you notice that the problem is not backbuffer related at all because framerate goes very high when delphi is up and runing (go and try you self. Open delphi and run my GDI test application).

    But very weird indeed..

    Quote Originally Posted by de_jean_7777
    As for the game I get around consistent 1000 ~ 1100 FPS in windowed mode, for fullscreen I get 1800 ~ 2100 FPS though it sometimes jumps briefly to less (like 1400 FPS).

    I am not sure why this is happening. It's quite bizzare. I think I've heard of something similar before but cannot remember. If I do remember I will post it. As for your timer, it seems kinda irratic. I'd suggest that you get the framerate once per second, instead of lower times you might be using.

    As for my hardware, I have an AMD Athlon64 3000+ and an ATI Radeon X600 Pro (Catalyst 9.3) with 512 MiB RAM.
    believe me, I have been testing all kind of the timers I ever have found from internet, but I will do more research for them.

    I assume that the game (Meteors) moved smoothly on your PC? But I ponder you have so good omputer and still get only those framerates..
    - In a world without the wall and fences, who will need the Gates and Windows.

  10. #10

    Re: TBitmap vs. CreateDIBsection

    I'm using TTimer myself most of the times Stable 60 fps without consuming cpu and gpu power for pointless frames. It actually keeps the cpu fans quiet too... but i was once experimenting with sleep() to achieve the same kind of cpu save but it didn't quite work that well.

    Edit: Actually for current game i limited it to 30 fps.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL