UnderwareDesign
February 23, 2018, 06:10:25 PM *
News: PlayBASIC V1.65B _Retail Upgrade_ Now Available (23rd, June, 2017)
   Home    
Pages: [1]
 
Author Topic: PlayBASIC LIVE: How to Make a 320 by 200 16 colour Palette Mapped Screen  (Read 178 times)
Member
Development Team


WWW
« on: November 22, 2017, 09:12:17 AM »



PlayBASIC LIVE:   How to Make a 320 by 200 16 colour Palette Mapped Screen  (22 Nov 2017)

   In this video we take a look at how we could use the Palette mapping library to create a classic 8 bit styled screen that's 320 by 200 pixels with only 16 colours.    Which is something like the  type of graphic hardware you'd find in that classic 8bit / 16 bit computers.  In this example the programmer can use any of the 16 colours anyway on the the screen at any time,  this was generally not the case for classic  8Bit systems, which tend to have various limitations on how many colours can appears within a bitmap,  which makes some of the old artists even more impressive. 

 Anyway, you can find the source code on our forums of course with thousands of other examples..  Have fun !

 Video:


Example Code:
PlayBASIC Code:
// Include the palette Mapping library
   #include "paletteMapping"
   

   // Define    
   Dim Palette(256)
   
   
   SetPalette(Palette())
   

   for lp =0 to 15
         palette(lp) =rndrgb()
   next

   Palette(0)  = $0000ff
   Palette(1)  = $ffffff
   


   constant ScreenWidth = 320
   constant ScreenHeight = 200

   PaletteSCreenImage=GetFreeImage()      
   CreateFXImageEx PaletteScreenImage,ScreenWidth,ScreenHeight, 16
   
   FxScreen   = newfximage(SCreenWidth,ScreenHeight)
   
   

   x1=rnd(ScreenWidth)
   y1=rnd(ScreenHeight)


do   
   rendertoimage PaletteScreenImage


   x2=rnd(ScreenWidth)
   y2=rnd(ScreenHeight)
   
   linec x1,y1,x2,y2,indextorgb(rnd(15))

   circlec mousex(),mousey(),30,true, indextorgb(CurrentColour)

   if mousebutton()=1 and ButtonDown=false
      CurrentColour = (CurrentColour+1 ) and $f      
      ButtonDown=true
   else
      ButtonDown=false
   endif


   x1=x2
   y1=y2
   
   RenderPaletteMappedScreen(PaletteScreenImage,0,0,FxScreen)

   rendertoscreen   
   
   drawrotatedimage  FxScreen,0,0,0,2,2,0,0,false
      
   drawimage PaletteScreenImage,400,0,false
   
   sync

loop spacekey()
 end
    


function RenderPaletteMappedScreen(SrcPalettedImage,Xpos,Ypos,DestImage=0)
   
   if GetImageDepth(SrcPalettedImage) = 16

      local OldSurface = getSurface()
   
      rendertoimage DestImage   
         
         lockbuffer
         local ThisRGB       = point(0,0)
         local ImagePtr    = GetImagePtr(SrcPalettedImage)
         local ImageModulo = GetImagePitch(SrcPalettedImage)
         
         local Width = GetImageWidth(SrcPalettedImage)
         
         For ylp=0 to GetImageHeight(SrcPalettedImage)-1
               DrawPaletteMappedStrip16 Xpos, Ypos+ylp, ImagePtr, Width, $000f   
               ImagePtr+=ImageModulo
         next
   
         unlockbuffer   

      rendertoimage OldSurface
   endif
EndFunction

   



Logged

Member


« Reply #1 on: January 26, 2018, 12:58:52 PM »


PlayBASIC LIVE:   How to Make a 320 by 200 16 colour Palette Mapped Screen  (22 Nov 2017)

   In this video we take a look at how we could use the Palette mapping library to create a classic 8 bit styled screen that's 320 by 200 pixels with only 16 colours.    Which is something like the  type of graphic hardware you'd find in that classic 8bit / 16 bit computers.  In this example the programmer can use any of the 16 colours anyway on the the screen at any time,  this was generally not the case for classic  8Bit systems, which tend to have various limitations on how many colours can appears within a bitmap,  which makes some of the old artists even more impressive. 

 Anyway, you can find the source code on our forums of course with thousands of other examples..  Have fun !

 Video:


Example Code:
PlayBASIC Code:
// Include the palette Mapping library
   #include "paletteMapping"
   

   // Define    
   Dim Palette(256)
   
   
   SetPalette(Palette())
   

   for lp =0 to 15
         palette(lp) =rndrgb()
   next

   Palette(0)  = $0000ff
   Palette(1)  = $ffffff
   


   constant ScreenWidth = 320
   constant ScreenHeight = 200

   PaletteSCreenImage=GetFreeImage()      
   CreateFXImageEx PaletteScreenImage,ScreenWidth,ScreenHeight, 16
   
   FxScreen   = newfximage(SCreenWidth,ScreenHeight)
   
   

   x1=rnd(ScreenWidth)
   y1=rnd(ScreenHeight)


do   
   rendertoimage PaletteScreenImage


   x2=rnd(ScreenWidth)
   y2=rnd(ScreenHeight)
   
   linec x1,y1,x2,y2,indextorgb(rnd(15))

   circlec mousex(),mousey(),30,true, indextorgb(CurrentColour)

   if mousebutton()=1 and ButtonDown=false
      CurrentColour = (CurrentColour+1 ) and $f      
      ButtonDown=true
   else
      ButtonDown=false
   endif


   x1=x2
   y1=y2
   
   RenderPaletteMappedScreen(PaletteScreenImage,0,0,FxScreen)

   rendertoscreen   
   
   drawrotatedimage  FxScreen,0,0,0,2,2,0,0,false
      
   drawimage PaletteScreenImage,400,0,false
   
   sync

loop spacekey()
 end
    


function RenderPaletteMappedScreen(SrcPalettedImage,Xpos,Ypos,DestImage=0)
   
   if GetImageDepth(SrcPalettedImage) = 16

      local OldSurface = getSurface()
   
      rendertoimage DestImage   
         
         lockbuffer
         local ThisRGB       = point(0,0)
         local ImagePtr    = GetImagePtr(SrcPalettedImage)
         local ImageModulo = GetImagePitch(SrcPalettedImage)
         
         local Width = GetImageWidth(SrcPalettedImage)
         
         For ylp=0 to GetImageHeight(SrcPalettedImage)-1
               DrawPaletteMappedStrip16 Xpos, Ypos+ylp, ImagePtr, Width, $000f   
               ImagePtr+=ImageModulo
         next
   
         unlockbuffer   

      rendertoimage OldSurface
   endif
EndFunction

   




How do i get the library and install it?
Logged

Jesus was only famous because of his dad
Member


« Reply #2 on: January 27, 2018, 01:18:41 AM »

Okay, I just jumped to code and saw library.
Watched the video absoloutly superb!

Would love to see a video of making a program thats slow say bit banging pixels on screen and the compiling and converting with the machine code tool!

Kind Regards Baggey Grin
Logged

Jesus was only famous because of his dad
Member
Development Team


WWW
« Reply #3 on: January 29, 2018, 10:59:21 AM »


Quote
Would love to see a video of making a program thats slow say bit banging pixels on screen and the compiling and converting with the machine code tool!

  Yep that's on the TO DO list..
Logged

Pages: [1]
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2009, Simple Machines LLC | Privacy Policy Valid XHTML 1.0! Valid CSS!