Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using LINE or CIRCLE on a GET/PUT buffer?
#1
Have not tried this before and can't find an actual example to see if I'm leaving something out, but how does one go about drawing directly on a GET/PU buffer?

I want to create and draw images directly on the buffer instead of drawing on the screen and then "getting" the image. The code below is a simple attempt at creating a 400 x 400 view that is to be drawn upon and then "PUT" onto the main display:

Code:
'  create 400x400 "scratch surface" for drawing
dim myview(4 + (400*400)) as long
screen 18
line myview, (10,10)-(30,30), 3, BF
put (0,0), myview, pset
sleep

It doesn't show anything on the screen. What did I forget?
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#2
You have to setup the buffer "header" yourself, iir: buffer(0) = width*8: buffer(1) = height, assuming buffer was declared as an array of short's.

I think it would be better to have dynamic allocated images, as fbgfx supports pointers being passed, not arrays only. mysprite = createimageorsomeothername( 32, 32, 8 ): drawontothisthing( mysprite ): put (), mysprite: delimage( mysprite). I always missed that in the QB..
Reply
#3
OK. Got it figured out. One thing I realize now that I have been doing wrong is assuming that all pixel data is held as 32bit values. So each array calculation for 256 color resolution was 4 times larger than it need to be. So after fiddling with setting width and height in the first two values of a LONG array, I actually read through the documentaion closely and see the "hints" area spells out the speifics for what I was attempting if I just paid closer attention to the GET/PUT setup information.

The following code works:
Code:
'  create 400x400 "scratch surface" for drawing
dim myview((4 + (400*400))/2) as ushort
myview(0) = 400 shl 3
myview(1) = 400
screen 18
line myview, (10,10)-(30,30), 3, BF
put (0,0), myview, pset
sleep
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#4
Quote:You have to setup the buffer "header" yourself, iir: buffer(0) = width*8: buffer(1) = height, assuming buffer was declared as an array of short's.

I think it would be better to have dynamic allocated images, as fbgfx supports pointers being passed, not arrays only. mysprite = createimageorsomeothername( 32, 32, 8 ): drawontothisthing( mysprite ): put (), mysprite: delimage( mysprite). I always missed that in the QB..

I miss it too. I will put it in the requests list. In the meantime...

Code:
declare function makebuffer(h as integer, w as integer) as byte ptr
screen 20,32

dim buf as byte ptr
buf=makebuffer(100,100)
for i=49 to 1 step -1
circle buf,(49,49),i,rgb(255-i*4,i*4,0)
next

put (100,100),buf,pset
deallocate buf

sleep
end


function makebuffer(h as integer, w as integer) as byte ptr
   dim info as integer ptr
   dim buf as byte ptr
   info=callocate(36)  'the size of a screeninfotype
   info=screeninfo
   bpp=info[5]\8
   print bpp  
   deallocate info
   buf =callocate (h*w*bpp+4)
   a=8*w
   buf[0]=lobyte(a)
   buf[1]=hibyte(a)
   buf[2]=lobyte(h)
   buf[3]=hibyte(h)
   function=buf
end function
Antoni
Reply
#5
Antoni, that will not work... SCREENINFO returns a pointer to a static structure inside gfxlib, no need to allocate/deallocate stuff. Just access the memory pointed to by its return value. So your code should look like:
Code:
function makebuffer(w as integer, h as integer)
  dim info as integer ptr
  dim buf as ushort ptr
  dim bpp as integer

  info = screeninfo
  bpp = info[5] \ 8
  buf = callocate(w*h*bpp+4)
  buf[0] = w * 8
  buf[1] = h
  function = buf
end function
ngelo Mottola - EC++
Reply
#6
Ok...

Could it be a function in the gfxlib? It would be useful!
Antoni
Reply
#7
This is how to do it in the latest version
Maybe someone can use it


declare function makebuffer(w As Integer, h as Integer)
Screen 19,32,,1
Dim Shared w,h,depth
SCREENINFO w,h,depth,,,refresh,driver_name$
Dim buf as byte Ptr
buf=makebuffer(100,100)
for i=49 to 1 step -1
circle buf,(49,49),i,rgb(255-i*4,i*4,0)
Next
put (100,100),buf,PSet
deallocate buf
Sleep
End

function makebuffer(w as integer, h as integer)
dim buf as ushort Ptr
dim bpp as Integer
bpp = depth \ 8
buf = callocate(w*h*bpp+4)
buf[0] = w * 8
buf[1] = h
function = buf
end function
Reply
#8
Note that there is an IMAGECREATE built-in which performs the same function as that 'makebuffer' in the latest version: http://www.freebasic.net/wiki/wikka.php?...magecreate
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)