Page 1 of 1

How to do a fast plasma effect?

Posted: Fri Nov 28, 2008 11:49 pm
by Psychophanta
I am looking for a fast well done plasma effect with PB, but seems really difficult to do.... :roll:
may be using Palette library, but some of the modern VGA don't allow 8 bit depth modes :cry:
any idea would be welcome.

Posted: Sat Nov 29, 2008 12:26 am
by Hroudtwolf

Posted: Sun Nov 30, 2008 9:29 pm
by Psychophanta
Hroudtwolf wrote: Sorry, if I misunderstood "plasma".
Thanks,
well, it is more like this one:
http://www.purebasic.fr/english/viewtopic.php?t=14426
but there is very ugly.
The best ones i have seen was in some intro and cracktro for amiga platform.
http://es.youtube.com/watch?v=r5GGodIZsSA
http://es.youtube.com/watch?v=QpGuVdcynJA

Posted: Sun Nov 30, 2008 9:59 pm
by Fred
http://www.purebasic.com/Plasma_DSA.pb

Disable the debugger for fullspeed.

Posted: Sun Nov 30, 2008 10:02 pm
by Psychophanta
Fred wrote:http://www.purebasic.com/Plasma_DSA.pb

Disable the debugger for fullspeed.
Yes, that example is fine. :)

Posted: Mon Dec 01, 2008 1:47 pm
by Psychophanta
Arranged to:
- not to have a 'StartDrawing()-StopDrawing()' stuff inside main loop.
- not to have to flip buffers in the main loop.

Code: Select all

#ScreenWidth=800  ; Feel free to change this to see the pixel filling speed !
#ScreenHeight=600
Macro getdisplaydata
  StartDrawing(ScreenOutput())
  *Buffer.b=DrawingBuffer(); Get the start address of the screen buffer
  Pitch.l=DrawingBufferPitch(); Get the length (in byte) took by one horizontal line
  If DrawingBufferPixelFormat()=#PB_PixelFormat_32Bits_RGB; Get the pixel format.
    For i.w=0 To 255
      ColorTable(i)=i<<16; Blue is at the 3th pixel
    Next
  Else; Else it's 32bits_BGR
    For i=0 To 255
      ColorTable(i)=i; Blue is at the 1th pixel
    Next    
  EndIf
  StopDrawing()
EndMacro  
Macro writetodisplaymem
  For y.l=0 To #ScreenHeight-1
    pos1.l=CosTable(y+wave)
    *Line.Pixel=*Buffer+Pitch*y
    For x.l=0 To #ScreenWidth-1
      *Line\Pixel=ColorTable(CosTable(x+Wave)+CosTable(x+y)+pos1) ; Write the pixel directly to the memory !
      *Line+4
    Next
  Next
EndMacro
If InitSprite()=0 Or InitKeyboard()=0
  MessageRequester("Error","DirectX 7+ is needed.",0):End
EndIf
Structure Pixel
  Pixel.l
EndStructure
Dim CosTable.l(#ScreenWidth*2)
Dim ColorTable.l(255)
For i.w=0 To #ScreenWidth*2
  CosTable(i)=Sin(9/8*i*#PI/180.0)*32+32
Next
If OpenScreen(#ScreenWidth,#ScreenHeight,32,"PB Plasma")=0:MessageRequester("Error","Can't open the screen !",0):End:EndIf
getdisplaydata
FlipBuffers(#PB_Screen_NoSynchronization)
Repeat
  ExamineKeyboard()
  writetodisplaymem
  Wave+6
  If Wave>320:Wave=0:EndIf
  Delay(16)
Until KeyboardPushed(#PB_Key_Escape)
It works here like a charm.
But looks like it does not work for some PCs: Why?

Posted: Mon Dec 01, 2008 2:16 pm
by djes
DirectX may change the context, so that the drawingbuffer is not always at the same place. You have to put it in the main loop. I also had this issue long ago.

Posted: Mon Dec 01, 2008 2:46 pm
by Psychophanta
djes wrote:DirectX may change the context...
Damn! :o
Thanks!

Posted: Mon Dec 01, 2008 2:58 pm
by Psychophanta
A last question comes to me:
Is there needed to call StartDrawing() function before to call DrawingBuffer() or it doesn't?
Don't find in the manual...

Posted: Mon Dec 01, 2008 3:41 pm
by djes
I'm not sure, but I imagine you'll have to do it, as PB may do some sort of lock() and stuff like that to allow fast writing to the buffer.

Posted: Mon Dec 01, 2008 5:37 pm
by Fred
Sure you need it.