COPYRECT in blitzmax ??

BlitzMax Forums/BlitzMax Programming/COPYRECT in blitzmax ??

erwan(Posted 2005) [#1]
Could someone tell me how to translate in Bmax the CopyRect command ? I 've found in there serverals sources witch tell us how to do this, but it doesn't work. Perhaps Copyrect will be available in a future version ? Thanks a lot for you awswers


ImaginaryHuman(Posted 2005) [#2]
There is an OpenGL command, glCopyPixels, which you have to set up using several other calls to tell it where to read from, write to, etc. ... you can use it to copy rectangular areas of the backbuffer to other locations in the backbuffer. I'm not sure whether it is hardware accelerated or not, it seems like a CPU routine on my computer.

You could also use GrabImage and DrawImage. DrawImage is fast but GrabImage is slow. If you were using OpenGL calls you could use glCopyTexSubImage2D to grab the backbuffer to a previously-defined texture, and then render the texture (like with DrawImage). Not sure if it's really way fast either, but it works too.

Note that OpenGL pixels are internally stored with a floating point value for each color component including alpha, which consumes about 16 bytes per pixel. ... unless it stores it as plain old RGBA888 data. Not sure.


Crystal Noir(Posted 2005) [#3]
Hi all :)

I don't understand how can you copy a part of an image with grabimage or drawimage ? Can you explain plz ? Because Drawimage draws all the image doesn't it ?


PaulJG(Posted 2005) [#4]
Depends on the size of the block you allocated using createimage. Use createimage to set the size you want - then grabimage to get the image at the x/y position.

If you want a dynamically change the size of the grab, then the only way I can see how you'd use it is to delete the image - before creating a new one.

Drawimage will blast the entire image onto the screen. I'm using the setviewport command to get it to display a certain area of my image. Not a wonderful hack - but fast enough for my needs.


Crystal Noir(Posted 2005) [#5]
yes but with setviewport you can't draw an other image on the entire screen can you ?

For ex : If we use setviewport to draw a part of an image, and at the same time in our loop we want to draw an other image but this time all the image, is it possible ? with an another setviewport command perhaps ?


PaulJG(Posted 2005) [#6]
yes.. I'm doing it

Setting the viewport down to my image clipping window, once I've blasted what I want - reset it back to screen size so I can edit the score panel.

Infact I've got a nice parellex scrolling backdrop. (its just a couple of huge images clipped to the viewport window)


ImaginaryHuman(Posted 2005) [#7]
Yes you'd need to restore the fullscreen viewport after you've specified a smaller one. Please note though that according to the OpenGL documentation, defining a viewport smaller than the screen doesn't necessarily mean that nothing will be drawn outside of the viewport area. You should be defining a SCISSOR area and enabling the scissor test. This will ensure that there is no drawing outside the viewport.

Another way to do this, if you want to do more of your own OpenGL, is you set up a dummy image like what CreateImage does, do a grab image, and then instead of doing the viewport/drawimage part, switch on texturing yourself and draw a quad at whatever coords and specify the texture coordinates for each vertex. This will allow you to render only a part of the total image, and it doesn't have to be square.


Crystal Noir(Posted 2005) [#8]
Ok thx :) have you got an example of code how to do a copyrect style plz ?


DannyD(Posted 2006) [#9]
I'm trying to convert this code to BlitzMax but failing at the copyrect. Any help appreciated
Melt Effect



This tutorial will show you how you can make a melting like effect, where an image is drawn onto the screen in a way that it looks like it is melting down the screen until the image is complete.

The way that I have done it, is that I have two loops, one looping through the image from top to bottom, the other one inside looping through the image from the top to the bottom minus where the first loop is at drawing the same line each time, and then copy the rest of the image at after. Not sure that it makes sense, but its a bit difficult to explain, so look the code over and see if you can catch what I mean.

You have to provide your own image for this one.

Here follows a code example:

Graphics 640,480,32,2
temp = LoadImage( "picture.jpg" )

SetBuffer BackBuffer()

melt( temp, 640, 480, 2 )

WaitKey
End

;---------------------------------------------------------------------
; NAME : melt()
; PURPOSE : draws an image onto the screen in a melting like effect
; INPUTS : image handle, width, height, update frequency
; RETURNS : nothing
;---------------------------------------------------------------------
Function melt( PICTURE, WIDTH, HEIGHT, UPDATEFREQ )
HEIGHT = HEIGHT-1
Local lastupdate = MilliSecs()
For y1 = 0 To HEIGHT
While MilliSecs() < ( lastupdate + UPDATEFREQ )
Wend
lastupdate = MilliSecs()
For y2 = 0 To HEIGHT-y
CopyRect 0, HEIGHT-y1, WIDTH, 1, 0, y2, ImageBuffer( PICTURE ), BackBuffer()
Next
CopyRect 0, HEIGHT-y1, WIDTH, y1+1, 0, HEIGHT-y1, ImageBuffer( PICTURE ), BackBuffer()
Flip
Next
End Function



Curtastic(Posted 2006) [#10]
I want to know also.


Jesse(Posted 2006) [#11]
here it is a quick and dirty convertion. Not exactly a one to one convertion but it gives the same results


EDIT:

the only way I thing you can do a copyrectangle is to make your own function using readpixel and plot/writepixel.


DannyD(Posted 2006) [#12]
Thanks for the input Jesse! When I try running it I get a Unhandled exception: Pixmap coordinates out of bounds for this line in the funcion Melt
		Local color% = ReadPixel(pix,x,y)

Is ReadPixel on Blitz different than ReadPixel on Max? Couldn't find documentation.


Jesse(Posted 2006) [#13]
it was supposed to be used with an image 640x480 change the image to that or change the call line to this:

melt( temp, ImageWidth(temp),ImageHeight(temp), 200 )



DannyD(Posted 2006) [#14]
Ahhh, it makes sense now, thanks again.