Draw textured rectangle

BlitzMax Forums/BlitzMax OpenGL Programming/Draw textured rectangle

What do I have to do to my dimensions to apply max2d origin, handle, scale, rotation, etc to a quad I'm drawing? What about alpha and blend?

I thought I saw a way to do it by modifying the modules but that is less than optimal..

(Talking GetScale, GetHandle, GetOrigin, GetRotation etc..)

Current code:
Function DrawTexturedQuad(x:Float, y:Float, w:Float, h:Float, texture:Int)
	
	'Make transformations to dimensions
	
	glPushMatrix() 'Necessary?
	
	glBindTexture(GL_TEXTURE_2D, texture)
	
	glBegin(GL_QUADS)
	glTexCoord2f(0.0, 0.0); glVertex2f(x, y)			'Top-Left
	glTexCoord2f(1.0, 0.0); glVertex2f(x + w, y)		'Top-Right
	glTexCoord2f(1.0, 1.0); glVertex2f(x + w, y + h)		'Bottom-Right
	glTexCoord2f(0.0, 1.0); glVertex2f(x, y + h)		'Bottom-Left
	glEnd()
	
	'Unbind texture??
	
	glPopMatrix() 'Necessary?

End Function


Nevermind.. I just looked at the code for DrawPixmap, which already handles the dimensions and draws the pixels directly from the pixmap instead of having a load of textures on hand.

EDIT: Lost my thought there.. I have to be able to change the vertex values so using drawimage/drawpixmap isn't an option..

Halp, GL guru's!

SuperStrict

Framework brl.glmax2d
Import brl.pngloader

SetGraphicsDriver GLMax2DDriver()
Graphics 1024, 768, 0


Global ow:Float, oh:Float
Global tex:Int = LoadTexture("texture.png")

Local ox:Float = 512, oy:Float = 384
While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
	
	Cls
	
	If KeyDown(KEY_SPACE)
		
		SetTransform(45.0, 0.5, 0.5)
		
	Else
		
		SetTransform(0.0, 1.0, 1.0)
		
	End If
	
	DrawRect ox - 200.0, oy, ow, oh
	DrawTexturedQuad(ox, oy, ow, oh, tex)
	DrawRect ox + 200.0, oy, ow, oh
	
	Flip
	
	Delay 10
Wend

End


Function DrawTexturedQuad(x:Float, y:Float, w:Float, h:Float, texture:Int)
  
  Local ix:Float, iy:Float, jx:Float, jy:Float
	GetTransformVars(ix, iy, jx, jy)
	
	'Make transformations to dimensions
  Local origin_x:Float, origin_y:Float
  Local x0:Float, y0:Float, x1:Float, y1:Float, tx:Float, ty:Float
	GetHandle(x0, y0)
	x1 = x0 + w	'handle_x + width
	y1 = y0 + h	'handle_y + height
	
	tx = x + origin_x	'x + gc.origin_x
	ty = y + origin_y	'y + gc.origin_y
	
	glPushMatrix() 'Necessary?
	
	glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
	glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
	glEnable(GL_TEXTURE_2D)
	glLoadIdentity()
	glBindTexture(GL_TEXTURE_2D, texture)
	
	glBegin(GL_QUADS)
	'OLD!!
	'glTexCoord2f(0.0, 0.0); glVertex2f(x, y)			'Top-Left
	'glTexCoord2f(1.0, 0.0); glVertex2f(x + w, y)		'Top-Right
	'glTexCoord2f(1.0, 1.0); glVertex2f(x + w, y + h)		'Bottom-Right
	'glTexCoord2f(0.0, 1.0); glVertex2f(x, y + h)		'Bottom-Left
	
	glTexCoord2f(0.0, 0.0);
	glVertex2f(x0 * ix + y0 * iy + tx, x0 * jx + y0 * jy + ty)
	
	glTexCoord2f(1.0, 0.0);
	glVertex2f(x1 * ix + y0 * iy + tx, x1 * jx + y0 * jy + ty)
	
	glTexCoord2f(1.0, 1.0)
	glVertex2f(x1 * ix + y1 * iy + tx, x1 * jx + y1 * jy + ty)
	
	glTexCoord2f(0.0, 1.0)
	glVertex2f(x0 * ix + y1 * iy + tx, x0 * jx + y1 * jy + ty)
	
	glEnd()
	
	glDisable GL_TEXTURE_2D
	
	glPopMatrix() 'Necessary?

End Function

Function LoadTexture:Int(url:Object)
  Local pm:TPixmap, id:Int
	
	pm = LoadPixmap(url)
	gw = pm.width; gh = pm.height' / 2
	
	id = GLTexFromPixmap(pm)
	
	Return id
	
End Function



*Gasps for air*

Sheesh.. That took forever..

But I had to make a modification to brl.glmax2d :(