In the Project > Options dialog: What does MULTISAMPLE do?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu// --------------------------------- //
// Project: mem-paint-test
// --------------------------------- //
SETCURRENTDIR("Media")
LOCAL PX1%[], PX2%[]
LOCAL x,y,r,c,i,mx,my,mbl,mbr,rr,cc
LOCAL cr,cg,cb,ca
LOCAL argb%
CREATESCREEN 1,1,640,480
CREATESCREEN 2,2,40,40
CREATESCREEN 3,3,640,480
LOADSPRITE "catndog1.png",1
LOADSPRITE "ball.png",2
WHILE TRUE
//get mouse state
MOUSESTATE mx,my,mbl,mbr
//reset image - should build load safety timer here.. but its a test anyway.
IF mbr = 1 THEN LOADSPRITE "catndog1.png",1
//check that the mouse right and bottom are on the screen
//.....else the arrays fall over
IF mx+39 < 640 AND my+39 < 480
//get the background
SPRITE2MEM (PX1[],1)
//get paintbrush
SPRITE2MEM (PX2[],2)
//paste brush onto background
IF mbl = 1
rr = -1
FOR r = my TO my + 39 //for each row
rr = rr + 1
cc = -1
FOR c = mx TO mx + 39 //for each column
cc = cc + 1
argb = PX2[cc+rr*40]
cr = bAND(argb, 0xff)
cg = bAND(ASR(argb,8), 0xff)
cb = bAND(ASR(argb,16), 0xff)
ca = bAND(ASR(argb,24), 0xff)
IF ca <> 0
PX1[c+r*640] = argb
ENDIF
NEXT
NEXT
MEM2SPRITE (PX1[],1,640,480)
ENDIF
ENDIF //mouse in screen
//START DRAWING from here
USESCREEN -1
//dump background
DRAWSPRITE 1,0,0
//display paintbrush
DRAWSPRITE 2,mx,my
PRINT "Right Mouse button to reset", 5,450
SHOWSCREEN
WEND
// --------------------------------- //
// Project: sprite2mem-tes-13
// --------------------------------- //
SETCURRENTDIR("Media")
LOCAL PX1%[]
LOCAL argb%
LOCAL r,y
CREATESCREEN 1,1,320,240
CREATESCREEN 2,2,320,240
CREATESCREEN 3,3,50,50
USESCREEN 3
DRAWRECT 0,0,49,49,RGB(255,0,0)
USESCREEN -1
LOADSPRITE "dogncat1.png",1
SPRITE2MEM(PX1[],1)
MEM2SPRITE(PX1[], 2, 320, 240)
// Create a new screen and sprite to use as an intemediary step to publish
CREATESCREEN 4,4,320,240
USESCREEN 4
DRAWSPRITE 2,0,0
DRAWSPRITE 3,200,100
PRINT "HI",5,5
USESCREEN -1
DRAWSPRITE 4,0,0
SHOWSCREEN
MOUSEWAIT
// --------------------------------- //
// Project: sprite2mem-test-12
// --------------------------------- //
SETCURRENTDIR("Media")
LOCAL PX1%[]
LOCAL argb%
CREATESCREEN 1,1,320,240
CREATESCREEN 2,2,320,240
CREATESCREEN 3,3,50,50
USESCREEN 3
DRAWRECT 0,0,49,49,RGB(50,100,150)
USESCREEN -1
LOADSPRITE "dogncat1.png",1
SPRITE2MEM(PX1[],1)
MEM2SPRITE(PX1[], 2, 320, 240) // <----------comment out this line and the rest works fine
USESCREEN 2
DRAWSPRITE 3,200,100
PRINT "HI",5,5
USESCREEN -1
DRAWSPRITE 2,0,0
SHOWSCREEN
MOUSEWAIT
// --------------------------------- //
// Project: mem2mem-paint-test
// --------------------------------- //
//we define our variables here
GLOBAL x,y,i,r,i, mx,my,mlb,mrb,c,cc,rr
GLOBAL brush%[], bground%[], dirty%[]
//we start with a white image to paint on - we stick to 640x480 with this test
CREATESCREEN 30, 99, 640, 480 //screen 30, sprite 99, our work area
//we now use our own screen to make our work area white
USESCREEN 30
DRAWRECT 0,0,640,480, RGB(255,255,255)
//we set up a new screen for a paintbrush image
CREATESCREEN 31, 100, 20, 20 //screen 31, sprite 100, brush size 20x20
//we switch to our paintbrush screen to create the brush
USESCREEN 31
//we use math to draw in circles
FOR r = 1 TO 10 //for radius 1 to 10. Half width of our brush = radius
FOR i = 0 TO 360 //all around the compas
x = SIN(i)*r //1st part of a circle formula
y = COS(i)*r //2nd part of a circle formula
SETPIXEL x+10,y+10,RGB(100,100,100) //0,0 is top left corner, so we offset drawing to middle of image
NEXT
NEXT
//our main game loop
WHILE TRUE
//we get the mouse state
MOUSESTATE mx,my,mlb,mrb
//if the left button is down, we MEM our brush onto the canvas
IF mlb =1 THEN drawBrush()
//we ensure that all final drawings go to the real screen
USESCREEN -1
//we draw our work area sprite onto the real screen
DRAWSPRITE 99, 0, 0
//use the brush as a mouse pointer
DRAWSPRITE 100,mx,my
SHOWSCREEN
WEND
FUNCTION drawBrush: //we could use parameter, but for this test we use globals
LOCAL x = mx-9 //mouse x less half the brush width + center pixel
LOCAL y = my-9 //mouse y less half the brush height + center pixel
LOCAL w = x+19 //width of the brush less 1
LOCAL h = y+19 //height of the brush less 1
LOCAL r%,g%,b%,a%
LOCAL BGabgr% //Background alpha, red, green, blue . .that's why it has a funny name
LOCAL DIRTYabgr%, BRUSHabgr%
LOCAL rr,yy
//grab the background work area
SPRITE2MEM(bground%[], 99)
//grab the brush
SPRITE2MEM(brush%[], 100)
//build the dirty rectangle
rr = -1 //inner rows
cc = -1 //inner columns
FOR r = y TO h //for each row
rr = rr + 1 //for each inner row
cc = -1 //reset inner column for new row
FOR c = x TO w //for each column
cc = cc + 1 //for each inner column
BGabgr% = bground%[c + r*20] //get a piece of our drawing buffer
DIRTYabgr% = BGabgr% //get the buffer into the dirty rectangle
BRUSHabgr% = brush%[cc + rr*20] //get the brush
BGabgr% = bOR(DIRTYabgr%,BRUSHabgr%) //add the brush to the diry rectangle
bground%[c + r*20] = BGabgr% //rebuild background from the rectangle
NEXT
NEXT
//Replace background with changes
MEM2SPRITE(bground%[], 99, 640, 480)
ENDFUNCTION
// --------------------------------- //
// Project: spritememToy
// --------------------------------- //
LOCAL pxl%[]
LOCAL res
LOCAL w
LOCAL h
LOCAL x
LOCAL y
LOCAL sw
LOCAL sh
LOCAL barrel%
LOCAL i
LOCAL offs1, offs2
LOADSPRITE "prettyImage.png",0
GETSPRITESIZE 0,w,h
GETSCREENSIZE sw,sh
res = SPRITE2MEM(pxl%[], 0)
WHILE 1
FOR y = 0 TO h-1
FOR i = 0 TO w-1
offs1 = (w/2 + i) + (y*h)
offs2 = (w/2 + i+1) +(y*h)
barrel% = pxl%[offs1]
pxl%[offs1] = pxl%[offs2]
pxl%[offs2] = barrel%
NEXT
MEM2SPRITE (pxl%[], 0, w, h)
NEXT
DRAWSPRITE 0, sw/2-w/2, sh/2-h/2
PRINT w+" "+h, 10,10
SHOWSCREEN
WEND
TYPE _PRINTX
chr []
fontID
base
border = 2 //font border if used
fw = 64 + self.border //font width
fh = 72 + self.border //font height
count = 15
FUNCTION Init: font$
LOCAL i, j, c=-1, x,y
self.fontID = RND(1000)+1000
self.base = RND(10000)+2000
LOADSPRITE font$, self.fontID
FOR j = 0 TO 15 //change this to 31 to include high ascii values
FOR i = 0 TO 15
c = c + 1
x = i * self.fw
y = j * self.fh
CLEARSCREEN
DRAWSPRITE self.fontID, -x,-y
GRABSPRITE self.base + c, 0,0, self.fw, self.fh
DIMPUSH self.chr[], self.base + c
NEXT
NEXT
CLEARSCREEN
ENDFUNCTION
FUNCTION _print: text$, x, y, scale#
LOCAL i,c, s$
FOR i = 0 TO LEN(text$)-1
s$ = MID$(text$,i,1)
c = ASC(s$)
ZOOMSPRITE self.chr[c], x + (i * self.fw *scale#), y, scale#, scale#
NEXT
ENDFUNCTION
ENDTYPE
LOCAL font1 AS _PRINTX //define your own font object
font1.Init("arial72.png") //initialize the font here
font1._print ("AbCdEfG 123", 0, 0, 0.2)
font1._print ("Hello world", 0, 20, 0.2)
font1._print ("!@#$%^&*()_+", 0, 40, 0.3)
font1._print ("Is it a bird, is it a plane? No it's Super-GLBasic", 0 ,60, 0.18)
font1._print ("Eat your food to grow", 0, 80, 0.4)
font1._print ("even bigger", 0, 110, 0.6)
font1._print ("and bigger", 0, 140, 0.8)
font1._print ("Yum !", 30, 200, 1.5)
font1._print ("...oooOOOoooooo...", 20, 300, 0.5)
SHOWSCREEN
MOUSEWAIT
FOR i = 0 TO 45
PRINT CHR$(i), 10,i*10
NEXT
SHOWSCREEN
MOUSEWAIT