graphic buffers from BP+

BlitzMax Forums/BlitzMax Beginners Area/graphic buffers from BP+

CloseToPerfect(Posted 2009) [#1]
I have finally upgraded from BP+ to MAX and now find myself relearning alot of concepts. I have tried to search the forums as I am sure my question is on here somewhere from someone but there is just to much to look though.

Anyway, In my BP+ programs I would create a buffer then set that buffer as my current buffer and do my cutting and modifing of the image on it. I think what I want in MAX is pixmaps but I am not sure how to use them.

If some one can help me here are the specific steps if you can help me though it.

start,load an image from a png file.

create a new image buffer.

draw the image to the new buffer.

cut from the new buffer.

paste back to the new buffer.

grab the image from the buffer for regular use in the normal graphics mode.


I don't know if you can load directly to a pixmap or if you have to loadimage first then draw to a pixmap.

That's it for now,
John


Jesse(Posted 2009) [#2]
blitzMax has a lot of things that work better out of the box thank BPlus but pixmap do not. If you really learn how to use them they are a lot faster than the fastest raw writing to the The Bplus buffer. but you are either going to have to create your own functions or use some that are in the Code Archives.
I don't recommend for you to load the pixmap from the png instead load an image:
image:TImage = loadImage("image.png")

you can read or write to the image through its pixmap. to extract its pixmap you can do thi:
pixmap:tpixmap = lockImage(image)

you can read or write to the pixmap like this:
pixelcolors:int = ReadPixel(pixmap,x,y)

(look in the help menu for pixel formats)
to write to a pixmap:
writePixel(pixmap,x,y,pixelcolors)

when you are done writting to the pixmap don't forget to unlock the image:
unlockImage(image)

when you draw the image it will contain the modifications:
drawImage(image,x,y)

note: this is not the fastest way to access the data in an image but there are more advanced ways. look in the right hand side of the Max IDE and in the home tab:
moduleSource->brl.mod->pixmap.mod->pixmap.bmx
for the source code of the pixmap module. if you understand the code, you will be able to figure out how to work with them more efficiently.


you can also create an empty image with createImage and copy pixels from one image to another using the principle above.


CloseToPerfect(Posted 2009) [#3]
ok this seems simple enough. If I understand there is no function to grab a smaller pixmap from a larger pixmap and redraw that back to the pixmap. I simply have to make a function then to read a section and write it back using pixel function.

I guess a good way do do this would be to use PixmapWindow and ReadPixel from it and WritePixel back to the original pixmap?

Thanks,
John


Zeke(Posted 2009) [#4]
yes.
but you dont need to read/write pixels. just use copy/paste:
Local pix:TPixmap = LoadPixmap("test.png") 'load source pixmap

Local newpix:TPixmap=pix.Window(50,50,100,100).Copy() 'create 'virtual window' AND copy pixels to new pixmap

'do stuff to newpix

pix.paste(newpix, 50, 50) 'paste newpix pixmap back to source pixmap



Jesse(Posted 2009) [#5]
yes, I forgot about window and paste but they are in the pixmap module.


CloseToPerfect(Posted 2009) [#6]
ah, i didn't see the paste command. Still getting the hang of the function index in the IDE. Thanks for the help. This seems to be working for me now.


MGE(Posted 2009) [#7]
You'll probably want to research "render to texture" sounds like that's what you might want to do. And that is not supported out of the box unfortunately. I think there is a routine floating around to do it though.


theHand(Posted 2009) [#8]
Images & Pixmaps - simple explanation please explains them quite well.
It confused the hell out of me until I understood that it was sort of a workaround to be able to use GPUs to speed up BlitzMax (that's why, right?!).