Converting blitz2d to max
BlitzMax Forums/BlitzMax Programming/Converting blitz2d to max
| ||
I have this code in Blitz2D, and I want it work in blitzmax but there is no copyrect or imagebuffers. I think you should be able to do everything in blitzmax that you could do in blitz2d... but this code needs to run very fast. And it is fast in blitz2d. Heres basically what the code looks like: Each loop it has to write to every fire image buffer using copyrect and writepixelfast. I haven't ever used pixmaps, can they do this? Is there some sort of copyrect function? Function FireUpdate(Fire.Fire) SetBuffer ImageBuffer(Fire\image) For whatever X=Rnd() Y=Rnd() AddX=Rand(-1,1) CopyRect X,Y,Rnd(5,7),Rnd(5,10), X+AddX, Y - 1 Next LockBuffer ImageBuffer(Fire\image) For whatever X=Rnd() Y=Rnd() WritePixelFast X,Y,0 Next UnlockBuffer ImageBuffer(Fire\image) End Function |
| ||
This should help. |
| ||
There is no copyrect function. You can use drawimage and grabimage to grab a rect and then draw it again. Alternatively you can use memcopy. Another way is to use pixmapwindow and copypixmap. You could look at setviewport to limit the drawing of an image. Finally, you can use setuv to draw a portion of an image. For writepixelfast you can lockimage(image) and put the result in apixmap and then use writepixel before loadimage(pixmap). I tried to write a function you could use but there are too many variables in what you might be trying to do and how big an image you're using. |
| ||
Ok, its starting to work now. I'm having trouble with pixel access. This outputs the pixel information of an image that should be just a single dot. Strict Graphics 666,666 Local image:timage=CreateImage(5,5,dynamicimage) SetColor 0,0,200 Plot 2,2 GrabImage image,0,0 Local s:String Local pixmap:TPixmap pixmap=LockImage(image) For Local y=0 To 4 s="" For Local x=0 To 4 s:+(ReadPixel(pixmap,x,y)&$FFFFFF)+"," Next Print s Next UnlockImage image Print "ROUND 2" DrawImage image,0,0 GrabImage image,0,0 pixmap=LockImage(image) For Local y=0 To 4 s="" For Local x=0 To 4 s:+(ReadPixel(pixmap,x,y)&$FFFFFF)+"," Next Print s Next UnlockImage image End Why does it show that there are 4 pixels of color 200? Why does it get darker when I draw the image and then grab it? How do I get it to be pixel-perfect? |
| ||
Ok wow I got it working and its even faster than blitz2d. thanks for the help GFK and tg. But one problem remains: How can I use DrawOval onto an image, pixel-perfectly? (without coding my own drawoval function) |
| ||
Graphics 640,480 Local image:TImage=LoadImage("max.png") Cls DrawImage image,0,0 DrawOval 0,0,100,100 GrabImage(image,0,0) Cls DrawImage IMAGE,0,0 Flip WaitKey() ? |
| ||
hmm I guess I meant a Plot. Plotting one pixel plots 9. according to the readpixel information. Graphics 800,600 i=CreateImage(10,10) Plot 5,5 GrabImage i,0,0 p=LockImage(i) For y=0 Until 10 For x=0 Until 10 Print ReadPixel(p,x,y) & $FF 'print the blue value of each pixel Next Next UnlockImage(i) |