I can't get this to work (Additive Blend function)
Blitz3D Forums/Blitz3D Beginners Area/I can't get this to work (Additive Blend function)
| ||
Can anybody help me figure out what the problem is? I've tried this with both TextureBuffers and ImageBuffers. Neither seems to work. I can load and display the images individually by copying them to the backbuffer, but when I call the function, it just produces a black box. I'm still very new at this and I wrote this code without a firm experience-based understanding of what each command does, just the info I've read in the Blitz3D command reference. So probabaly, one of the commands I used doesn't do what I think it does. If anyone can explain what the problem is, or can make this work, please let me know. Thanks in advance for any helpful replies. :) Graphics3D 800,600,16,0 camera=CreateCamera() Global Target= CreateImage(64,64) Global Source1= LoadImage("tex1.bmp") Global Source2= LoadImage("tex2.bmp") AddBlend(Source1,Source2,Target) Repeat Mil1=MilliSecs() UpdateWorld RenderWorld SetBuffer BackBuffer() CopyRect 0,0,64,64,0,0,ImageBuffer(Target),BackBuffer() Mil2= MilliSecs() Color 255,255,0 Text 4,500,"Render time: "+(Mil2-Mil1) Flip Until KeyDown(1) Function AddBlend(SourceTexture1,SourceTexture2,TargetTexture) For x = 0 To 64 For y = 0 To 64 SetBuffer ImageBuffer(SourceTexture1) GetColor x,y r1#=ColorRed g1#=ColorGreen b1#=ColorBlue SetBuffer ImageBuffer(SourceTexture2) GetColor x,y r2#=ColorRed g2#=ColorGreen b2#=ColorBlue SetBuffer ImageBuffer(TargetTexture) Color r1#+r2#,g1#+g2#,b1#+b2# Plot x,y Next Next End Function |
| ||
Easy Edit: r1#+r2# might been higher than 255 and might loop to 0 DrawImage might be faster than CopyRect |
| ||
GAH! I forgot the ()! :P Why do so many commands with no parameters use ()s? Or is that to keep from confusing them with handles? Oh well, thanks Luke. :D I had a feeling my technique was right and the mistake was something simple like that. :P I'll have to remember to check for ()'s in the command descriptions and example code, from now on. |
| ||
Why do so many commands with no parameters use ()s? Or is that to keep from confusing them with handles? Function's names can be reused as vars. |
| ||
Any function that returns a value needs the brackets. |
| ||
Hi WarpZone, i messed with your code and added some blend modes: Global Target= CreateImage(256,256) Global Source1= LoadImage("rock.bmp") Global Source2= LoadImage("water.bmp") Blend(Source1,Source2,Target,"Average") SetBuffer BackBuffer() CopyRect 0,0,256,256,0,0,ImageBuffer(Target),BackBuffer() Flip Repeat Until KeyDown(1) Function Blend(SourceTexture1,SourceTexture2,TargetTexture,BlendMode$) Time1 = MilliSecs() For x = 0 To 256 For y = 0 To 256 SetBuffer ImageBuffer(SourceTexture1) GetColor x,y r1#=ColorRed() g1#=ColorGreen() b1#=ColorBlue() SetBuffer ImageBuffer(SourceTexture2) GetColor x,y r2#=ColorRed() g2#=ColorGreen() b2#=ColorBlue() SetBuffer ImageBuffer(TargetTexture) Select BlendMode Case "Average" Color (r1# + r2#) Shr 1 ,(g1# + g2#) Shr 1,(b1# + b2#) Shr 1 Case "Multiply" Color (r1# * r2#) Shr 8 ,(g1# * g2#) Shr 8,(b1# * b2#) Shr 8 Case "Screen" Color 255-((255-r1#) * (255-r2#) Shr 8) , 255-((255-g1#) * (255-g2#) Shr 8),255-((255-b1#) * (255-b2#) Shr 8) End Select Plot x,y Next Next Time2 = MilliSecs() TimeNeeded = Time2 - Time1 End Function I have tried to speed it up with writepixel etc. but got no luck... http://www.moonworx.de |
| ||
You may speed up things massively when you first read all pixels to an array, then process the array instead of the buffer and finally write the array back to the buffer. The reason why is the machine will be able to cache things this way. Tho in a 64*64 Buffer it doesn't matter that much. |