Author Topic: Requiring helps for purebasic.  (Read 7045 times)

0 Members and 1 Guest are viewing this topic.

Offline maracuja

  • C= 64
  • **
  • Posts: 31
  • Karma: 4
    • View Profile
Re: Requiring helps for purebasic.
« Reply #20 on: August 03, 2011 »
I'm back, so this code in "theory" will be work but not....
Code: [Select]
Global s$
; Constants

#WINTITLE  = "E-Swat - Replicants Remake"
#WINHEIGHT = 480
#WINWIDTH  = 640
#BPP       = 32
#SPRH = 16 ; sprite height
#SPRW = 16;  " "    width
;Declaration procedure
Declare PrintTransparentSprite(IdSprite, x, y , r, g, b)
Declare getLetterPos(caractere$)
Declare getFonts(IdSprite, x, y, w, h, num, r, g, b)
Declare ErrorWindowCreation()
Declare Anim(fullscreen.b)
Declare PrintTextWindows(text$)
;
; 8x8
; DC.B      '            ----------------            '
; DC.B      '            -THE REPLICANTS-            '
; DC.B      '            ----------------            ',$00
; DC.B      '           PRESENTS: - ESWAT + -        '
; DC.B      '                                        '
; DC.B      'GREETZ TO : AVB,NEXT,AUTOMATION,TMB     '
; DC.B      'THE POMPEY PIRATES,PHALANX,ALLIANCE,BB, '
; DC.B      'DELIGHT,FOF,TLB,TDI,QUARTET,HTL,MCA,    '
; DC.B      'THOR,MAD VISION,INNER CIRCLE,TSG...     ',$00
; DC.B      '                                        '
; DC.B      'MEGA THANX TO THE BWK FOR DIS LOGO...   ',$00
; DC.B      '          BASH ',$27,'T',$27,' FOR TRAINER          ',$FF
;
s$ =      "            ----------------            " + Chr(10) + Chr(13)
s$ = s$ + "            -THE REPLICANTS-            " + Chr(10) + Chr(13)
s$ = s$ + "            ----------------            " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "           PRESENTS: - ESWAT + -        " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "GREETZ TO : AVB,NEXT,AUTOMATION,TMB     " + Chr(10) + Chr(13)
s$ = s$ + "THE POMPEY PIRATES,PHALANX,ALLIANCE,BB, " + Chr(10) + Chr(13)
s$ = s$ + "DELIGHT,FOF,TLB,TDI,QUARTET,HTL,MCA,    " + Chr(10) + Chr(13)
s$ = s$ + "THOR,MAD VISION,INNER CIRCLE,TSG...     " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "MEGA THANX TO THE BWK FOR DIS LOGO...   " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "          BASH 'T' FOR TRAINER          " + Chr(10) + Chr(13)


; print a sprites
Procedure PrintTransparentSprite(IdSprite, x, y, r, g, b)
  TransparentSpriteColor(IdSprite, RGB(r,g,b))
  DisplayTransparentSprite(IdSprite, x, y)
EndProcedure

; give the position of caractere$ in alpha variable.
; parameters:
; In :
; - caractere$ : a char to find in a array which synchronized with letter on a bitmap fonts
; Out :
; - an integer which returns the good position if the char exist else 0 but here 0 is space.
Procedure getLetterPos(caractere$)

  alpha$ =          " !" + Chr(34) + "    '()*+,-. 0123456789:; = ? ABCDEFG"
  alpha$ = alpha$ + "HIJKLMNOPQRSTUVWXYZ"
 

    length = Len(alpha$);

    i = 1;

    While (Mid(alpha$, i, 1) <> Mid(caractere$, 1, 1) And i <= length)
      i = i + 1
    Wend

    If i > length
      ProcedureReturn 0
    EndIf
   
    ProcedureReturn i; 
EndProcedure


