Textured Poly / Star Wars Scroller

BlitzMax Forums/BlitzMax Programming/Textured Poly / Star Wars Scroller

sswift(Posted 2009) [#1]
I'm trying to implement a star wars scroller in my game, and I thought maybe using a textured poly would be a good way to go, but the following code from the code archives no longer works:

http://blitzmax.com/codearcs/codearcs.php?code=1812

Anyone know what "Driver.islost" has been changed to?

Another way I could implement this would be to rotate images away from the camera and scale them, but I'm not sure how to go about that, or if it's even possible with the way BlitzMax's cameras are set up.

Any other ideas on how to implement this would be appreciated. Any solution must work in both OpenGL and DirectX.


Tommo(Posted 2009) [#2]
Maybe you can use " not Driver.isValid()" instead of "Driver.islost".


Warpy(Posted 2009) [#3]
This works:

Function DrawTexturedPoly(image:TImage, xyuv:Float[] , frame = 0, vertex = -1) 
	Local handle_x#,  handle_y#
	GetHandle handle_x#,  handle_y#
	Local origin_x#,  origin_y#
	GetOrigin origin_x#,  origin_y#	
	
	Local D3DDriver:TD3D7Max2DDriver = TD3D7Max2DDriver(_max2dDriver)
	
	Assert Image, "Image not found"
	
	If D3DDriver Then 
		DrawTexturedPolyD3D ..
			D3DDriver,..
			 TD3D7ImageFrame(image.Frame(frame)), ..
			 xyuv, handle_x, handle_y, origin_x,origin_y, vertex*4
		Return
	End If
	Local  OGLDriver:TGLMax2DDriver = TGLMax2DDriver(_max2dDriver)
	If OGLDriver Then
			DrawTexturedPolyOGL ..
				OGLDriver,..
				 TGLImageFrame(image.Frame(frame)), ..
				 xyuv, handle_x, handle_y, origin_x,origin_y,  vertex*4
		Return
	End If
End Function


Function DrawTexturedPolyD3D( Driver:TD3D7Max2DDriver,  Frame:TD3D7ImageFrame,xyuv#[],handlex#,handley#,tx#,ty# , vertex)
	'If Driver.islost Return
	If xyuv.length<6 Return
	Local segs=xyuv.length/4
	Local len_ = Len(xyuv)
	
	If vertex > - 1 Then
		segs = vertex / 4
		len_ = vertex
	End If
	Local uv#[] = New Float[segs*6] ' 6
	

	Local c:Int Ptr=Int Ptr(Float Ptr(uv))
	
	Local ii:Int = 0
	For Local i=0 Until len_ Step 4
		Local x# =  xyuv[i+0]+handlex
		Local y# =  xyuv[i+1]+handley
		uv[ii+0] =  x*Driver.ix+y*Driver.iy+tx
		uv[ii+1] =  x*Driver.jx+y*Driver.jy+ty 
		uv[ii+2] =  0  ' *********** THIS IS THE Z-COORDINATE
		c[ii+3] = Driver.DrawColor
		uv[ii+4] =  xyuv[i+2]
		uv[ii+5] =  xyuv[i+3]
		ii:+6
	Next
	Driver.SetActiveFrame Frame
	Driver.device.DrawPrimitive(D3DPT_TRIANGLEFAN,D3DFVF_XYZ| D3DFVF_DIFFUSE | D3DFVF_TEX1,uv,segs,0)
End Function

Function DrawTexturedPolyOGL (Driver:TGLMax2DDriver, Frame:TGLImageFrame, xy#[],handle_x#,handle_y#,origin_x#,origin_y#, vertex) 
	Private
	Global TmpImage:TImage
	Public
	
	If xy.length<6 Return
	
	Local rot#  = GetRotation()
	Local tform_scale_x#, tform_scale_y#
	GetScale tform_scale_x, tform_scale_y
	
	Local s#=Sin(rot)
	Local c#=Cos(rot)
	Const scale#=1.28
	Local ix#= c*tform_scale_x*scale
	Local iy#= -s*tform_scale_y*scale
	Local jx#= s*tform_scale_x*scale
	Local jy#= c*tform_scale_y*scale
	
	glBindTexture GL_TEXTURE_2D, Frame.name
	glEnable GL_TEXTURE_2D
	
	glBegin GL_POLYGON
	For Local i=0 Until Len xy Step 4
		If vertex > -1 And i >= vertex Then Exit
		Local x#=xy[i+0]+handle_x
		Local y#=xy[i+1]+handle_y
		Local u#=xy[i+2]
		Local v#=xy[i+3]
		glTexCoord2f u,v
		glVertex2f x*ix+y*iy+origin_x,x*jx+y*jy+origin_y
	Next
	glEnd
	If Not tmpImage Then tmpImage = CreateImage(1,1)
	DrawImage tmpImage, -100, - 100 ' Chtob zbit' flag texturi
End Function



Warpy(Posted 2009) [#4]
oh whoops, just noticed all I've done is commented that line out!
Maybe "If Not Driver.IsValid() Return" ?


N(Posted 2009) [#5]
While you're at it, might as well wrap the D3D code in ?Win32 ... ?


ImaginaryHuman(Posted 2009) [#6]
You're going to need a perspective projection in order to properly display the perspective effect otherwise it's going to look like a `squeeze` effect.


sswift(Posted 2009) [#7]
ImaginaryHuman:

Hm. Yeah you're right. :-(

I decided to just go with a standard scroll. It's not really worth having a star wars scroll for the amount of text I have in the story anyway.


ImaginaryHuman(Posted 2009) [#8]
But wait, it's easy to fake it.

All you need is a bunch of horizontal strips, which you individually scale and position to form a trapezium. Depending on the Y position you scale by a given amount. You could precalculate it or use some `realistic` perspective projection/divide thing.


Mr. Write Errors Man(Posted 2009) [#9]
There used to be one written by indiePath. It had the bonus of supporting vertex colors (separate for each point of the polygon).