UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on August 18, 2016, 11:03:01 AM

Title: Palette Mapped Example (16bit)
Post by: kevin on August 18, 2016, 11:03:01 AM
   Palette Mapped Example (16bit)

 This example shows the very basics of creating 16bit palette mapped image using the palette mapping library (slib).     The actual image is just a normal 16bit RGB image in FX format, so we can render to it using most draw operations.      In this case we're using Circle and CLS to fill the image with the required palette indexes.   Now since the original commands only render in RGB's,  we need to convert our palette indexes to RGB using IndexToRGB,  which just bit shifts/converts the input data into a 32bit RGB colour form.   So when that colour is  drawn to the surface, it becomes the same value.  




[pbcode]

   #include "Palettemapping"


   ; Define array we'll use for the palette  
   Dim Palette($10000)
   SetPalette Palette()
   
   
   ; set colour 620   palette index purple
   Palette(620) = rgb (255,0,255)

  ; set colour 7483 to GREEN in the palette
   Palette(7483) = rgb (0,255,0)
   
   
   ; make a image for that we'll use for palette mapped rendering
   PaletteMappedImage = NewPaletteMapImage(800,600)
   


   ; ----------------------------------
   ; Start of programs main loop
   ; ----------------------------------
   Do
   
      ; set cursor position to top left croner
         SetCursor 0,0

      ; render to the Palette mapped image
         rendertoimage PaletteMappedImage
   

            ; fill this image with colour 620 from the palette
            cls indextorgb(620)


            ; fill this circle with colour 7483 from the palette
            Circlec mousex(),mousey(), 100, true, IndextoRgb(7483)


      ; set rendering back to the screen
         rendertoscreen


      ; check if a mouse button is pressed      
      if Mousebutton()=false

            ; draw as palette mapped
            drawpalettemapimage PaletteMappedImage,0,0
            print "Rendering Palette Mapped"
            
            
      else
      
            ; draw actual RGB version of the image to the screen
            ; so we can see these they are different            
            drawimage PaletteMappedImage,0,0,false
            print "Rendering as bitmap"
      
      endif            
      
      
      
      ; flip the screens back buffers and    
      Sync
      
      ; loop until a key is pressed
   loop scancode() >0


[/pbcode]



  Related Examples

     * Palette Mapped / Raster Bar Examples (http://www.underwaredesign.com/forums/index.php?topic=4060.msg27344#msg27344)

     *  Classic Glenz Vector (http://www.underwaredesign.com/forums/index.php?topic=4060.msg27431#msg27431)

     *  Glenz Vector Cube (http://www.underwaredesign.com/forums/index.php?topic=4060.msg27432#msg27432)

     *  8bit / 16bit palette mapped strips (http://www.underwaredesign.com/forums/index.php?topic=4060.msg27473#msg27473)

     * Shadows / Recolouring (http://www.underwaredesign.com/forums/index.php?topic=4060.msg27477#msg27477)

      * Load Compressed 8bit Palette Mapped Images from Data Statements (http://www.underwaredesign.com/forums/index.php?topic=2245.msg28772#msg28772)
   
       * Vampire Demo (16bit) (http://www.underwaredesign.com/forums/index.php?topic=4356.0)