; take the good bitmap char in a sprite picture. Before num computed by getLetterPos
; parameters :
; In :
; - IdSprite : sprite handle which contains bitmap fonts
; - x,y : letter position in pixel in a pic
; - w,h : width, height in pixel for a letter
; - num : logic letter position in a pic
; - r,g,b : transparency color for sprite
; Out:
;
Procedure getFonts(IdSprite, x, y, w, h, num, r, g, b)
  fontsW = SpriteWidth(IdSprite) ; [!] Just take with sprite width
  ; ClipSprite(IdSprite, #PB_Default, #PB_Default, #PB_Default, #PB_Default)
  ; reinit original sprite size after clipping
  posX = (num-1) % ((fontsW / w))
  posY = (num-1) / ((fontsW / w))
  srcX = (posX) * w
  srcY = (posY) * h
  srcH = h
  srcW = w
 
  ClipSprite(IdSprite, srcX, srcY, srcW, srcH)
  PrintTransparentSprite(IdSprite, x, y, r, g, b)
  ClipSprite(IdSprite, #PB_Default, #PB_Default, #PB_Default, #PB_Default)
EndProcedure

; Generic Error function.
Procedure ErrorWindowCreation()
  MessageRequester("Error", "This is fucked up, I can't create the window", 0)
  End
EndProcedure

; Animatation routine
; In:
; - fullscreen.b : create an animation in fullscreen mode or not. Two state: 0/false -> windowed mode, 1/true -> fullscreen
: Out:
;
Procedure Anim(fullscreen.b)
  ;Init subsystem and the windows with fullscreen or not
  InitSprite()
  InitKeyboard()
  If fullscreen
    If OpenScreen(#WINWIDTH, #WINHEIGHT, #BPP, #WINTITLE) = 0
      ErrorWindowCreation()
    EndIf
  Else
    If OpenWindow(1337,0,0,#WINWIDTH, #WINHEIGHT, #WINTITLE, #PB_Window_BorderLess | #PB_Window_ScreenCentered)
      If Not OpenWindowedScreen(WindowID(1337), 0, 0, #WINWIDTH, #WINHEIGHT, 1, 0, 0)
        ErrorWindowCreation()
      EndIf
    Else
       ErrorWindowCreation()
    EndIf
  EndIf

  ;Animation
  Result = CatchSprite(0, ?fontsReps, #PB_Sprite_Texture)
  Result = CatchSprite(1, ?logoReps, #PB_Sprite_Texture)
  Result = CreateImage(12, #WINWIDTH, #WINHEIGHT,#BPP)
  ClearScreen(0)
  Repeat
  xpad = 0
  ypad = 0
  StartDrawing(ImageOutput(12))
  For i = 1 To Len(s$) Step 1
    car$ = Mid(s$, i , 1)
    Select car$
      Case Chr(10)
        ypad = ypad + #SPRH
      Case Chr(13)
        xpad = 0
      Default
        getFonts(0,xpad, ypad+156, #SPRW, #SPRH, getLetterPos(car$), 0, 0, 0)
        xpad = xpad + #SPRW
    EndSelect
  Next i
  PrintTransparentSprite(1, 0, 0, 0, 0, 0)
  StopDrawing()
   
   
  ClearScreen(0)
  StartDrawing(ScreenOutput())
  DrawImage(ImageID(12),0,100) ; Here, if i removed ImageID the program segfault.
  StopDrawing()                              ; In all case nothing are print. But it's backbuffer -> frontbuffer right ?
  FlipBuffers()
    If fullscreen = 0
      Event = WaitWindowEvent(0)
    EndIf
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Space) Or KeyboardPushed(#PB_Key_T)
 
EndProcedure

; Init the question for fullscreen or windowed mode. After selection the button, the animation will be in a good screen mode
; In :
; - text$ : Is the message for MessageBox
; Out :
;
Procedure PrintTextWindows(text$)
  Result = MessageRequester(#WINTITLE, text$,#PB_MessageRequester_YesNoCancel)
  Select Result
    Case #PB_MessageRequester_Yes
      Anim(#True)
    Case #PB_MessageRequester_No
      Anim(#False)
    EndSelect
EndProcedure



;!!!!! Begin !!!!!
  PrintTextWindows("Credits : Jace, Padman, StormBringer !!! and you ;o)"+ Chr(10) + Chr(13) + "Do you want Fullscreen ? :)")

  End ; va!n advice
;!!!!! End !!!!!

DataSection
  fontsReps: IncludeBinary("eswatfonts.bmp")
  logoReps:  IncludeBinary("eswatlogo.bmp")
EndDataSection

; IDE Options = PureBasic 4.51 (Linux - x86)
; CursorPosition = 196
; FirstLine = 158
; Folding = -

Offline maracuja

  • C= 64
  • **
  • Posts: 31
  • Karma: 4
    • View Profile
Re: Requiring helps for purebasic.
« Reply #21 on: August 03, 2011 »
Another strange effect :

Code: [Select]
Global s$
; Constantes

#WINTITLE  = "E-Swat - Replicants Remake"
#WINHEIGHT = 480 ; Impossible de faire du 320x200, résolution minimale 640x480
#WINWIDTH  = 640
#BPP       = 32
#SPRH = 16
#SPRW = 16
;Declaration procedure
Declare PrintTransparentSprite(IdSprite, x, y , r, g, b)
Declare getLetterPos(caractere$)
Declare getFonts(IdSprite, x, y, w, h, num, r, g, b)
Declare ErrorWindowCreation()
Declare Anim(fullscreen.b)
Declare PrintTextWindows(text$)

;Include text
;XIncludeFile "Payload.pbi" ; crack message

;
; 8x8
; DC.B      '            ----------------            '
; DC.B      '            -THE REPLICANTS-            '
; DC.B      '            ----------------            ',$00
; DC.B      '           PRESENTS: - ESWAT + -        '
; DC.B      '                                        '
; DC.B      'GREETZ TO : AVB,NEXT,AUTOMATION,TMB     '
; DC.B      'THE POMPEY PIRATES,PHALANX,ALLIANCE,BB, '
; DC.B      'DELIGHT,FOF,TLB,TDI,QUARTET,HTL,MCA,    '
; DC.B      'THOR,MAD VISION,INNER CIRCLE,TSG...     ',$00
; DC.B      '                                        '
; DC.B      'MEGA THANX TO THE BWK FOR DIS LOGO...   ',$00
; DC.B      '          BASH ',$27,'T',$27,' FOR TRAINER          ',$FF
;
s$ =      "            ----------------            " + Chr(10) + Chr(13)
s$ = s$ + "            -THE REPLICANTS-            " + Chr(10) + Chr(13)
s$ = s$ + "            ----------------            " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "           PRESENTS: - ESWAT + -        " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "GREETZ TO : AVB,NEXT,AUTOMATION,TMB     " + Chr(10) + Chr(13)
s$ = s$ + "THE POMPEY PIRATES,PHALANX,ALLIANCE,BB, " + Chr(10) + Chr(13)
s$ = s$ + "DELIGHT,FOF,TLB,TDI,QUARTET,HTL,MCA,    " + Chr(10) + Chr(13)
s$ = s$ + "THOR,MAD VISION,INNER CIRCLE,TSG...     " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "MEGA THANX TO THE BWK FOR DIS LOGO...   " + Chr(10) + Chr(13) + Chr(10) + Chr(13)
s$ = s$ + "          BASH 'T' FOR TRAINER          " + Chr(10) + Chr(13)


; print a sprites
Procedure PrintTransparentSprite(IdSprite, x, y, r, g, b)
  TransparentSpriteColor(IdSprite, RGB(r,g,b))
  DisplayTransparentSprite(IdSprite, x, y)
EndProcedure

; give the position of caractere$ in alpha variable.
; parameters:
; In :
; - caractere$ : a char to find in a array which synchronized with letter on a bitmap fonts
; Out :
; - an integer which returns the good position if the char exist else 0 but here 0 is space.
Procedure getLetterPos(caractere$)

  alpha$ =          " !" + Chr(34) + "    '()*+,-. 0123456789:; = ? ABCDEFG"
  alpha$ = alpha$ + "HIJKLMNOPQRSTUVWXYZ"
 

    length = Len(alpha$);

    i = 1;

    While (Mid(alpha$, i, 1) <> Mid(caractere$, 1, 1) And i <= length)
      i = i + 1
    Wend

    If i > length
      ProcedureReturn 0
    EndIf
   
    ProcedureReturn i; 
EndProcedure


; take the good bitmap char in a sprite picture. Before num computed by getLetterPos
; parameters :
; In :
; - IdSprite : sprite handle which contains bitmap fonts
; - x,y : letter position in pixel in a pic
; - w,h : width, height in pixel for a letter
; - num : logic letter position in a pic
; - r,g,b : transparency color for sprite
; Out:
;
Procedure getFonts(IdSprite, x, y, w, h, num, r, g, b)
  fontsW = SpriteWidth(IdSprite) ; [!] Just take with sprite width
  ; ClipSprite(IdSprite, #PB_Default, #PB_Default, #PB_Default, #PB_Default)
  ; reinit original sprite size after clipping
  posX = (num-1) % ((fontsW / w))
  posY = (num-1) / ((fontsW / w))
  srcX = (posX) * w
  srcY = (posY) * h
  srcH = h
  srcW = w
 
  ClipSprite(IdSprite, srcX, srcY, srcW, srcH)
  PrintTransparentSprite(IdSprite, x, y, r, g, b)
  ClipSprite(IdSprite, #PB_Default, #PB_Default, #PB_Default, #PB_Default)
EndProcedure

; Generic Error function.
Procedure ErrorWindowCreation()
  MessageRequester("Error", "This is fucked up, I can't create the window", 0)
  End
EndProcedure

; Animatation routine
; In:
; - fullscreen.b : create an animation in fullscreen mode or not. Two state: 0/false -> windowed mode, 1/true -> fullscreen
: Out:
;
Procedure Anim(fullscreen.b)
  ;Init subsystem and the windows with fullscreen or not
  InitSprite()
  InitKeyboard()
  If fullscreen
    If OpenScreen(#WINWIDTH, #WINHEIGHT, #BPP, #WINTITLE) = 0
      ErrorWindowCreation()
    EndIf
  Else
    If OpenWindow(1337,0,0,#WINWIDTH, #WINHEIGHT, #WINTITLE, #PB_Window_BorderLess | #PB_Window_ScreenCentered)
      If Not OpenWindowedScreen(WindowID(1337), 0, 0, #WINWIDTH, #WINHEIGHT, 1, 0, 0)
        ErrorWindowCreation()
      EndIf
    Else
       ErrorWindowCreation()
    EndIf
  EndIf

  ;Animation
  Result = CatchSprite(0, ?fontsReps, #PB_Sprite_Texture)
  Result = CatchSprite(1, ?logoReps, #PB_Sprite_Texture)
  Result = CreateImage(12, #WINWIDTH, #WINHEIGHT,#BPP)
  ClearScreen(0)
  Repeat
  xpad = 0
  ypad = 0
  StartDrawing(ImageOutput(12))
  For i = 1 To Len(s$) Step 1
    car$ = Mid(s$, i , 1)
    Select car$
      Case Chr(10)
        ypad = ypad + #SPRH
      Case Chr(13)
        xpad = 0
      Default
        getFonts(0,xpad, ypad+156, #SPRW, #SPRH, getLetterPos(car$), 0, 0, 0)
        xpad = xpad + #SPRW
    EndSelect
  Next i
  PrintTransparentSprite(1, 0, 0, 0, 0, 0)
  StopDrawing()
   
   
 ; ClearScreen(0)
  StartDrawing(ScreenOutput())
  DrawImage(ImageID(12),0,100,640,480) ; On my pb linux version this code print at x = 0, y = 0, image height = 100 but !!! On the doc, it's drawimage(Id, x, y, w, h) so x = 0, y = 100 and image height= 480 and width = 640....
  StopDrawing() ; It's really obvious !!!! :'(
      FlipBuffers()
    If fullscreen = 0
      Event = WaitWindowEvent(0)
    EndIf
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Space) Or KeyboardPushed(#PB_Key_T)
 
EndProcedure

; Init the question for fullscreen or windowed mode. After selection the button, the animation will be in a good screen mode
; In :
; - text$ : Is the message for MessageBox
; Out :
;
Procedure PrintTextWindows(text$)
  Result = MessageRequester(#WINTITLE, text$,#PB_MessageRequester_YesNoCancel)
  Select Result
    Case #PB_MessageRequester_Yes
      Anim(#True)
    Case #PB_MessageRequester_No
      Anim(#False)
    EndSelect
EndProcedure



;!!!!! Begin !!!!!
  PrintTextWindows("Credits : Jace, Padman, StormBringer !!! and you ;o)"+ Chr(10) + Chr(13) + "Do you want Fullscreen ? :)")

  End ; va!n advice
;!!!!! End !!!!!

DataSection
  fontsReps: IncludeBinary("eswatfonts.bmp")
  logoReps:  IncludeBinary("eswatlogo.bmp")
EndDataSection

; IDE Options = PureBasic 4.51 (Linux - x86)
; CursorPosition = 196
; FirstLine = 158
; Folding = -
; EnableXP



The interesting code snippet :
Code: [Select]
...
; ClearScreen(0)
  StartDrawing(ScreenOutput())
  DrawImage(ImageID(12),0,100,640,480) ; On my pb linux version this code print at x = 0, y = 0, image height = 100 but !!! On the doc, it's drawimage(Id, x, y, w, h) so x = 0, y = 100 and image height= 480 and width = 640....
  StopDrawing() ; It's really obvious !!!! :'(
      FlipBuffers()
    If fullscreen = 0
      Event = WaitWindowEvent(0)
    EndIf
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Space) Or KeyboardPushed(#PB_Key_T)
...

Do you have the same bug with pb for windows ?

With a screenshot to proof it.
« Last Edit: August 03, 2011 by maracuja »

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 977
  • Karma: 258
    • View Profile
Re: Requiring helps for purebasic.
« Reply #22 on: August 03, 2011 »
Quote
I'm back, so this code in "theory" will be work but not....

Well if you put the  PrintTransparentSprite(1, 0, 0, 0, 0, 0) after the Clearscreen(0) you'll see at least the logo:

Code: [Select]


(...)
 StartDrawing(ImageOutput(12))
  For i = 1 To Len(s$) Step 1
    car$ = Mid(s$, i , 1)
    Select car$
      Case Chr(10)
        ypad = ypad + #SPRH
      Case Chr(13)
        xpad = 0
      Default
        getFonts(0,xpad, ypad+156, #SPRW, #SPRH, getLetterPos(car$), 0, 0, 0)
        xpad = xpad + #SPRW
    EndSelect
  Next i

  StopDrawing()
     
  ClearScreen(0)
  PrintTransparentSprite(1, 0, 0, 0, 0, 0)                      <------- put it here
  StartDrawing(ScreenOutput())
(...)

For the rest (as far as I can tell after a quick look) you are mixing Sprites and Images up once again. The getfonts proc needs to be changed to use Images and these Images you can then plot on a Sprite. Jace's examples both work fine, why don't you just adapt one of it? ;)

The other problem really seems to be a Linux bug, looks ok on Windows.
Challenge Trophies Won:

Offline jace_stknights

  • Amiga 1200
  • ****
  • Posts: 399
  • Karma: 32
  • PEEK & POKE are not MOVEM!
    • View Profile
    • ST Knights WebSite
Re: Requiring helps for purebasic.
« Reply #23 on: August 04, 2011 »
I have tested your example, and it don't work for me!

And just because there are things you cannot do in purebasic, even if it's written in the help:

1- you can't sprite over a sprite !
2- you can't image over an image! (it displays at the screen)

So if you take a closer look at my examples, I'm doing this:

- image over a sprite!!! (I create an array to put the Ids)
or
- all at screen a start of frame and then grabbing all in a sprite!

And don't try to think it's nuts, just because at the end you will do it like that! Why? Just because:
1- sprites are fasters than image
2- you can create sprite3d from sprite (with #pb_sprite_texture) wich are even faster than sprite themselves! (use of the material acceleration)

I know it's a bit disturbing at start, but if you just do it like that, you will stop blasting your head!

So just use a sprite at first for the buffer, and then display image on it like I do in my example  ;D


Challenge Trophies Won: