Whoooa... so that SetSpriteUV() thing sent me off on a wonderful mathematical google journey that was far too complicated for my small chimpanzee brain with it's D grade in GCSE maths to comprehend.
I remember clearly thinking in lessons how useless trigonometry was in the real world, and how I'd never need it, so i won't pay attention. Yes, never mind...
So anyway, I think I've got Bengismos shader working, so many thanks to Bengismo should you happen to come across this thread.
I had to fiddle with it a bit to get it going, so I'll pop it in here in noob friendly format for anyone else that's thinking a combination of "I need fast filled 2d polygons" along with "whats a shader?".
so first up, stick this is a text file and save it in your media folder as vertex.vs
// File: shader.agc
// Created: 20-08-10
attribute highp vec4 position;
attribute mediump vec4 color;
attribute mediump vec2 uv;
varying mediump vec2 uvVarying;
varying mediump vec4 colorVarying;
uniform highp mat4 agk_Ortho;
uniform highp vec4 Coords[4];
void main()
{
vec4 pos = position;
// CHeck which corner it is
if(uv.x == 0.0)
{
if(uv.y == 0.0)
{
pos.xy = Coords[0].xy; // Top left
}
else
{
pos.xy = Coords[1].xy; // Bottom left
}
}
else
{
if(uv.y == 0.0)
{
pos.xy = Coords[2].xy; // Top right
}
else
{
pos.xy = Coords[3].xy; // Bottom right
}
}
gl_Position = agk_Ortho * pos;
uvVarying = uv;
colorVarying = color;
}
then stick this in a text file and save it as pixel.ps in your media folder
uniform sampler2D texture0;
varying mediump vec2 uvVarying;
varying mediump vec4 colorVarying;
void main()
{
gl_FragColor = texture2D(texture0, uvVarying) * colorVarying;
}
then a quick demo:
// Project: polytry
// Created: 20-08-10
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "YAY FAST QUADS" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
//SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
LoadShader(1,"vertex.vs","pixel.ps")
CreateImageColor ( 1, 255, 255, 255, 255 )
CreateSprite ( 1, 1 )
SetSpriteSize ( 1, 1, 1 )
setspriteshader(1,1)
do
for t=1 to 1000
X1=random(0,1024):Y1=random(0,1024)
X2=X1+random(0,50):Y2=Y1+random(0,50)
X3=X1+random(0,50):Y3=Y1+random(0,50)
X4=X1+random(0,50):Y4=Y1+random(0,50)
SetShaderConstantArrayByName(1,"Coords",0,x1,y1,0,0) // Top left
SetShaderConstantArrayByName(1,"Coords",1,x2,y2,0,0) // bottom left
SetShaderConstantArrayByName(1,"Coords",2,x3,y3,0,0) // Top right
SetShaderConstantArrayByName(1,"Coords",3,x4,y4,0,0) // bottom right
Drawsprite(1)
next t
Print( ScreenFPS() )
Sync()
loop
This gets me over 1000 filled quads at 60fps on my lowly laptop, which is ample for my needs.
yay.. has hit my fps a bit but is turned on for the whole track at the mo.