Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

codefreak

alpha blending in vb

This topic is 6934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, im struggling with this alpha blending stuff. here are my routines: i know this is very slow and if someone got some pointers for me, please share it. i am using vb5 this is just to setup the loockup table ''Dim alpha(32) As Double Dim i As Double, j As Integer Dim r As Single, g As Single, b As Single alpha(1) = 0 alpha(2) = 0.03 alpha(3) = 0.06 alpha(4) = 0.09 alpha(5) = 0.13 alpha(6) = 0.17 alpha(7) = 0.21 alpha(8) = 0.24 alpha(9) = 0.27 alpha(10) = 0.31 alpha(11) = 0.34 alpha(12) = 0.37 alpha(13) = 0.41 alpha(14) = 0.44 alpha(15) = 0.47 alpha(16) = 0.49 alpha(17) = 0.51 alpha(18) = 0.53 alpha(19) = 0.56 alpha(20) = 0.59 alpha(21) = 0.63 alpha(22) = 0.66 alpha(23) = 0.69 alpha(24) = 0.73 alpha(25) = 0.76 alpha(26) = 0.79 alpha(27) = 0.83 alpha(28) = 0.87 alpha(29) = 0.91 alpha(30) = 0.94 alpha(31) = 0.97 alpha(32) = 1 For j = 0 To 32 For i = 0 To 65536 r = DX.ColorGetRed(i) g = DX.ColorGetGreen(i) b = DX.ColorGetBlue(i) r = r * alpha(j) g = g * alpha(j) b = b * alpha(j) pixelshade(j, i) = DX.CreateColorRGB(r, g, b) Next i Next j then this is what i do to change the colors: (and this is very slow) For i = 1 To 30 tmpdds2.Lock alpharect, tmpddsd, DDLOCK_WAIT, 0 For jx = 0 To 640 For jy = 0 To 480 srcpix = tmpdds.GetLockedPixel(jx, jy) despix = pixelshade(i, srcpix) tmpdds2.SetLockedPixel jx, jy, despix Next jy Next jx ''blit to backbuffer and flip tmpdds2.Unlock alpharect Call backbuffer.BltFast(0, 0, tmpdds2, rSrc, DDBLTFAST_WAIT) primary.Flip Nothing, DDFLIP_WAIT Next i but it doesnt work.... just get funny colors i think maybe it is my lookup table, is it ok to use the ColorGetBlue,ColorGetRed and ColorGetGreen functions or is it the Dx.CreateColorsRGB function, ive tried it with VB''s RGB function, but still doesnt work. please help anyone. thanks

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by codefreak

ok, im struggling with this alpha blending stuff.

here are my routines: i know this is very slow and if someone got some pointers for me, please share it.

i am using vb5

this is just to setup the loockup table


''Dim alpha(32) As Double
Dim i As Double, j As Integer
Dim r As Single, g As Single, b As Single

alpha(1) = 0
alpha(2) = 0.03
alpha(3) = 0.06
alpha(4) = 0.09
alpha(5) = 0.13
alpha(6) = 0.17
alpha(7) = 0.21
alpha(8) = 0.24
alpha(9) = 0.27
alpha(10) = 0.31
alpha(11) = 0.34
alpha(12) = 0.37
alpha(13) = 0.41
alpha(14) = 0.44
alpha(15) = 0.47
alpha(16) = 0.49
alpha(17) = 0.51
alpha(18) = 0.53
alpha(19) = 0.56
alpha(20) = 0.59
alpha(21) = 0.63
alpha(22) = 0.66
alpha(23) = 0.69
alpha(24) = 0.73
alpha(25) = 0.76
alpha(26) = 0.79
alpha(27) = 0.83
alpha(28) = 0.87
alpha(29) = 0.91
alpha(30) = 0.94
alpha(31) = 0.97
alpha(32) = 1

For j = 0 To 32
For i = 0 To 65536
r = DX.ColorGetRed(i)
g = DX.ColorGetGreen(i)
b = DX.ColorGetBlue(i)
r = r * alpha(j)
g = g * alpha(j)
b = b * alpha(j)
pixelshade(j, i) = DX.CreateColorRGB(r, g, b)
Next i
Next j



then this is what i do to change the colors:

(and this is very slow)
For i = 1 To 30
tmpdds2.Lock alpharect, tmpddsd, DDLOCK_WAIT, 0


For jx = 0 To 640
For jy = 0 To 480
srcpix = tmpdds.GetLockedPixel(jx, jy)


despix = pixelshade(i, srcpix)



tmpdds2.SetLockedPixel jx, jy, despix

Next jy
Next jx

''blit to backbuffer and flip
tmpdds2.Unlock alpharect
Call backbuffer.BltFast(0, 0, tmpdds2, rSrc, DDBLTFAST_WAIT)
primary.Flip Nothing, DDFLIP_WAIT

Next i


but it doesnt work.... just get funny colors

i think maybe it is my lookup table, is it ok to use the ColorGetBlue,ColorGetRed and ColorGetGreen functions
or is it the Dx.CreateColorsRGB function, ive tried it with VB''s RGB function, but still doesnt work.

please help anyone.

thanks


Well, I cannot help you with alpha blending in Direct Draw, but I can help you with optimization. I don''t think you really need the lookup table.

instead of
For j = 0 To 32
For i = 0 To 65536

''...

Next i
Next j

how about...

For j = 0 To 1 step .03
For i = 0 To 65536

''...

Next i
Next j

hmm?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!