• Welcome to Dark Bit Factory & Gravity.
 

Draw Image Rectangle Sub

Started by Clyde, July 13, 2006

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Clyde

The following snippet is kinda Psuedo code, as I've not included the entire source which is pretty lengthy.
However, this portion of the code isn't right, and I wondered if anybody could spot what I'm calculating wrongly.
I've based it off, from the Blitz Basic "DrawImageRect" command. All that is contained in the Images(x,y) is the image colour data.

If you know what I've buggered up, I'd love to know what the correction is.


Sub DrawImageRect ( ByVal PosX, Byval PosY, ByVal rect_x, ByVal rect_y, ByVal rect_width, ByVal rect_height)

    Dim x,y, Col
   
    For y=rect_y to rect_height-1
        For x=rect_x To rect_width-1
           
            Col=Images(x,y)
           
            FeedPixels( x+PosX, y+PosY, Col )
           
        Next
    Next
   
End Sub


Cheers for taking a look and many thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

TinDragon

what is it actually doing wrong as from that code, assuming that your not running out of the images arrays x & y size, looks like it would work ?

Tetra

#2
Not sure what all you inputs mean, so I got rid of rect_x and rect_y
Dunno if this is what you are looking for.


Sub DrawImageRect ( ByVal PosX, Byval PosY, ByVal rect_width, ByVal rect_height )

Ã,  Ã,  Dim x,y, Col
Ã,  Ã,  
Ã,  Ã,  For y=0 to rect_height-1
Ã,  Ã,  Ã,  Ã,  For x=0 To rect_width-1
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Col=Images(x, y)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  FeedPixels( x + PosX, y + PosY, Col )
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  Next
Ã,  Ã,  Next
Ã,  Ã,  
End Sub


But for it to be similar to blitz, you would usually get the rect_width and height from the actual image.
Challenge Trophies Won:

Clyde

@TinDragon: It doesnt display anything.

@Tetra: Want to aim for the Blitz approach, Im thinking maybe I need to add rect_x and rect_Y at the start of the x,y loop and also to the end rect_height / width. Will have a play.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Clyde

Hmmm, I can't phathom this one. I've tried doing the following:


Sub DrawImageRect( ByVal PosX, Byval PosY, ByVal rect_x, Byval rect_y, ByVal rect_width, ByVal rect_height )


    Dim x,y, Col
   
    Col=Images( rect_x, rect_y )

    For y=0 to rect_height-1
        For x=0 To rect_width-1
           
           FeedPixels( x + PosX, y + PosY, Col )
           
        Next
    Next
End Sub


And still no joy. :(
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Clyde

Cool, i've fixed it!! Hurray :D


Sub DrawImageRect( ByVal PosX, Byval PosY, ByVal rect_x, Byval rect_y, ByVal rect_width, ByVal rect_height )

    Dim x,y, Col
   

    For y=0 to rect_height-1
        For x=0 To rect_width-1
           
            Col=Images( x+rect_x, y+rect_y )

            if x+PosX>0 and x+PosY<XRES-1 and y+PosY>0 and y+PosY<YRES-1 then
           
                FeedPixels( x + PosX, y + PosY, Col )
           
           End if
           
        Next
    Next
   
End Sub


Feel free to use.

Cheers - Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

Hehehe, I must be drunk. I started trying to fix this problem before I realised that there were more posts underneath Doh!  ;D Never mind and glad you got it fixed mate.
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

Cheers, this opens alot of doors for me porting over some effects.
Hope it's of use to others too.

Thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

Drawimagerect is a handy function for all sine scrollers :)
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

I've now also managed to do a very famous Jeff Minter Atari effect too. Which I hope to put to use in the next GVY release.
There's a ton of cool stuff to be had with DIR.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

thrawn89

Can you please give us a short example with this function in action? Im having difficulty understanding as to its purpose...thanks :-)

Thrawn

Shockwave

The main thing with this function is that for example, you could load in a whole picture, say a screen with a font on it and cut the bits out of it that you want to draw.
Being able to draw slices out of the image makes it very easy to simulate Amiga copper wobble effects and also to make sine scrolls with ease as you can then just step through the letter with a simple for next loop varying the sine wave as you go.
Shockwave ^ Codigos
Challenge Trophies Won:

thrawn89

Ahh...you know, I can code a png decoder, I can even write my own render from scratch...yet...that just went right over my head XD

Ok, ok, I understood some of it...how would you use it as you say to cycle through a font pic [cause if you resource and load one png it will drastcally cut down on load times for a font set]?

Also...could you use it for say...sound resampling?

Thrawn


Shockwave

#13
No problem, you'd have a strip of the letters, I've attached a strip of sprites from a game I made because I can't find a suitable font at the minute but it will give you the idea.

You'd set your font out in a similar fashion to this, as one long image all in ascii order, you can load in your image as this one strip and then just use the ascii offset to calculate mathematically the position in the strip.
for example, if you wanted to draw the exclamation mark and your letters are 32*32, being as the first character is space and the second one is exclamation mark you could do;

STRING="!"


         offset = (ASC(MID(STRING,POINTER,1)) - 31) * 32
         draw_image_rect ( FONT_SCREEN , XPOS , YPOS , OFFSET , 0 , OFFSET+31 , 31 )


To cut the letter out of the font strip that you wanted to draw.
I guess that you could use the technique to get different notes from a sound sample, if you sampled a sound at a very low C for instance and stepped through the sound data to increase the speed you play the note you'd notice a rise in pitch so I guess that you could make a simple tracker program in that way, dunno I've never really thought about doing anything like that.
All I know is that it's a pain in the ass to have to load each letter of a font seperately and it would be nice to be able to load gfx strips like this.


Shockwave ^ Codigos
Challenge Trophies Won:

thrawn89

Ok, I understand fully now...Im sure you dont need all those variables in the parameter list though, when I get back and start making mine, I'll post the code....

Thrawn

Shockwave

Cool, But I'm sure you'd need to have at least these parameters;

SCREENX , SCREENY , STARTX , STARTY , WIDTH , HEIGHT
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

[quote = "Blitz Basic Syntax" ]
DrawImageRect:  image,x,y,rect_x,rect_y,rect_width,rect_height,[frame]

Parameters:
image = variable holding the image handle
x = x location on the screen to draw the image
y = y location on the screen to draw the image
rect_x = starting x location within the image to draw
rect_y = starting y location within the image to draw
rect_width = the height of the area to draw
rect_height = the width of the area to draw
frame = optional frame number of image to draw
Quote

If you've got or used BB in the past, then you'd know how pretty usefull this command is.

All I've done is omit the Image, as Im not using sprites as you'll see by my first few posts. All my data is loaded / made into a Dim Image( Width, Height ) as I find it much easier to manipulate the colour data with.

I'll post up some code if I've still got Internet and I remember, when I get home of a few example a bit later in seperate topics.

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: