How to do a fast plasma effect?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

How to do a fast plasma effect?

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

http://www.purebasic.com/Plasma_DSA.pb

Disable the debugger for fullspeed.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Fred wrote:http://www.purebasic.com/Plasma_DSA.pb

Disable the debugger for fullspeed.
Yes, that example is fine. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post 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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

djes wrote:DirectX may change the context...
Damn! :o
Thanks!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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...
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Sure you need it.
Post Reply