Using TextureQuad To Draw Transparent Textured Strips

Started by kevin, January 10, 2022, 05:34:21 AM

Previous topic - Next topic

kevin

  Using TextureQuad To Draw Transparent Textured Strips


    This demo uses the TextureQuad function to draw transparent vertical strips with transparency.    Making it an alternative to the TextureStripV & TextureStripH functions, although this demo only supports vertical strips.    


Video

   



PlayBASIC Code: [Select]
; PROJECT : Using TextureQuad To Draw Transparent Textured Strips
; AUTHOR : PlayBASIC Tutor - http://playbasic.com
; CREATED : 10/01/2022
; EDITED : 10/01/2022
; ---------------------------------------------------------------------



loadfximage "textures/bubble_64x64.bmp",1



loadfximage "textures/tile000.jpg",2


do

TileX=mod(TileX+1,64)
tileimage 2,TileX,0,false


iw=getimagewidth(1)
lockbuffer
iAngle#=Angle#
for slp =0 to (getscreenwidth()-1)/iw
DestXpos=slp*iw
For xlp =0 to (iw-1)
Height = cos(iAngle#)*600
DestYpos=300-(Height*0.5)
DrawVerticalStripFromImage(1,xlp,DestXpos+xlp,DestYPos,DestYPos+height)
iAngle#++
next
next
unlockbuffer
Angle#=wrapangle(Angle#,1)

sync
loop spacekey()=true or esckey()
end


Function DrawVerticalStripFromImage(Image,StripX,DestX,DestY_Top,DestY_Bot)

if DestX>=0
if DestX<GetSurfaceWidth()

/* Here i'm assuming we're drawing from the top
To the bottom of the sourc texture, and we'll use viewport
clipping with pick the strip we want

*/

CurrentSurface=GetSurface()

// remember the
OLD_viewX1=GetImageViewportX1(CurrentSurface)
OLD_viewY1=GetImageViewportY1(CurrentSurface)
OLD_viewX2=GetImageViewportX2(CurrentSurface)
OLD_viewY2=GetImageViewportY2(CurrentSurface)

iw=getimagewidth(image)
ih=GetImageHeight(image)

ScreenY1 =DestY_Top
ScreenY2 =DestY_Bot

// subtract the strip from the display position
// as we're using the viewport to clip this vertical strip
ScreenX1 =DestX-StripX
ScreenX2 =ScreenX1+iw


// Set viewport to only show a single strip
if CurrentSurface
imageViewPort CurrentSurface,DestX,OLD_viewY1,DestX+1,OLD_viewY2
else
screenViewPort DestX,OLD_viewY1,DestX+1,OLD_viewY2
endif


// draw the quad
TextureQuad Image, ScreenX1 ,ScreenY1,0 ,0 ,_
ScreenX2 ,ScreenY1,iw ,0 ,_
ScreenX2 ,ScreenY2,iw ,ih,_
ScreenX1 ,ScreenY2,0 ,ih,1


if CurrentSurface
imageviewport currentsurface,OLD_viewX1,OLD_viewY1,OLD_viewX2,OLD_viewY2
else
screenviewport OLD_viewX1,OLD_viewY1,OLD_viewX2,OLD_viewY2
endif

endif
endif

EndFunction







Related Articles



hello welcome

back i just want to go through a very

quick

small code segment i just posted to the

board previously we were talking about

drawing transparent strips and one of

the limitations of the

the strip commands which are under

graphics down here somewhere

graphics

you've got the

where are we textured stripping

which draws a horizontal strip or a

vertical strip so you can do

slices of an image and split the image

up there that kind of thing

there's a ground version of it as well

one of the limitations of that command

in particular

is it doesn't support transparency

i never noticed

until recently actually

i think the plan was to add that but it

must have just fallen off the radar

so

how do you emulate that when it's not

actually part of the product well

what you can do is you can use the

the textured quad

which is really the same kind of

thing but we can limit the part of the

the output we're drawing to so we can

sort of simulate drawing a strip of

vertical pixels or a horizontal strip

here i'm using vertical string that's

true

and i'm still just drawing

uh texture fragments with sine wave

applied to it nothing all that

interesting to be honest

so they've got the ball being stretched

and having a sine wave controlling its

height

[Music]

normally what you have to do is have to

render all those strips to a secondary

buffer and then blit that buffer over

the background

with transparency

this is one way of doing it

the code itself is anything but optimal

so lighting the two textures with the

bubble texture

as effects surfaces

i could probably just do the backdrop

actually as a normal video image

just just check that's it before there's

issues with capturing this

so it captures okay now

[Music]

very strange

but anyway

the actual code itself

the background's just a tile image with

a modulated the modulus to simulate the

scrolling it's not interesting

this is the portion that controls uh

drawing

destroying strips across every scan

sorry every vertical

uh row of the screen

giving them different heights etc but

they're centered around the middle of

the screen

this function here is what we're

looking at that emulates the

uh the text strip vertical

command

giving it an image and what strip from

that image you want to draw

the output location

that we want to mean it to as well as

the the top point and the bottom point

so these can be so it can be stretched

so we're not doing a straight copy of

that image frame but we're doing a scale

of that fragment

uh we're checking if the source and this

destination are within the current

target surface if they're outside we

just ignore it

now a lot of this kind of safety code

can be got rid of if you want to do this

in a brute force way but here i'm just

kind of adding a

function that sort of does this task you

might have to clean it up a bit yourself

actually

we're running through grabbing the

current surface and remembering that for

next time grabbing the current viewports

we're going to be changing the viewport

as we're

doing this effect

so we'll need to restore this at the end

of the function so if you call it you're

not changing the state

[Music]

i'm grabbing the texture width and

height

setting out the target uh

the target y for where the strip is

going to be rendered to on on the screen

we subtract

the current x coordinate

because we want to draw a strip we have

to sort of line the strip up with this

viewport so i'm going to set the

viewport up to be the strip we want to

render rendering into

and then draw the image

on this rectangle as if we're

scrolling it left and right to show a

vertical row of it

that's what this stripper x is doing

depending on what surface we're drawing

to we set we use the image viewport

command or screen viewport command

in all seriousness what you would do is

you would work this out up ahead and

then do all of your texturing inside a

tight loop and then restore it later on

but anyway so

we're drawing texture quite sorry

calling text required to draw

actually we're drawing uh

a scaled a rectangle but what's

the only part that makes the screen is

the that vertical strip that we

we're interested in from the texture

well hopefully anyone

astron transparent

because texture coin supports

a transparent

flag this is probably one of the most

awkward functions in p bags it has so

many parameters as you can see

you've got to supply the texture and

then

the top left hand corner

then the top right hand coordinates

the top

are the bottom right hand corner and the

finals the bottom left and then the

transparency flag at the end so pretty

ugly

a few examples uh tacked on the outside

there

getting back to here so we're using the

texture quad to do its job

restoring the viewport and then

returning so we're drawing one strip at

a time from this thing scaled vertically

and that's the whole application run it

one more time

performance wise it's actually runs

pretty well so we're doing a full screen

vehicle strip here

if you're emulating something like or

trying to write a modern version of

something like a wolfenstein 3d for

example

those games were written to run in 320

by 200.

so we're running here 800 by 600 years

that would be the standard size

so it's you know a factor of probably

six times the amount of data

probably eight times even either today

in basic just as a more you know a bit

of a mock-up for you

[Music]

then i'll do us you can find the example

on the boards

uh it'll be over here on the boards

using texture quads to draw transparent

texture strips

that's the one thanks for watching i'll

see you next time






Related Articles

       * Wolf3D - Updated Demo Release