I would like to make a tail or streak-like effect for a moving points that fades out behind them. I tried to avarage the color of the buffer each frame then bitblt the results, I got something similar to the tail but at the cost of speed.
So anyone has any idea? I am using GDI API with VB6.
There is a few things you can do with GDI, a lot depends on what else you have going on and how many points you have.
I'd be better placed to suggest ideas if i knew a little more about what you are doing.
You say you have tried averaging the colours in the buffer, are you using a DIB for a buffer? Are you familiar with DIBs. How many moving points do you potentially have? How far (in pixels) do they move each frame?
There does come a point when regular GDI simply can't hack the amount of stuff going on. It's the time to consider using DirectX or Open GL.
There does come a point when regular GDI simply can't hack the amount of stuff going on. It's the time to consider using DirectX or Open GL.
While this is true.. it is possible to hack together stuff that looks fine anyway..
What is the object you're trying to tail ? Is it large? Small? Medium sized? Square? Circle?
One way I have used before to streak behind a large object, was to create a 1-pixel high by 40-pixel wide white image.. then blit that behind the object about 10 times. Then, with each one, I would just average random pixels from around rows 4-10, until the end had pretty much all of the pixels transparent.
So, instead of calculating 40*10 pixels individually and drawing them individually (which costs alot of cycles), you're drawing only 10 images, and altering only 7 of them slightly each time.
Attached is an extremely bad example in paint.. but it sorta outlines what I mean.
chem
Last edited by chemicalNova; Jul 18th, 2008 at 01:50 AM.
I'm pleasantly surprised at your post there Chem. I like GDI, it can do most of the things I want. I'll show you an example of what I mean by too much, that smoke trail below works fine in VB on it's own, but if I had say another 100 sprites and a few other blend effects then it starts to struggle.
I'm sorry for being late in my reply, I was out of internet connection..
anyway,
In fact am doing a kind of galaxy simulation with stars rotating around the center of the galaxy (using centripetal force and gravitation..etc)..so the number of my starts could be anything from 500 to 1000.
I know about DIB sections..but actaully I did not use it , I used instead GetBitmapBits
Milk - can you please give some hint about the smoke effect you made in that picture?
I would recommend that you don't use GetBitmapBits, rather create a DIBSection of the right size and use a SafeArray hack to access the pixel data. This means you don't have to make a copy of the bitmap every time you want to manipulate it.
This is the smoke trail code, nothing special. Attached is the source bitmap, it needs to be loaded into the PicSrc picturebox.
Code:
Option Explicit
Private Declare Function AlphaBlend Lib "msimg32" (ByVal hDestDC As Long, _
ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal widthSrc As Long, _
ByVal heightSrc As Long, ByVal blendFunct As Long) As Boolean
Private Const USE_BITMAP_ALPHA = &H1000000 'AC_SRC_ALPHA scaled up to the 4th byte of a long
Private Const FULL_OPACITY = &HFF0000 '255 scaled up to the 3rd byte of a long
Private mMosX As Long
Private mMosY As Long
Private mFrameX() As Long
Private mFrameY() As Long
Private mFrameUB As Long
Private mCurFrame As Long
Private mFrameSz As Long
Private Sub Form_Load()
ScaleMode = vbPixels
AutoRedraw = True
With picSrc
.AutoRedraw = True
.Autosize = true
.ScaleMode = vbPixels
.BorderStyle = 0
.Visible = false
mFrameUB = .Width \ .Height - 1
mFrameSz = .Height
End With
ReDim mFrameX(mFrameUB)
ReDim mFrameY(mFrameUB)
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
mMosY = -mFrameSz \ 2
mMosX = X + mMosY
mMosY = Y + mMosY
End Sub
Private Sub Timer1_Timer()
Dim i As Long, j As Long, XOff As Long
If mCurFrame < mFrameUB Then mCurFrame = mCurFrame + 1 Else mCurFrame = 0
mFrameX(mCurFrame) = mMosX - 8 + Rnd * 16
mFrameY(mCurFrame) = mMosY - 8 + Rnd * 16
Cls
XOff = mFrameUB * mFrameSz
j = mCurFrame - 1
For i = 0 To mFrameUB
If j < mFrameUB Then j = j + 1 Else j = 0
AlphaBlend hDC, mFrameX(j), mFrameY(j), mFrameSz, mFrameSz, picSrc.hDC, XOff, 0, mFrameSz, mFrameSz, USE_BITMAP_ALPHA Or &H400000
XOff = XOff - mFrameSz
Next i
Refresh
End Sub