Page 3 of 5

Posted: Mon Sep 08, 2008 8:11 am
by djes
liam wrote:wow, i cant believe you can do so much with such little code in PB!
you guys are sick! :shock:
Just try! You'll see it's not so difficult :)

Posted: Wed Sep 10, 2008 11:05 am
by Psychophanta
Awesome thread :o :!:
Please make it sticky :)

I hope to add my bits soon 8)

Posted: Wed Sep 10, 2008 1:14 pm
by djes
Psychophanta wrote:Awesome thread :o :!:
Please make it sticky :)

I hope to add my bits soon 8)
Hope too :)

Posted: Mon Dec 01, 2008 12:15 pm
by Psychophanta
Plasma, based in an example from PB team, but arranged by me in 2 important aspects:
- not to have a 'StartDrawing()-StopDrawing()' stuff inside main loop.
- not to have to flip buffers in the main loop.
Here it is:

Code: Select all

DisableDebugger:InitSprite():InitKeyboard():Dim CosTable.l(1599):Dim ColorTable.l(255):For i.w=0 To 1599:CosTable(i)=Sin(9/8*i*#PI/180.)*32+32:Next:OpenScreen(800,600,32,"Plasma") 
StartDrawing(ScreenOutput()):*Buffer=DrawingBuffer():*Buffer2=*Buffer:Pitch=DrawingBufferPitch():For i=0 To 255:ColorTable(i)=i:Next:StopDrawing():FlipBuffers() 
Repeat:ExamineKeyboard():If *Buffer2<>*Buffer:StartDrawing(ScreenOutput()):*Buffer=DrawingBuffer():*Buffer2=*Buffer:StopDrawing():EndIf
For y.l=0 To 599:pos1.l=CosTable(y+wave):*Line.long=*Buffer+Pitch*y:For x.l=0 To 799:*Line\l=ColorTable(CosTable(x+Wave)+CosTable(x+y)+pos1):*Line+4:Next:Next:Wave+6:If Wave>320:Wave=0:EndIf 
Delay(16):Until KeyboardPushed(#PB_Key_Escape) 
:)

Posted: Mon Dec 01, 2008 12:38 pm
by djes
I have an invalid memory address here...

Posted: Mon Dec 01, 2008 12:55 pm
by Psychophanta
djes wrote:I have an invalid memory address here...
Damn!, strange; where? can you give me the line?
Mmm... not the line, but the command :P

Posted: Mon Dec 01, 2008 1:22 pm
by traumatic
Psychophanta wrote:Plasma, based in an example from PB team, but arranged by me in 2 important aspects:
- not to have a 'StartDrawing()-StopDrawing()' stuff inside main loop.
- not to have to flip buffers in the main loop.
Sorry but that's exactly what makes it crash here :)

Posted: Mon Dec 01, 2008 1:28 pm
by Psychophanta
Oh! here it works like a charm!
May be pure luck or what?

I really doubt any of those arrangements are the cause of a crash :roll:

Posted: Mon Dec 01, 2008 1:43 pm
by traumatic
Psychophanta wrote:Oh! here it works like a charm!
May be pure luck or what?

I really doubt any of those arrangements are the cause of a crash :roll:
Well, putting the StartDrawing()/DrawingBuffer() bit _inside_ the loop
works. Your modification however does not (invalid memory access).

Posted: Mon Dec 01, 2008 1:48 pm
by Psychophanta
Just reported it in the coding questions:
http://www.purebasic.fr/english/viewtop ... 091#269091

Posted: Mon Dec 01, 2008 2:52 pm
by Psychophanta
Thanks djes
it should work now for everyone

Posted: Mon Dec 01, 2008 4:23 pm
by djes
In fact... no! I've modified to make it work... But I've lost your optimisation on the way :cry:

Code: Select all

InitSprite()
InitKeyboard()

If OpenScreen(800,600,32,"Plasma")=0
  Debug "Can't create screen"
  End
EndIf

StartDrawing(ScreenOutput())
If DrawingBufferPixelFormat()&(#PB_PixelFormat_32Bits_RGB|#PB_PixelFormat_32Bits_RGB)=0
  Debug "No 32 bits screen mode available"
  End
EndIf
StopDrawing()

Dim CosTable.l(1599)
Dim ColorTable.l(255)

For i.w=0 To 1599
  CosTable(i)=Sin(9/8*i*#PI/180.)*32+32
Next

If DrawingBufferPixelFormat()=#PB_PixelFormat_32Bits_RGB
  For i=0 To 255
    ColorTable(i)=i
  Next
Else
  For i=0 To 255
    ColorTable(i)=i<<16
  Next
EndIf

Repeat

  ExamineKeyboard()

  StartDrawing(ScreenOutput())
 
  *Buffer=DrawingBuffer()
  Pitch=DrawingBufferPitch()

  For y.l=0 To 599
    pos1.l=CosTable(y+wave)
    *Line.long=*Buffer
    For x.l=0 To 799
      *Line\l=ColorTable(CosTable(x+Wave)+CosTable(x+y)+pos1)
      *Line+4
    Next
    *Buffer+Pitch
  Next

  Wave+6
  If Wave>320
    Wave=0
  EndIf

  StopDrawing()

  FlipBuffers(1)

Until KeyboardPushed(#PB_Key_Escape) 

End

Posted: Mon Dec 01, 2008 10:21 pm
by Psychophanta
Very bad, because that is the same as the example by PB Team.
So ATM nothing new. :(

Posted: Tue Dec 02, 2008 9:08 am
by djes
Yes :cry: ... Anyway, there's still a lot of optimisations to do :P

Posted: Tue Dec 02, 2008 7:08 pm
by djes
Licorn horn (only with DirectX9! Else a simple worm)

Code: Select all

;Should only work with PB4.30b5

SetPriorityClass_(  GetCurrentProcess_(), #HIGH_PRIORITY_CLASS)

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf

If InitSprite3D() = 0
  MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
  End
EndIf

If OpenScreen(640, 480, 32, "Sprite")

  CreateSprite(0, 128, 128, #PB_Sprite_Texture)
  StartDrawing(SpriteOutput(0))
  a.f = 0
  For y = 0 To 127
    For x = 0 To 127
      vx.f = x - 64
      vy.f = y - 64
      dist.f = Sqr(vx * vx + vy * vy)
      If dist = 0 : dist = 0.0001 : EndIf
      If dist < 64
        vx   = vx / dist
        vy   = vy / dist
        c = 128 + 128 * ACos(vx * vy)
        Plot(x, y, RGB(c, $55, c/2))
      EndIf
    Next x
  Next y
  StopDrawing()
  CopySprite(0, 1)

  CreateSprite3D(0, 0)

  SetFrameRate(60)
  SetRefreshRate(60)

  frame_counter = 0

  Repeat
     
    ClearScreen(RGB($55, 0, $55))
   
    If Start3D()

      RotateSprite3D(0, frame_counter * 5, 0)

      For u=0 To 255 Step 1
        x = 150 * Sin((frame_counter * 2 + u) / 50)
        DisplaySprite3D(0, 256 + x, u, 255 * Sin(u * #PI / 256))
        ZoomSprite3D(0, 64, 32 + u/2)
        RotateSprite3D(0, 5, 1)
      Next u

      Stop3D()

    EndIf
   
;    Delay(15)
    FlipBuffers(1)
    frame_counter + 1
   
    ExamineKeyboard()

  Until KeyboardPushed(#PB_Key_Escape)
 
Else
  MessageRequester("Error", "Can't open a 640*480 - 32 bit screen !", 0)
EndIf

End