5

I have a native Delphi TFrame that emulates Roy Tanck's Cumulus Tag Cloud viewer, a WordPress Flash plug-in. What that plug-in does is create a 3D sphere of words that spin around on the surface of a "virtual" sphere. You can see it in action here:

http://www.roytanck.com/2008/03/06/wordpress-plugin-wp-cumulus-flash-based-tag-cloud/

In my application structure each word has its own TBitmap and to render the sphere I print all the word's bitmaps to a temporary TBitmap and then BitBlt() that temporary TBitmap on to the Canvas of a visible TPaintBox. The render operation occurs on a TTimer timer event that happens every 50 milliseconds.

However, no matter how hard I try there is a noticeable "jitter" to the movement of the words, especially in comparison to the silky smooth movement of the Flash player. I thought increasing the frame rate might help and I even tried using a Multimedia timer that updated every 10 milliseconds with proper locking and unlocking of all the Canvases due to the multithreaded nature of the MM timer. Still jittery. The only thing I can figure is that the calculations I do result in discrete pixel locations for each word to render at and that causes jitter. In contrast, and this is supposition, perhaps Flash potentially does dithering to facilitate "between pixel" rendering or maybe does anti-aliasing in real-time and that's why it doesn't jitter?

In any case, is it possible to get the silky smooth motion I am looking for using native Delphi code? Or is the only way to do it is to go all the way to something like a Direct3D or OpenGL solution? I don't want to waste time tweaking this thing to death if it's a losing battle. On the other hand, if you have any tips I'd love to hear them. My guess is that if I do have to go the Direct3D/OpenGL route it's a big job and learning curve so if I could find a way to get this done in native Delphi code I'd love that.

FOLLOW-UP EDIT: Would printing to a much larger "virtual" bitmap and then using a resampling method like that given here help to print "down" to the actual visible Canvas?:

Scale an image nicely in Delphi?

Community
  • 1
  • 1
Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
  • Do you have on DoubleBuffering,AllPaintingInWmPaint,SupportsTransparentBackColor, and UserPaint? Using these when doing GDI rendering on a form will prevent flickering. – Nowayz Oct 10 '10 at 02:39
  • Nowayz. I don't have flickering. The jitter is positional, not due to repaints. – Robert Oschler Oct 10 '10 at 02:49
  • The answer is definitely yes. But if you want really smooth 3D graphics, the CPU isn't fast enough. You need to use the GPU, using OpenGL. – Andreas Rejbrand Oct 10 '10 at 12:09
  • 3
    CPU is fast enough. Windows is just not regular enough :-) – Marco van de Voort Oct 10 '10 at 12:39
  • It turns out I'm getting a much better looking frame using the Graphics32 library I link to in my question. I had to switch away from the kernel resampler to a draft resampler because even on my quad core Intel i5 I couldn't get more than 4 frames a second without having performance issues. With the draft resampler I don't have to limit the frame rate and it definitely looks a lot better than without. Now I just have to figure out why I'm getting an oddball flicker on my sub-images and I'm done. I've never had flicker before when writing to a temp bitmap and then BitBlt()'ing to a Canvas. – Robert Oschler Oct 10 '10 at 14:48
  • Have you considered trying SDL? – Kenneth Cochran Oct 11 '10 at 14:49

2 Answers2

2

I have written a number of games in Delphi. It is certainly doable. There are a number of things to watch for.

Not only do you have to trigger an event regularly but also check the time when it arrives and move based upon the polled time rather than assuming the time based upon the expected wait period.

If subpixel accuracy without GPU dependency is needed I would recommend Antigrain Geometry or it's Pascal cousin AGGPAS for Delphi.

Animating Fonts can have an additional issue in that font rendering often contains logic to ensure that thin strokes appear on pixel boundries. Moving text rendered in that manner can change appearance as different strokes can jump from being aligned with one pixel to the next.

If the font is rendered to be pixel aligned, it would perhaps manage better if you quantized rendering to integers. It will still align to pixels but by moving a pixel at a time should make it do so consistently each time.

Lerc
  • 306
  • 2
  • 7
  • i believe that a GDI font with `ANTIALIASED_QUALITY`(http://msdn.microsoft.com/en-us/library/dd183499(v=vs.85).aspx) will not be "grid-fitted", avoiding the *"bouncing characters"* problem. – Ian Boyd Jan 30 '12 at 04:02
1

IMHO the right way to go is Direct3D (or OpenGL, but given Delphi is Windows only maybe Direct3D is better). It was introduced exactly because the GDI is not good at such tasks. Flash supports both vector and raster graphic, and thereby can handle such kind of applicaitons better than old plain GDI.

  • 1
    Writing an OpenGL Delphi application is very easy, because there is a OpenGL.pas unit. Writing a DirectX Delphi application is not that easy. – Andreas Rejbrand Oct 10 '10 at 13:10
  • My experience with Direct3D is that when it works it's great but when you have a problem, especially due to a codec issue somewhere in the filter chain, life can get very painful very quickly. That's why I'm working so hard to avoid it. I haven't tired OpenGL yet and definitely want to. – Robert Oschler Oct 10 '10 at 14:50
  • I just meant that being DirectX the native advanced graphic platform of Windows it has better support. MS showed they "don't like" OpenGL that much –  Oct 10 '10 at 16:05
  • 1
    @Robert: Direct3D doesn't do filter chains, nor does it have codecs. Don't confuse it with DirectShow, completely different beast alltogether. – Paul-Jan Oct 10 '10 at 18:38
  • Good point Paul-Jan. I did mix those two together and they're not the same thing as you pointed out. – Robert Oschler Oct 11 '10 at 01:06