Re: Newbie looking for info on basic graphics with Delphi.



"Mike Barnard" <m.barnard.trousers@xxxxxxxxxxxxxxx> wrote in message
news:qph9k2lakvjokb1edfdhqdms8a5nvioilm@xxxxxxxxxx
[...]
What I'd like it to be able to draw a basic wireframe to scale on a
panel objuct on the main form. I have googled and come up with stuff
that I can't use or is too advanced. Can anyone point me to a basic
tutorial on stuff like this?

I don't know about basic. It's a mixture of linear algebra (matrix math)
and goniometry (angle math). I doubt any of my neighbours would go far
with any of the books I have.

But then, they're not programmers. I could try to explain if you felt up
to it. *I* didn't find it very complicated, for all that's worth.


Questions I have are:

Does every viewable object (buttons, listboxes, panels etc) have its
own canvas?

No, some of them draw on their parent's canvas. I think all of Windows'
own controls have their own canvas, though, called 'device contexts' by
Windows.

As a counterexample, a TImage (a TGraphicControl) uses a bitmap's
canvas to draw on, and when it is asked to paint itself (on a device
context specified in the WM_PAINT message), it copies the bitmap to it.


Do I need to use a canvas to draw?

Yes. They are Windows' way of drawing. But it need not be your own.
Many people draw directly on a form's canvas.

I'd like to take the opportunity to offer some counterweight to all
the people who advocate using TImages as generic canvases. As noted
above, a TImage is indeed a generic canvas, with the nice property
that it _holds_ whatever you draw on it. The bitmap stores all the
pixels.

But Delphi also offers the TPaintBox, which takes a different approach.
The pixels are redrawn every time Windows needs them, by the programmer
hooking the OnPaint event. If rendering the image is not much work,
this is more lightweight than the bitmap's caching. In my opinion and
experience, drawing a wireframe isn't much work and so my OnPaint handler
was a simple 'Canvas.Assign(Model)'. (The Model has an overridden
AssignTo which knows that assigning to a TCanvas means to draw itself
onto it.)

It might be argued that recomputing the complete cordinate transforms
every time was a bit over the top. But the usual cause for an Invalidate
_was_ that the coordinate transform had changed (user input to the
viewer: rotating/translating/zooming) and at least I didn't repeat it
for every individual line.


Where can I find some basic algorithms for wireframe drawing?

I have some source. I'll see if I can put it on my website.

Groetjes,
Maarten Wiltink


.