Powerbasic Museum 2020-B

IT-Consultant: Patrice Terrier => The "Geek" corner => Topic started by: Patrice Terrier on August 02, 2007, 07:25:14 PM

Title: pbDex3D (the fundamentals of any 3D graphic engine)
Post by: Patrice Terrier on August 02, 2007, 07:25:14 PM
pbDex3D

This was a huge work to tanslate this piece of code to PB.

It shows you the common basis to all 3D engines (how things are done under the hood).

It uses my own animation technic to save CPU resources, to be cooperative with other running application, usualy it takes only 1 to 2% of the CPU cycles, instead of the 50% CPU found in most application that are based on the MSDN animation message pump example.

Here is the message pump animation being used:

          CALL SetTimer(hMain, 1, 0, %NULL)
          WHILE GetMessage(Msg, %NULL, 0, 0)
                CALL TranslateMessage(Msg)
                CALL DispatchMessage(Msg)
          WEND
          CALL KillTimer(hMain, 1)


simple isn't it?

Patrice Terrier
www.zapsolution.com
Title: Re: [SDK] 3D graphic animation in pure PowerBASIC
Post by: José Roca on August 02, 2007, 08:14:30 PM
 
Hi Patrice,

Great tip!

I have modified the message pump in the dx9_primitive_types example from:


   WHILE msg.message <> %WM_QUIT
      IF PeekMessage(msg, %NULL, 0, 0, %PM_REMOVE) THEN
         TranslateMessage msg
         DispatchMessage msg
      ELSE
         RenderD3DScene
      END IF
   WEND


to:


   SetTimer(g_hwnd, 1, 0, %NULL)
   WHILE GetMessage(msg, %NULL, 0, 0)
      TranslateMessage msg
      DispatchMessage msg
   WEND
   KillTimer(g_hwnd, 1)


and added this to the WndProc callback function:


   CASE %WM_TIMER
      RenderD3DScene
      EXIT FUNCTION


and CPU usage is now 2% instead of 100%. Also it repaints in real time when resizing the window, solving the two problems, CPU usage and repainting, at the same time!
Title: Re: [SDK] 3D graphic animation in pure PowerBASIC
Post by: Petr Schreiber on August 02, 2007, 08:35:08 PM
This is very good technique,

Patrice advised it for my thinEdge 3D editor and according to my tests so far it really dropped to about 2% for classic models and about 12% for complex models. It is amazing trick. Now I have to tune other features of the program :)


Thanks,
Petr

P.S. And PBDex is very cool too!
Title: Re: [SDK] 3D graphic animation in pure PowerBASIC
Post by: Patrice Terrier on August 02, 2007, 08:47:25 PM
Yes, it is kind of magic, this is the technic being used in GDImage either with OpenGL or pure GDImage,
and it works with everything including L5G applications like WinDev.

It is even more cooperative than WPF, and takes less resources than it, and no need to limit the frame rate to 30 fps as Microsoft does with WPF.


Indeed this message pump animation is a very good example of superiority of SDK over everything else,
because you control the low level message pump directly yourself.

Also very easy to create your own modal message pump if you need one.
Title: Re: [SDK] 3D graphic animation in pure PowerBASIC
Post by: Kent Sarikaya on August 02, 2007, 11:19:42 PM
Ok, now I am lost... I see no directX or openGL.

Does this mean all the graphics are being done by the CPU?

If so, this would be like selecting a software renderer correct and bypassing the GPU?

Thanks for the post, it looks like a very complete set of functions that should be available in all engines.
Lots to study in this one, thank you very much Patrice!
Title: Re: [SDK] 3D graphic animation in pure PowerBASIC
Post by: Paul Squires on August 03, 2007, 12:21:11 AM
Quote from: Patrice Terrier on August 02, 2007, 09:17:19 PM
...I have learned this and many other things from my Master Ethan Winer.
You and me both! At the time, Ethan's book really opened my eyes to the various methods to make more efficient code. I read and re-read that book literally hundreds of times. I emailed Ethan several years later to thank him for his work and I got a very nice response from him. Great guy, great coder.

Title: Re: [SDK] 3D graphic animation in pure PowerBASIC
Post by: Kent Sarikaya on August 03, 2007, 08:33:29 AM
Thanks Patrice, I don't have .net installed at all at the moment, so I will try the pbversion now.
Thanks.

Just ran it, wow really cool stuff and fast !! thanks.
Title: Re: pbDex3D (the fundamental of any 3D graphic engine)
Post by: Patrice Terrier on August 10, 2011, 03:55:20 PM
The first post of this thread has been updated, to fix the ZIP file corruption caused by the "Server Collapse".

...