Speeding up Drawing 
Author Message
 Speeding up Drawing

My current project involves a heavy amount of lines, circles, and pset's.
For the most part, they work fast enough. But when panning (using the mouse,
in this case), the painting quickly "lags" behind the cursor. (Using the
API, I first draw the lines, etc., then I BitBlt the resulting image to the
screen, to stop flickering)

I am contemplating different options to pursure, and am interested in VB
Guru (or not so guru) advice on this NG :-)

One thought: C++ is faster than VB. Write the code to handle the drawing
routines (currently managed by a cGraphics object), in C++, thus providing a
faster way to draw. Problem a: the DLL overhead? Problem b: I dont know how
to program in C++ (yet) :-)

Another thought: the slowest point in my program seems to be when I set the
color of the lines, circles, points. I currently use "picMain.foreColor =
rgb(...)", but after running some benchmarks, I found that if I skipped the
color set, the API was significantly faster. Problem is, I need the
different colors. So is there a way to set the forecolor of the picture box
I am working on through the api? (Or some related Idea?)

Final thought: Write the cGraphics object by using DirectX... doing circles
by some sort of 2D-textured box.... er maybe on version 10.... :-)

C, A?

Thanks for any help!



Wed, 24 Nov 2004 04:59:16 GMT  
 Speeding up Drawing
This reply will probably be of no help whatsoever, but I wrote a game (long
ago in a galaxy far, far away...) using Java.  The coding is very similar to
C++, although the function calls differ greatly.  Be happy to send you the
graphics plotting code if you think it may help.  As far as C++ sytax goes,
look at JavaScript.  The function calls, divisions, comments are all
identicle.

Good luck.

P.S. I know nothing on graphics in VB (yet :->) or I would comment on that
as well.

G

Quote:
> My current project involves a heavy amount of lines, circles, and pset's.
> For the most part, they work fast enough. But when panning (using the
mouse,
> in this case), the painting quickly "lags" behind the cursor. (Using the
> API, I first draw the lines, etc., then I BitBlt the resulting image to
the
> screen, to stop flickering)

> I am contemplating different options to pursure, and am interested in VB
> Guru (or not so guru) advice on this NG :-)

> One thought: C++ is faster than VB. Write the code to handle the drawing
> routines (currently managed by a cGraphics object), in C++, thus providing
a
> faster way to draw. Problem a: the DLL overhead? Problem b: I dont know
how
> to program in C++ (yet) :-)

> Another thought: the slowest point in my program seems to be when I set
the
> color of the lines, circles, points. I currently use "picMain.foreColor =
> rgb(...)", but after running some benchmarks, I found that if I skipped
the
> color set, the API was significantly faster. Problem is, I need the
> different colors. So is there a way to set the forecolor of the picture
box
> I am working on through the api? (Or some related Idea?)

> Final thought: Write the cGraphics object by using DirectX... doing
circles
> by some sort of 2D-textured box.... er maybe on version 10.... :-)

> C, A?

> Thanks for any help!



Sun, 28 Nov 2004 12:20:25 GMT  
 Speeding up Drawing
Writing your code in C++ is unlikely to improve the speed of your drawing
because the most "time consuming" part of the task is the actual drawing
operation (API Line, Ellipse, Pset etc) and the time taken by your "logic
and arithmetic" is very small by comparison.

By the way, why are you Blitting to the screen after you have done your
drawings? The best way is to draw everything into an Autoredraw = True
Picture Box (so that the drawings are actually done into its Image property,
which is "hidden" in memory) and then use a PicBox.Refresh command when you
have finished, which will cause the operating system to transfer the
completed Image to the screen display at the next available video frame.

Also, avoid using a "mix" of API functions and standard VB drawing
functions, because any VB drawing function (Line, Circle, Pset or anything
like that) into an Autoredraw Picture Box will automatically "trigger" the
VB Autoredraw refresh system whereas the VB Autoredraw refresh system knows
nothing at all about the stuff you are drawing with the API until you "tell
it" that something has been drawn and needs to be transferred
(PicBox.Refresh).

By the way, setting the ForeColor to any specific value doesn't actually
slow down any of the API drawing methods (LineTo, Circle, SetPixel etc), but
the act of setting the Forecolor itself takes some time, of course, so for
maximum speed you should ensure that you are only changing it when it is
absolutely necessary, and certainly not before every single drawing command
"in the drawing loop itself". The idea would be to set the colour to a
specific value and then draw everything that needs to be drawn in that
colour. Then set the colour to some other value and draw all those things.
You can also speed things up a little bit by using the API to set the
drawing colour, but if your code is written correctly then the overall speed
increase will be so little that it is hardly worth bothering. Also,
everything will work significantly slower if the pen width (VB DrawWidth or
API CreatePen) is greater than one pixel, so avoid drawing "thick" lines or
circles unless it is absolutely necessary.

Another thing to avoid (even though the automatic "clipping" normally takes
care of it for you) is drawing stuff that currently "cannot be seen". It is
best if your own drawing logic itself omits to draw those things that are
entirely "off the viewable area". When dealing with graphics, the "logic and
arithmetic" part of your code is very, very quick (once compiled) when
compared to the drawing operations themselves (almost insignificant, in
fact), so writing even long, complex routines will actually speed things up
if those routines result in a more efficient drawing process.

Mike


Quote:
> My current project involves a heavy amount of lines, circles, and pset's.
> For the most part, they work fast enough. But when panning (using the
mouse,
> in this case), the painting quickly "lags" behind the cursor. (Using the
> API, I first draw the lines, etc., then I BitBlt the resulting image to
the
> screen, to stop flickering)

> I am contemplating different options to pursure, and am interested in VB
> Guru (or not so guru) advice on this NG :-)

> One thought: C++ is faster than VB. Write the code to handle the drawing
> routines (currently managed by a cGraphics object), in C++, thus providing
a
> faster way to draw. Problem a: the DLL overhead? Problem b: I dont know
how
> to program in C++ (yet) :-)

> Another thought: the slowest point in my program seems to be when I set
the
> color of the lines, circles, points. I currently use "picMain.foreColor =
> rgb(...)", but after running some benchmarks, I found that if I skipped
the
> color set, the API was significantly faster. Problem is, I need the
> different colors. So is there a way to set the forecolor of the picture
box
> I am working on through the api? (Or some related Idea?)

> Final thought: Write the cGraphics object by using DirectX... doing
circles
> by some sort of 2D-textured box.... er maybe on version 10.... :-)

> C, A?

> Thanks for any help!



Sun, 28 Nov 2004 18:53:37 GMT  
 Speeding up Drawing
You might take a look at Addflow
See http://www.lassalle.com/
This is an activeX that handles drawing in VB and it is Fast
I do not work for them by the way, but I recommend it to anyone who is
trying to draw diagrams in VB.


Sun, 28 Nov 2004 21:21:23 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Speed Comparison Post #1 of 2 (Was Fast Drawing)

2. Speed Comparison Post #2 of 2 - quite large (Was Fast Drawing)

3. Line speed (sucks!), drawing rectangles

4. Line speed (sucks!), drawing rectangles

5. WebBrowser Draw Speed

6. Speed of drawing using api/VB

7. Text Drawing Speed using WinAPI

8. Speed problems with drawing large graphics

9. Help! Speed problems with drawing large graphics

10. Improving draw speed for image control

11. Speed, Speed, and Speed!

12. Speed Speed Speed - Cutting down on wasted cycles

 

 
Powered by phpBB® Forum Software