Options for pure-graphics display in Delphi 2009 - delphi

My whole experience with direct use of graphics consists of drawing shapes using Turbo Pascal’s gdi unit on a 386 machine ages ago, finding it unbearably slow and never giving it a second thought. In other words, I have next to no idea where to begin.
For a simple Internet radio player application, I would like to design a graphic display somewhat similar to Winamp (but a bit larger and easier on the eyes, since the illegibility of such displays is one reason I’m trying to do my own).
Simple graphic components like those imitating LED displays are nowhere near sufficient, of course. I don’t expect to be drawing clickable UI controls, and certainly not skins – just the readout, with text, digits and a few symbols. I understand Delphi 2010 supports Direct2D, but I only have D2009.
What are my options? Are there any 3rd party components that would help?
On edit two small points. I need the drawing to be flicker-free (i.e,, unlike what I experienced all those years ago in Turbo Pascal :-). Is TCanvas going to be fast enough for that? Also, I would probably want to use alphablending, which I don't think I can get with the basic TextOut, LineTo etc. graphics API. (I just don't know what's possible). What about GDI+?

A library for fast 2D graphics for Delphi is available as open source on Sourceforge:
Graphics32 (home page: http://www.graphics32.org/)
Graphics32 is a graphics library for
Delphi and Kylix/CLX. Optimized for
32-bit pixel formats, it provides fast
operations with pixels and graphic
primitives. In most cases Graphics32
considerably outperforms the standard
TBitmap/TCanvas methods.
Features Some of Graphics32 features include:
Fast per-pixel access up to 100 times faster compared to standard TBitmap;
High-performance Bitmap alpha blending (including per-pixel alpha blending);
Pixel, line and polygon antialiasing with sub-pixel accuracy (combined with alpha blending);
Arbitrary polygon transformations and custom fillings;
Bitmap resampling with high quality reconstruction filters (e.g. Lanczos, Cubic, Mitchell);
A unique state-of-the-art rasterization system;
Affine transformations of bitmaps: rotations, scaling, etc with sub-pixel accuracy;
Arbitrary projective transformations of bitmaps;
Arbitrary remapping transformations of bitmaps (e.g. for Warping, Morphing);
Flexible supersampling implementation for maximum sampling quality;
Flicker-free image displaying components with optimized double buffering via advanced MicroTiles based repaint optimizer;
Multiple customizible easy-to-use overlay layers;
Locking of bitmaps for safe multithreading;
A property editor for RGB and alpha channel loading;
Design-time loading of image formats supported by standard TPicture;
Works on Borland Delphi, C++ Builder and Kylix (The last version that supported Kylix was 1.8.3).
As of version 1.5.1b Graphics32 is licensed under the terms of the Mozilla Public License.

Take a look at TCanvas. It's built into most visual controls and contains easy methods for the sort of simple drawing you're looking at, without the need for mucking around with DirectX or OpenGL. If you want a really simple surface you can draw on, place a blank TImage TPaintBox on the form and use its Canvas as your drawing surface.

Mostly I agree with Mason and the comments. TPaintBox is a very simple component really. You implement the OnPaint event and are in complete control. It is fast enough on a fast-enough machine.
Put it on a TScrollBox and you don't even need to worry about where the user has scrolled to :)
Make sure you check out the DoubleBufferred property of the parent control(panel/ScrollBox).
If it is a complex drawing/graphic also check out InvalidateRect - this controls which area of a canvas is redrawn.
Of course like all graphics/drawing it gets pretty complicated pretty quickly :(

Just saw your edit. If you need alpha blending and flicker-free drawing, TCanvas is probably not going to be good enough for you. You should look at components that wrap OpenGL or Direct3D and provide you a high-power graphics canvas.
One such package is Asphyre, though I'm not sure if they have a version that works on Delphi 2009+ yet. I've also got a custom-built library that wraps SDL 1.3 and gives you a drawing frame component you can place on a Delphi form. It does work on Delphi 2009 and later, but I haven't released it as its own package yet. You could find it if you dig around in the SVN archive of my game engine, but if you can wait a day or two I could try to get it made into an easily-usable BPL component package and available for download.

Related

How to render and zoom RTF on canvas in Delphi

Hello I need to integrate formatted text into an older application written in Delphi where it would be rendered into the canvas (GDI - yes prehistoric technology, need to support Win Vista and later). I've tried to accomplish this with html and rtf but both have pros and cons. I've decided to use rtf and TRichEdit as an editor. It has nice interface and it's easy to write needed functionality. The problem is with rendering (already solved that part) and zooming it in reasonable image quality and linear scaling (or almost linear). I've alreday tried 2 approaches:
Rendering into bitmap and then zooming - nice linear scaling, but terrible pixelated image - as expected
Zooming via TRichEdit feature and then rendering into bitmap - nice sharp image, but linear scaling is gone.
Is there some other approach? Thanks.

How can I create an animated palette (color cycling) animation in FireMonkey?

An old-school graphics effect is palette animation, where for an image of (say) 256 colours, the palette that each color index of 0-255 refers to is shifted. As it shifts, the colours of each pixel change.
You can read more about the technique here and see a fantastic HTML5 reproduction of old-style effects here. Here is a plasma example from Wikipedia:
I would like to achieve the same effect in FireMonkey, using FMX TBitmaps or another inbuilt class. (I currently have TBitmaps - with static colours - built once-off from a table of values.) FMX is quite abstracted from the underlying OS, and also using underlying OS techniques will stop the app being cross-platform-compatible. On the other hand, since it uses DirectX or OpenGL under the hood, fast animation effects should be very possible. What's the best approach?
I am using Delphi XE2 (original FireMonkey) but a technique for anything up to XE4 (FMX 3) is fine too.

Making a "piece of paper with text on it" in OpenGL (Specifically on iOS 5)

I've never done OpenGL, but I'm looking for some pointers on this particular question on an AR app I'm practicing with.
I'd like to make an app with a "flat rectangle" along with text written on the surface of the rectangle. Visually, I'm imagining something along the lines of a piece of paper with text written on it. Each time the app starts, the text would be something different (the text is pulled from a plist file).
The user would be able to view the paper from all sides, much as if there was a piece of paper hanging in front of him.
Is this trivial to do in OpenGL? How could I get started?
Sorry for the really open-ended question, but I wanted to get a feel for how this kind of thing is done.
Looking at the OpenGL template source code in the Xcode sample projects, I see that there is a big array of vertices. I presume that to create a "flat" rectangle, I'd essentally just have to remove or make the z-axis zero. And then the dynamic text that will attach to the surface of the flat rectangle...I dont have any idea how to do that......
This question is hard to answer unambiguously. In general, this is trivial, but then again it is not.
Drawing a "flat rectangle with something on it" is a couple of API calls, as simple as it can get. Drawing text in OpenGL in an efficient way, and high quality, and without big preprocessing is an entirely different story.
What I would do is render text using whatever the "normal system-supported" way is under iOS (just like you would draw in any window, I wouldn't know this specific detail), but draw into a bitmap rather than on the screen. This should be supported, pretty much every OS has supported this for at least 10-15 years. Then turn this bitmap into a texture, bind it, and draw your trivial flat quad with OpenGL (set up a vertex buffer with 4 vertices, each vertex a texture coordinate, and draw two triangles - as easy as it gets).
The huge advantage of that is that you get to use the installed system fonts (or any fonts available), you don't need to generate a bitmap font and don't need to think about really ugly things such as hinting and proper spacing, and it's much easier to mix different text styles, etc. OpenGL has built-in support for text too, of course, but it is not terribly efficient or nice either. If the text does not change every millisecond, it's really best to render it using the standard renderer that the operating system provides (yes, that probably won't be hardware accelerated, but so what... since the user must read the text, it likely won't change every millisecond).
Now it gets more complicated if your "piece of paper" should bend and twist too, or do a page peel effect rather than being just a flat rectangle. In that case you need to tesselate it, which can be harder than it sounds, too. Not all tesselations look optimal for all bends/twists, or they do but do not have the optimal (read as minimum) number of vertices.
There is an article on "page peel" and such tesselation in one of the GPU Gems or GPU Pro books, let me search...
There: Andreas Bizzotto: "A Shader-Based eBook Reader - Page peeling effect", GPU Pro2 pp. 278-299
Maybe you can get hold of a copy or are lucky enough to find it on Google Books or something.

How to draw a text (write on the screen) using standard OpenGL functions?

I know I can do it with GLUT. But, I have a big project and I had problem adding GLUT (I am using Delphi) to it.
So, what other options do I have?
You can't do it with standard OpenGL functions, unless you basically have textures with text in them, or a list of characters on a texture that you draw from. But don't reinvent the wheel - I would recommend FTGL for rendering text in an OpenGL view. It has several different rendering methods and takes care of things like kerning for you, supports unicode, and has good text metrics features too.
Use TextSuite. http://textsuite.opengl24.de/
Use FreeType to yield a bitmap given your text.
Edit: It is a mature cross platform library that brings a complete text display capabilities based on fonts including normal Windows TrueType fonts. Here is its definition from Wikipedia:
FreeType is a software library written
in C that implements a font
rasterization engine. It is used to
rasterize characters into bitmaps and
provides support for other
font-related operations.
If you do decide to implement your own font system be sure to use a texture atlas, I've seen too many OpenGL demos that use one texture per glyph, which leads to atrocious performance (due to the overheads incurred in the OpenGL driver and texture caches).

Delphi: image with alpha blending capabilities

Is there some simple component that could display PNG 32-bit images and alpha-blend it to another image on mouse enter and on mouse leave? Or even just a simple image that can load 32-bit PNG and additionally would have Alpha parameter...
I suppose I could use some skin library (alphacontrols?) or some graphics library, but for some simple purely visual effects that would be quite an overkill and I can't seem to find a simple one that does it for me and would work on Glass surface as well...
It is not quite a component, but here is a link to a good article on how to do it yourself. Its just a few lines of code:
http://melander.dk/articles/alphasplash/
The basic TImage is capable of displaying a PNG image and alpha-blend-it to whatever is behind it. You just need to add the "pngimage" unit to the uses clause of your form. You didn't mention the version of Delphi you're on: Delphi 2010 has this unit, but I have no idea with what version of Delphi they started shipping it. For Delphi 7 I know for sure you'll need to find the open source "pngimage".
If you need to do this when the user moves in and out of your control, consider caching the state images in bitmaps: it will be faster at runtime and you can use a single TImage that shows the current image, you don't need two overlapping TIMage controls.

Resources