[Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 340
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by ar-s »

It looks awesome !!!
Thanks for sharing !
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Mijikai »

Thank you @ar-s

Update alpha 10:
  • PalleteFill() now uses a color to fill/clear the palette (for some reason it used the palette index before)
Makes much more sense now - it slipped by because i only cleared to black in my tests.

I also managed to put together some documentation, still incomplete but it covers the main interface :)
Link can be found in the first post.

Demo 7 (choppy gif preview):
Image

Code:

Code: Select all

EnableExplicit

;Demo 7 (alpha 10) - Font from image!

XIncludeFile "rpix.pbi"

UsePNGImageDecoder()

Structure DEMO_STRUCT
  *rpix.RPIX
  *surface.RPIX_SURFACE
  *region.RPIX_REGION
EndStructure

Global demo.DEMO_STRUCT

Procedure.i ImageAlign(*Image.Integer);<- rpix only accepts images that are a multiple of 2
  Protected img_w.i
  Protected img_h.i
  Protected fix_w.i
  Protected fix_h.i
  Protected fix.i
  If *Image
    If IsImage(*Image\i)
      img_w = ImageWidth(*Image\i)  
      img_h = ImageHeight(*Image\i)
      fix_w = img_w + Bool(img_w % 2 <> 0)
      fix_h = img_h + Bool(img_h % 2 <> 0)
      If fix_w = img_w And fix_h = img_h
        ProcedureReturn #True
      EndIf
      fix = CreateImage(#PB_Any,fix_w,fix_h,ImageDepth(*Image\i))
      If fix
        If StartDrawing(ImageOutput(fix))
          DrawImage(ImageID(*Image\i),0,0)
          StopDrawing()
          FreeImage(*Image\i)
          *Image\i = fix
          ProcedureReturn #True
        EndIf
        FreeImage(fix)
      EndIf
    EndIf
  EndIf
  ProcedureReturn #False
EndProcedure

Procedure.i DownloadImage();<- download the font image & create a surface from it
  Protected *buffer
  Protected load.i
  With demo
    *buffer = ReceiveHTTPMemory("https://www.spriters-resource.com/resources/sheets/57/60372.png?updated=1460962517")
    If *buffer
      load = CatchImage(#PB_Any,*buffer,MemorySize(*buffer))
      FreeMemory(*buffer)
    EndIf
    If load
      If ImageAlign(@load);<- if the image is already a multiple of 2 ImageAlign() is not needed!
        \surface = \rpix\SurfaceBitmap(ImageID(load))
      EndIf  
      FreeImage(load)
    EndIf
    ProcedureReturn \surface
  EndWith
EndProcedure

Procedure.i Main()
  Protected tick.i
  Protected fx.d
  With demo
    \rpix = rpixWindowOpen(#RPIX_WINDOW_NORMAL,960,600,320,200)
    If \rpix
      If DownloadImage()
        \region = \surface\RegionCreate(32,1,0,0,16,16);<- create a region composed of all font characters we are interested in
        If \region
          \region\FontRegister(0,"abcdefghijklmnopqrstuvwxyz.12ö_",0);<- register/map characters to ascii codes!
          Repeat
            tick + 1
            fx = Sin(tick / 4) * 2
            \region\FontSpacingSet(fx);<- change the font spacing
            \rpix\BufferFill(80);<- fill the background
            \rpix\DrawCircle(0,160,90 - fx + 8,8,-1,70);<- some shadow
            \region\DrawTextMask(0,160,90 + fx,"ö",0,1,1);<- now we can use all registered characters :)
            \region\DrawTextTint(0,160,112 + fx,"hello_world",0,70,1);<- draw a text with the new font
            \region\DrawTextMask(0,160,110 + fx,"hello_world",0,1,1)
            \rpix\BufferDrawEvent()
          Until rpixWindowExit(\rpix)
        EndIf
      EndIf
      rpixWindowClose(\rpix)
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Main()

End
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Mijikai »

Update alpha 11:
  • fixed another problem related to the cursor clipping
  • changed the behaviour of the \Buffer() functions (documentation updated)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Mijikai »

Update alpha 13:
  • SurfaceBitmap() now also fills a pallete with the colors of the source image
This is very helpful to quickly load colors along the source image or for palettes in image format.

Example:
Image

Code: Select all

EnableExplicit

UsePNGImageDecoder()

XIncludeFile "rpix.pbi"

Procedure.i Main()
  Protected *rpix.RPIX
  Protected *palette.RPIX_PALETTE
  Protected *surface.RPIX_SURFACE
  Protected image.i
  *rpix = rpixWindowOpen(#PB_Window_Normal,800,600,400,300)
  If *rpix
    image = LoadImage(#PB_Any,"car.png")
    *palette = *rpix\PaletteCreate()
    *surface = *rpix\SurfaceBitmap(ImageID(image),#Null,#Null$,*palette);<- supply the palette which is then filled :)
    *palette\Use()
    Repeat
      *rpix\BufferFill()
      *surface\Draw(0,156,45)
      *rpix\BufferDrawEvent()
    Until rpixWindowExit(*rpix)
    rpixWindowClose(*rpix)
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Mijikai »

Even thought RPIX currently does not support scaling out of the box its not difficult to implement :)

Demo:

Code: Select all

EnableExplicit

;RPIX - Example
;A way to scale a surface/sprite

;NOTE: Press [SPACE] to see the scaled surface/sprite

XIncludeFile "rpix.pbi"

Global *g.RPIX
Global *s.RPIX_SURFACE 

Procedure.i SpriteDrawScaled(X.i,Y.i,Width.i,Height.i,Center.i);<- draws surface/sprite scaled with the new Width and Height
  Protected.i px,py,pw,ph,pc,tx,ty
  Protected.f fx,fy
  *s\OutputSize(@pw,@ph)
  fx = pw / Width;<- calculate the scaling factor
  fy = ph / Height
  If Center
    X - (Width >> 1)
    Y - (Height >> 1)
  EndIf
  Width - 1
  Height - 1
  For py = 0 To Height
    For px = 0 To Width
      tx = Round(px * fx,#PB_Round_Down);<- calculate the pixel coordinares in surface/sprite space
      ty = Round(py * fy,#PB_Round_Down)
      *s\BufferGet(tx,ty,@pc);<- sample the color from the surface/sprite buffer
      *g\BufferSet(X + px,Y + py,pc);<- draw the pixel into the backbuffer
    Next
  Next
  ProcedureReturn #Null
EndProcedure

Procedure.i SpriteDrawNormalButFlipped(X.i,Y.i,Center.i);<- draws a surface/sprite
  *s\BufferFlip(#True)
  *s\Draw(#Null,X,Y,Center)
  *s\BufferFlip(#True)
  ProcedureReturn #Null
EndProcedure

Procedure.i SpriteCreate();<- create a test surface/sprite
  *s = *g\SurfaceCreate(8,8)
  If *s
    *s\BufferFill(150)
    *g\DrawBox(*s,1,1,6,3,154,#True)
    *g\DrawBox(*s,1,4,6,3,164,#True)
    *g\DrawLine(*s,0,0,1,1,10)
    *g\DrawLine(*s,7,0,6,1,11)
    *g\DrawLine(*s,7,7,6,6,12)
    *g\DrawLine(*s,0,7,1,6,14)
  EndIf
  ProcedureReturn *s
EndProcedure

Procedure.i Main()
  Protected.i toggle
  *g = rpixWindowOpen(#RPIX_WINDOW_NORMAL,512,512,64,64)
  If *g
    *g\PalettePreset(#Null,#RPIX_PALETTE_VGA)
    If SpriteCreate()
      Repeat
        *g\InputUpdate()
        If *g\InputKeyToggle(#VK_SPACE)
          toggle ! 1  
        EndIf
        *g\BufferFill(222);<- clear the background to the specified color index
        If toggle
          SpriteDrawScaled(32,32,64,64,#True);<- if toggle is #True draw the sprite scaled
        EndIf
        SpriteDrawNormalButFlipped(32,32,#True);<- draw the sprite as it is aka. with its original size (but flipped)
        *g\BufferDrawEvent()
      Until rpixWindowExit(*g)
    EndIf
    rpixWindowClose(*g)
  EndIf
EndProcedure

Main()

End
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by luis »

Pretty amazing, congrats :)
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Mijikai »

Thank you @luis :)

Update BETA 0.14:

Main changes:
- window functions are now part of the main interface *rpix\Window...()
- added a dedicated function to create a palette from an image *rpix\PaletteBitmap()
- renamed rpixWindowOpen() -> rpixWindow()
- renamed rpixInterface() -> rpixContext()

Example - a window now:

Code: Select all

EnableExplicit

XIncludeFile "rpix.pbi"

Procedure.i Main()
  Protected *rpix.RPIX
  *rpix = rpixWindow(#RPIX_WINDOW_NORMAL,800,600)
  If *rpix
    Repeat
    Until *rpix\WindowExit() 
    *rpix\WindowClose()
  EndIf
  ProcedureReturn #Null
EndProcedure

End Main()
Download:
https://www.dropbox.com/s/d79pus0a3se0s ... 4.zip?dl=0
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Kuron »

Any news to share? I am genuinely interested in seeing any progress that has been made on this.
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Mijikai »

@Kuron
Im currently busy writing the documentation which i want to finish* before the next release.
(*at least for the main interface)
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library

Post by Kuron »

Thank you for replying. I am glad to know you are still working on it, and wanted you to know there are some of us very interested in it. :mrgreen:
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

Update v.1.00 :
Here we go v.1.00, many changes and fixes later. 8)
Im still not done with the documentation but i wanted to release it anyway.
I will create a dedicated thread once the documentation is ready.

Anyway its for those who want to play around, have fun :D

Example for RPIX v.1.00:

Image

Code: Select all

EnableExplicit

XIncludeFile "rpix.pbi"

;---------------------------------------------
;VGA 32x32 PixelEditor Example for RPIX v.1.00
;---------------------------------------------
;Author: Mijikai
;Version: alpha
;---------------------------------------------

Global *rpix.RPIX
Global *background.RPIX_SURFACE
Global *drawing.RPIX_SURFACE
Global *image.RPIX_SURFACE

Procedure.i BitmapSave()
  Protected file.s
  file = SaveFileRequester("SAVE",GetCurrentDirectory(),"Bitmap (*.bmp)|*.bmp",#Null)
  If file
    If Not LCase(Right(file,4)) = ".bmp"
      file + ".bmp"
    EndIf
    If *rpix\BitmapSurface(*image,#Null,file)
      MessageRequester("Info","File saved!",#PB_MessageRequester_Info)
    Else
      MessageRequester("Info","File could not be saved!",#PB_MessageRequester_Error)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i BitmapLoad()
  Protected file.s
  Protected *load.RPIX_SURFACE
  Protected w.i
  Protected h.i
  file = OpenFileRequester("LOAD",GetCurrentDirectory(),"Bitmap (*.bmp)|*.bmp",#Null)
  If file
    *load = *rpix\SurfaceBitmap(#Null,#Null,file)
    If *load
      *load\OutputSize(@w,@h)
    EndIf
    If w = 32 And h = 32
      *load\BufferWrite(*image)
      *load\Release()
      *background\DrawRect(*drawing,0,0,0,0,192,192)
      *image\DrawUpscaleMask(*drawing,0,0,6,0)
      MessageRequester("Info","File loaded!",#PB_MessageRequester_Info)
    Else
      If *load
        *load\Release()
      EndIf
      MessageRequester("Info","File could not be loaded!",#PB_MessageRequester_Error)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i SpriteSave()
  Protected file.s
  file = SaveFileRequester("SAVE",GetCurrentDirectory(),"Sprite (*.rpix)|*.rpix",#Null)
  If file
    If Not LCase(Right(file,5)) = ".rpix"
      file + ".rpix"
    EndIf
    If *image\Save(file)
      MessageRequester("Info","File saved!",#PB_MessageRequester_Info)
    Else
      MessageRequester("Info","File could not be saved!",#PB_MessageRequester_Error)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i Main()
  Protected init.i
  Protected mx.i
  Protected my.i
  Protected x.i
  Protected y.i
  Protected index.i
  *rpix = rpixWindow(#RPIX_WINDOW_NORMAL,560,384,280,192,#True);<- open a new window with a screen with 280 x 192 pixels and 60 fps
  If *rpix;<- was the screen created
    *rpix\WindowTitle("VGA 32x32 PixelEditor");<- change the window title
    *rpix\PalettePreset(#Null,#RPIX_PALETTE_VGA);<- load the vga palette from the presets
    *rpix\FontSpaceSet(-1);<- set the font spacing to -1 so the font chars are drawn closer to each other (internal "debug" font)
    *background = *rpix\SurfaceLoad(?vga_ie_background);<- load the background sprite (surface) from memory (datasection)
    *image = *rpix\SurfaceCreate(32,32);<- create a empty sprite (surface) that will be used for loading/saving (drawing area @ 1:1 scale)
    If *background And *image;<- test if the sprites (surfaces) could be created
      *drawing = *background\Duplicate();<- create another staging sprite (surface) it will hold the visual representation of the drawing area
      If *drawing;<- was it created !?
        index = 7;<- set the index (palette) to 7 (the drawing color used by the editor)
        Repeat;<- start the render loop
          *drawing\Draw(0,0,0);<- draw the editors background & drawing area
          If init > 250;<- if the editor is past the loading splash screen
            *rpix\DrawBox(*drawing,258,110,35,6,index,#True,#True);<- draw a box with the current selected color next to the COLOR text
            If *rpix\InputUpdate();<- query the user input
              *rpix\InputMouseTranslate(@mx,@my);<- query and translate the mouse position into screen coordinates
              If *rpix\InputKeyToggle(#VK_F2);<- if the F1 key was hit swith from window to screen mode or vice versa
                *rpix\ScreenToggle();<- switch screen modes
              EndIf
              If *rpix\InputKeyToggle(#VK_F1);<- if the S key is hit save the current drawing as rpix sprite
                SpriteSave();<- save a sprite
              EndIf
              If *rpix\TestPointEx(mx,my,236,60,80,80,#True);<- if the mouse is within the editors palette allow it to pick a color
                If *rpix\InputKeyToggle(#VK_LBUTTON);<- if the left mouse button is clicked select a color
                  *drawing\BufferGet(mx,my,@index);<- override the index that holds the drawing color of the editor
                EndIf
              ElseIf *rpix\TestPointEx(mx,my,236,128,80,16,#True);<- if the mouse is within the clear button allow interaction
                *rpix\DrawBox(0,236,128,80,16,22,#False,#True);<- highlight the button
                *rpix\DrawText(0,236,124,"CLEAR",28,#True);<- highlight the text
                If *rpix\InputKeyToggle(#VK_LBUTTON);<- if the left mouse button is pressed clear the drawing area
                  *image\BufferFill(#Null);<- clear sprite that holds the 1:1 representation of the drawing area
                  *background\DrawRect(*drawing,0,0,0,0,192,192);use the background sprite to redraw the drawing area sprite
                EndIf
              ElseIf *rpix\TestPointEx(mx,my,236,146,80,16,#True);<- if the mouse is within the save button allow interaction
                *rpix\DrawBox(0,236,146,80,16,22,#False,#True);<- highlight the button
                *rpix\DrawText(0,236,142,"SAVE",28,#True);<- highlight the text
                If *rpix\InputKeyToggle(#VK_LBUTTON);<- if the left mouse button is pressed call the save function
                  BitmapSave();<- call save function  
                EndIf
              ElseIf *rpix\TestPointEx(mx,my,236,164,80,16,#True);<- if the mouse is within the load button allow interaction
                *rpix\DrawBox(0,236,164,80,16,22,#False,#True);<- highlight the button
                *rpix\DrawText(0,236,160,"LOAD",28,#True);<- highlight the text
                If *rpix\InputKeyToggle(#VK_LBUTTON);<- if the left mouse button is pressed call the load function
                  BitmapLoad();<- call load function
                  index = 7;<- reset the drawing color
                EndIf
              ElseIf *rpix\TestPoint(mx,my,0,0,192,192);<- if the mouse is within the drawing area allow interaction
                x = mx / 6
                y = my / 6
                mx = x * 6
                my = y * 6
                If *rpix\InputKeyDown(#VK_LBUTTON);<- if the key is pressed allow interaction
                  If index <> 0 And index <> 16 And index < 248;<- if the color isnt black use the index selected
                    *image\BufferSet(x,y,index);<- draw into the 1:1 representation
                    *rpix\DrawBox(*drawing,mx,my,6,6,index,#True);<- draw into the drawing area
                  Else
                    *image\BufferSet(x,y,0);<- draw the black (transparent) color into the 1:1 representation
                    *background\DrawRect(*drawing,mx,my,mx,my,6,6);<- draw into the drawing area
                  EndIf
                ElseIf *rpix\InputKeyDown(#VK_RBUTTON);<- if the right button is pressed erase a pixel of the drawing
                  *image\BufferSet(x,y,#Null);<- erase a pixe in the 1:1 representation
                  *background\DrawRect(*drawing,mx,my,mx,my,6,6);<- erase a pixel in the drawing area
                ElseIf *rpix\InputKeyToggle(#VK_MBUTTON);<- if the middle mouse button is pressed use the fill function
                  If index <> 0 And index <> 16 And index < 248;<- again check for the blacks
                    *rpix\DrawFill(*image,x,y,index);<- draw into the 1:1 representation
                  Else
                    *rpix\DrawFill(*image,x,y,0);<- draw into the 1:1 representation
                  EndIf
                  *background\DrawRect(*drawing,0,0,0,0,192,192);<- clear the drawing area
                  *image\DrawUpscaleMask(*drawing,0,0,6,0);<- restore it with the new 1:1 representation
                EndIf
              EndIf
            EndIf
          Else;<- display the loading splash screen
            *background\Draw(0,0,0,0);<- draw the background
            *rpix\DrawBox(0,140,96,200,140,18,#True,#True);<- draw some boxes & text + animation
            *rpix\DrawBox(0,140,96,200,140,22,#False,#True)
            *rpix\DrawText(0,140,40,"MOUSE",70,#True)
            *rpix\DrawText(0,140,50,"DRAW   { LEFT }",80,#True)
            *rpix\DrawText(0,140,60,"ERASE { RIGHT }",80,#True)
            *rpix\DrawText(0,140,70,"FILL { MIDDLE }",80,#True)
            *rpix\DrawText(0,140,90,"KEYBOARD",70,#True)
            *rpix\DrawText(0,140,100,"EXPORT SRPITE { F1 }",80,#True)
            *rpix\DrawText(0,140,110,"FULLSCREEN    { F2 }",80,#True)
            *rpix\DrawBox(0,140,140,150,30,222,#True,#True)
            *rpix\DrawBox(0,140,140,150,30,22,#False,#True)
            *rpix\FontSpaceSet(Sin(init * 0.2) * 4.0)
            *rpix\DrawText(0,140 - Cos(init * 0.15) * 3.0,135 - Sin(init * 0.3) * 4.0,"HAVE FUN :)",150,#True)
            *rpix\DrawText(0,140 + Cos(init * 0.15) * 3.0,135 + Sin(init * 0.3) * 4.0,"HAVE FUN :)",160,#True)
            *rpix\FontSpaceSet(-1)
            init + 1
          EndIf
          *rpix\BufferDrawEvent();<- render everything
        Until *rpix\WindowExit() Or *rpix\InputKeyToggle(#VK_ESCAPE);<- if the window is closed or the ESC key is pressed end the program
      EndIf
    EndIf
    *rpix\WindowClose();<- release all surfaces and close the window
  EndIf
  ProcedureReturn #Null
EndProcedure

End Main()

DataSection
  vga_ie_background:
  Data.w $07072,$07869,$00118,$00000,$000C0,$00000,$009B0,$00000,$00000,$00000,$07A31,$0626C,$00000,$00000,$0D200,$00000,$00000,$00000,$00000,$00008,$00000,$00000,$0BE12,$05FAB,$00008,$00000,$0D617,$01405,$05E2A,$0A900,$0FCFA,$0175F,$03162,$0C500,$02104,$00F16,$01106,$042C5,$00D00,$00842
  Data.w $00906,$01C00,$00D0B,$00512,$03C62,$00706,$0A10A,$0745C,$0047B,$077F0,$00205,$0C5C3,$00418,$01412,$02118,$00014,$01706,$00B1C,$00D00,$02850,$01706,$0B10D,$01858,$00605,$0C21D,$00014,$07D24,$01817,$0B843,$00DF2,$03C18,$00886,$0141B,$00663,$03808,$02C78,$0061D,$08814,$00B85,$0745D
  Data.w $0045F,$03162,$0C505,$010D6,$0FA94,$012DF,$01C0B,$000C6,$0140D,$02C38,$01614,$03112,$0189E,$0040F,$06216,$00B14,$0217D,$0045D,$0D081,$0C505,$01814,$09AC6,$0DD1A,$02A10,$0E1DF,$08C0B,$0408D,$01500,$02242,$00514,$00C62,$00608,$05704,$000C7,$06932,$01417,$04854,$00514,$0161A,$0D842
  Data.w $00004,$03061,$00608,$01812,$01222,$04218,$03A29,$0C216,$006E1,$0FF14,$01017,$08842,$0C500,$049D3,$0D984,$0851A,$02158,$00004,$08C42,$00608,$0211C,$0001E,$01106,$00A10,$00600,$0D513,$009A1,$0F12B,$0552F,$000F8,$0F552,$0F817,$0EABF,$00042,$055C5,$00087,$0C495,$01D2F,$07D08,$08400
  Data.w $05343,$0635C,$02EFE,$00404,$00505,$01414,$00108,$01041,$00200,$00300,$00400,$00410,$00500,$00600,$00400,$00741,$00800,$00900,$01041,$00A00,$00B00,$00C00,$00410,$00D00,$00E00,$01400,$00F42,$05300,$02FEB,$05554,$00517,$0F2BF,$05D17,$000F8,$0F287,$05317,$0285D,$0047B,$0FC02,$01405
  Data.w $01214,$04810,$00008,$00011,$01228,$05813,$00084,$0146C,$00815,$00082,$00016,$04217,$00045,$01815,$02019,$00008,$0001A,$0001B,$0081C,$00082,$0001D,$00B1E,$00021,$0001F,$0BE53,$05D10,$07D04,$005E8,$07FCA,$0E017,$000FF,$04114,$01410,$02012,$02100,$02200,$00410,$02300,$02400,$00400
  Data.w $02541,$02600,$02700,$01041,$02800,$02900,$02A00,$00410,$02B00,$02C00,$00400,$02D41,$02E00,$02F00,$0216A,$05300,$0DD75,$00417,$00ABE,$04805,$017AB,$08230,$00020,$00031,$00032,$02033,$00008,$00034,$00035,$00836,$00082,$00037,$08238,$00020,$00039,$0003A,$0203B,$00008,$0003C,$0003D
  Data.w $0103E,$00082,$0003F,$0FC53,$0F2BF,$0005D,$02817,$07497,$0FC7B,$0045D,$03BAE,$08205,$017B4,$00040,$02041,$00008,$00042,$00043,$00844,$00082,$00045,$08246,$00020,$00047,$00048,$02049,$00008,$0004A,$0004B,$0084C,$00082,$0004D,$00B4E,$00021,$0004F,$0BE53,$05D10,$05D04,$005E8,$0F2BF
  Data.w $05D17,$000F8,$0F297,$07417,$0285D,$0047B,$0FC2A,$0B405,$017FA,$00850,$00082,$00051,$08252,$00020,$00053,$00054,$02055,$00008,$00056,$00057,$00858,$00082,$00059,$0825A,$00020,$0005B,$0005C,$0215D,$00008,$0005E,$0005F,$00B10,$05D53,$0E804,$07FBE,$0055F,$02BFF,$0DF17,$00085,$02972
  Data.w $07417,$0DF7B,$00485,$0C2AF,$02005,$017AD,$00060,$00861,$00082,$00062,$08263,$00020,$00064,$00065,$02066,$00008,$00067,$00068,$00869,$00082,$0006A,$0826B,$00020,$0006C,$0006D,$0426E,$00008,$0006F,$02F53,$05DC4,$01704,$005BA,$055F2,$0F817,$0F2BF,$0005D,$02817,$07497,$0FC7B,$0045D
  Data.w $00208,$01405,$01214,$00070,$08271,$00020,$00072,$00073,$02074,$00008,$00075,$00076,$00877,$00082,$00078,$08279,$00020,$0007A,$0007B,$0207C,$00008,$0007D,$0007E,$02C7F,$00084,$0FB53,$05D42,$0F504,$005A1,$0FF2B,$08017,$000FF,$01414,$00412,$08041,$08100,$08200,$01041,$08300,$08400
  Data.w $08500,$00410,$08600,$08700,$00400,$08841,$08900,$08A00,$01041,$08B00,$08C00,$08D00,$00410,$08E00,$08F00,$0A800,$05385,$07475,$0045F,$02AFA,$02005,$017AD,$00090,$00891,$00082,$00092,$08293,$00020,$00094,$00095,$02096,$00008,$00097,$00098,$00899,$00082,$0009A,$0829B,$00020,$0009C
  Data.w $0009D,$0429E,$00008,$0009F,$0F153,$000FF,$077CA,$0A117,$0745C,$0047B,$077F0,$0BA05,$008EE,$017D2,$000A0,$082A1,$00020,$000A2,$000A3,$020A4,$00008,$000A5,$000A6,$008A7,$00082,$000A8,$082A9,$00020,$000AA,$000AB,$020AC,$00008,$000AD,$000AE,$02CAF,$00084,$0FB53,$05D42,$07704,$005A1
  Data.w $0CAFF,$07717,$000E1,$0CA5C,$07417,$0A177,$0047B,$0F0AB,$0D205,$017EA,$020B0,$00008,$000B1,$000B2,$008B3,$00082,$000B4,$082B5,$00020,$000B6,$000B7,$020B8,$00008,$000B9,$000BA,$008BB,$00082,$000BC,$084BD,$00020,$000BE,$000BF,$02C42,$05D53,$0A104,$005FB,$07DFC,$0AFFE,$07C17,$00017
  Data.w $0A5CA,$07417,$07F7B,$00417,$00ABE,$08205,$017B4,$000C0,$020C1,$00008,$000C2,$000C3,$008C4,$00082,$000C5,$082C6,$00020,$000C7,$000C8,$020C9,$00008,$000CA,$000CB,$008CC,$00082,$000CD,$00BCE,$00021,$000CF,$0BE53,$05D10,$05D04,$005E8,$057CA,$0E117,$000FF,$077CA,$0A117,$0745C,$0047B
  Data.w $077F0,$02005,$01408,$01214,$000D0,$000D1,$008D2,$00082,$000D3,$082D4,$00020,$000D5,$000D6,$020D7,$00008,$000D8,$000D9,$008DA,$00082,$000DB,$082DC,$00020,$000DD,$000DE,$0B1DF,$00010,$05D53,$00BEE,$0D704,$00587,$0FCAF,$00117,$000FE,$01414,$0E012,$00410,$0E100,$0E200,$00400,$0E341
  Data.w $0E400,$0E500,$01041,$0E600,$0E700,$0E800,$00410,$0E900,$0EA00,$00400,$0EB41,$0EC00,$0ED00,$01042,$0EE00,$0EF00,$0A100,$05316,$00475,$07DD0,$0EA05,$082AB,$017B4,$000F0,$020F1,$00008,$000F2,$000F3,$008F4,$00082,$000F5,$082F6,$00020,$000F7,$000F8,$020F9,$00008,$000FA,$000FB,$008FC
  Data.w $00082,$000FD,$00BFE,$00021,$000FF,$0C553,$000FF,$0DF29,$08517,$07472,$0047B,$0DFC3,$0EB05,$0FEBA,$01755,$0210E,$05300,$0BB5C,$06310,$04704,$005F8,$054BA,$02BA7,$000A1,$0841D,$000FE,$02EA8,$0F5C5,$00055,$0121C,$05C2F,$02177,$00463,$0F085,$0C505,$0D50F,$0E500,$017BF,$06CA1,$00669
  Data.w $00858,$00009,$0310D,$00084,$0000E,$00FF1,$0000C,$00870,$05C26,$0DF63,$00485,$0C214,$0EC05,$0DDE9,$098F5,$041BF,$0EB06,$085A6,$0AA78,$0000D,$00843,$01426,$06A04,$000EC,$0E117,$000FF,$00A4B,$009C8,$03118,$006C4,$00408,$0B77B,$0A1ED,$00B10,$02F00,$0F435,$01700,$02E50,$07B74,$0F804
  Data.w $095BB,$00542,$002C8,$08FD4,$01706,$0218A,$00A00,$04300,$02F1F,$0B500,$017AF,$066FD,$0FC40,$0174D,$02A20,$00A86,$04300,$0091D,$0B500,$017AE,$046B8,$0FE2B,$0064D,$08868,$00DA1,$0C71F,$02543,$00800,$058EB,$06600,$017A9,$0442C,$006E8,$08826,$005A1,$0C71F,$00442,$02F00,$078EB,$05700
  Data.w $017AD,$0E227,$04300,$0F8AE,$07D00,$026C5,$0E217,$0EC00,$0543E,$02500,$02FFF,$0762A,$0A900,$0FCFA,$0175F,$02EAC,$05C00,$0C462,$07452,$0A177,$0047B,$0F084,$0C405,$0ABA8,$0AAE1,$00043,$0544E,$017EE,$0CE10,$01C2A,$08E0D,$00E87,$08805,$0181F,$0D600,$01877,$0A8ED,$0A917,$06FFC,$0678A
  Data.w $00DB1,$06A3B,$0AABE,$0CA50,$09518,$00010,$0374E,$0FF42,$0FC00,$0C410,$0A7CD,$00052,$04210,$0D5FF,$0220D,$02A84,$0D00D,$002AA,$05839,$00B85,$0A800,$027C5,$07475,$0045F,$0210F,$0C405,$0ABCD,$000C6,$03502,$00619,$01020,$02842,$00017,$04317,$000AC,$0E54E,$017BF,$035A1,$00C0B,$050C4
  Data.w $00006,$02855,$0100D,$08877,$04E00,$0D6B3,$07C17,$0AFB4,$042C7,$02189,$0480D,$025D4,$0AC2F,$01F42,$0BE24,$00043,$04E4E,$017E5,$01262,$006A1,$0BC1F,$00014,$0880C,$00657,$0DE00,$04E77,$0BBB1,$00017,$00897,$05C4E,$0FD08,$0BA00,$0C442,$02ACD,$00084,$0894E,$02FFA,$00E10,$0635C,$0F804
  Data.w $015BB,$00542,$0CDC4,$0D421,$04E00,$0D5D2,$0B117,$000AF,$08870,$05C52,$0DF63,$00485,$0C257,$0E105,$0542A,$09500,$017FA,$0FFC2,$0C600,$0C4EA,$025CA,$07452,$07F7B,$00417,$0084A,$0C405,$084E1,$000BA,$03AAF,$0324E,$017E5,$0D62E,$09FCE,$02108,$00727,$00800,$00B5D,$0F600,$01A77,$0A8ED
  Data.w $09E17,$051DA,$021A5,$01216,$00B0D,$07421,$04E00,$02BFE,$02139,$00084,$0CDC4,$07422,$0A100,$05DE4,$0250B,$045C8,$0A85D,$00643,$0BF13,$00043,$0511C,$02FB2,$07254,$00B5D,$07685,$02CA5,$01DA1,$01BAC,$07621,$04E00,$0DFDA,$0AA17,$019C5,$04709,$07C2F,$053B9,$0165E,$01442,$0032F,$0217D
  Data.w $0045D,$0D084,$0C405,$02E84,$000CD,$04B50,$00928,$00804,$05B99,$08805,$0155F,$0FC00,$01A77,$0A8D2,$04717,$0080C,$004A1,$0EC0C,$00562,$0BF15,$00043,$0D54E,$017F5,$08844,$04E00,$0E851,$015BF,$00042,$0CDC4,$0D421,$04E00,$057D4,$04870,$05C2F,$0DF63,$00485,$0C210,$0C405,$0A1CD,$000AE
  Data.w $00EAE,$07D4E,$01795,$08C43,$05200,$02E5C,$06384,$01204,$005FE,$0A1E1,$000BA,$057D4,$0AFFE,$05617,$00017,$0312E,$052C4,$0BB74,$07B50,$04204,$005F8,$0D4C4,$0E155,$021D5,$04E00,$07DAE,$0C817,$0191E,$01735,$00642,$00D05,$0C21D,$01B00,$0FF2A,$05117,$01D2A,$0DBC4,$006A1,$02857,$01805
  Data.w $0884A,$04E00,$0A13A,$000FF,$00857,$0CDC4,$08E50,$01700,$0D706,$0868B,$00857,$01806,$0887D,$04E00,$07648,$0552F,$0064A,$04810,$075CB,$02117,$00016,$0180D,$05E21,$04E00,$0DFDA,$0B417,$09AE3,$03CED,$0B606,$0933A,$00836,$0A55D,$0FC00,$04E77,$0B747,$06917,$06A18,$005B0,$02E11,$00CC6
  Data.w $03B0A,$00084,$05D4E,$017FF,$05884,$04E00,$04BFE,$02166,$00084,$0CDC4,$05D42,$07D00,$04E15,$04487,$05C2F,$0085D,$00463,$0FC21,$0C405,$00AEA,$0EACD,$00010,$0574E,$017E9,$0D8C4,$05200,$03842,$0635C,$0E104,$005EF,$02BAA,$07DE1,$00015,$04AFF,$00B17,$000E1,$015C5,$000AA,$07D44,$0082F
  Data.w $05C87,$0FC63,$0045D,$02175,$0C505,$043AA,$04700,$017AE,$01612,$00C23,$00004,$09E12,$00FAF,$02B08,$00D0F,$0AC12,$00742,$0BF0D,$0004E,$043D1,$000E8,$0C2C5,$000A1,$00CF4,$00086,$01208,$01D16,$00643,$00408,$00876,$01806,$03EAA,$02D00,$02F26,$01908,$00243,$00408,$01431,$01627,$00414
  Data.w $0F0FA,$06200,$017B9,$00A00,$00FC5,$0A10D,$01D1E,$0181E,$0D8EE,$04200,$017B9,$018F5,$0F8C2,$00416,$02109,$006C4,$00508,$042C6,$01406,$03E1D,$00004,$0D7AA,$03117,$01056,$0F606,$0A863,$00029,$0B10D,$00F10,$00604,$00EC7,$00011,$0774A,$08417,$000AA,$0EBFE,$02ED1,$00084,$055C5,$000A8
  Data.w $0F512,$0212F,$05C1C,$00463,$077F0,$0D505,$0C585,$00EEA,$00000,$017FD
EndDataSection
Download v.1.00:
https://www.dropbox.com/scl/fi/cvar90dy ... vmk3q&dl=0
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Kuron »

Wow! Happy Thanksgiving! Normally do not get presents on Thanksgiving, but this is one heck of an awesome present! Thank You!
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
idle
Always Here
Always Here
Posts: 5038
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by idle »

really great project
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

Thanks :)

Update v.1.01:
- Fixed a bug in RPIX\PaletteBitmap()
- Added a new function RPIX\SurfacePalette(), see Example

Example:

Image

Code:

Code: Select all


EnableExplicit

;Example RPIX v.1.01

UsePNGImageDecoder()

XIncludeFile "rpix.pbi"

Procedure.i Spritesheet(Url.s);<- download spritesheet to memory
  Protected *buffer
  Protected image.i
  *buffer = ReceiveHTTPMemory(Url)
  If *buffer
    image = CatchImage(#PB_Any,*buffer,MemorySize(*buffer))
    FreeMemory(*buffer)
  EndIf
  ProcedureReturn image
EndProcedure

Procedure.i Main()
  Protected image.i
  Protected *rpix.RPIX
  Protected *sprite.RPIX_SURFACE
  Protected *tile.RPIX_REGION
  Protected *animation.RPIX_ANIMATION
  Protected mx.i
  Protected my.i
  Protected flip.i
  If rpixVersion() = #RPIX_VERSION
    image = Spritesheet("https://www.spriters-resource.com/resources/sheets/207/210365.png?updated=1700347587")
    ;Spritesheet by DP from Tecmo World Wrestling / Gekitou Pro Wrestling!! Toukon Densetsu
    If image
      *rpix = rpixWindow(#RPIX_WINDOW_NORMAL,256,256,128,128,#True)
      If *rpix
        *sprite = *rpix\SurfacePalette(ImageID(image));<- create a surface and palette from the image
        *tile = *sprite\RegionCreate(4,1,0,0,64,64);<- register tiles for the animation
        *animation = *rpix\AnimationCreate(0,3,13);<- create a animation loop
        *rpix\PaletteSet(1,$FAFAFA);<- replace the color at palette index 1 with a new one
        Repeat
          *rpix\InputUpdate();<- handle user input
          *rpix\InputMouseTranslate(@mx,@my);<- get screen coordinates for the mouse
          *rpix\BufferFill(2);<- fill the background with the second color in the palette
          If mx > 64 And flip = 0;<- if the mouse is at the right side of the screen center flip the sprite
            *sprite\BufferFlip()
            flip = 1
          ElseIf mx < 64 And flip = 1;<- if the mouse is at the left side of the screen center flip it back (so the sprite faces the mouse)
            *sprite\BufferFlip()
            flip = 0  
          EndIf
          *sprite\BufferFlip(#True);<- flip the sprite vertically to draw the shadow
          *tile\DrawTint(#Null,*animation,0,62,112,1,6,#True);<- draw a shadow by tinting
          *sprite\BufferFlip(#True);<- flip the sprite back
          *tile\Draw(#Null,*animation,0,64,48,#True);<- draw the weightlifter
          *rpix\DrawText(#Null,64,6,"RPIX v.1.01",1,#True);<- draw the text
          *rpix\BufferDrawEvent();<- render everything
          *rpix\AnimationUpdate();<- update all animations
        Until *rpix\WindowExit()
        *rpix\WindowClose()
      EndIf
      FreeImage(image)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

End Main()

Download:
https://www.dropbox.com/scl/fi/gnd8j5ae ... 9uxch&dl=0
threedslider
User
User
Posts: 87
Joined: Sat Feb 12, 2022 7:15 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by threedslider »

Hello Mijikai,

It is awesome your lib ! :shock: Thank you for sharing :mrgreen:

Can you provide an example of 2D game as 2D platform, please ? I want to make a 2D game platform ^^

Good job and keep it up bro !
Post Reply