textured poly

Monkey Forums/Monkey Programming/textured poly

pantson(Posted 2013) [#1]
Hi
I've searched the forums and cant see any answer to this.

DrawImagePoly img,x1,y1,x2,y2,x3,y3,x4,y4,frame

I've created a DrawImagePoly myself but as usual it wont be optimised and there is hardware that can do this in a flash.
Is there a similar built-in command in Monkey for cross platform use?

many thanks


Nobuyuki(Posted 2013) [#2]
there is not.


pantson(Posted 2013) [#3]
Just hacking at mojo now to add a DrawImagePoly command.
first attempt for android seems to be working




pantson(Posted 2013) [#4]
Have added a DrawImageQuad utilising GLES. Very happy with the results so far..
Textured road surface is a lot faster at drawing and keeps up FPS



@MarkSibly.. are you wanting the Android code for Mojo?


frank(Posted 2013) [#5]
Can you put the source online in github or google code or something? I need this and when I have some time I can write the code for the other targets (besides XNA which I don't use).


Skn3(Posted 2013) [#6]
Why not clone the official source and add it that way :) ?

Would definitely like this feature.


DruggedBunny(Posted 2013) [#7]
Me too!


Qcat(Posted 2013) [#8]
Me To!


Skn3(Posted 2013) [#9]
Me three, oh wait I already participated..


marksibly(Posted 2013) [#10]
Please feel free to post the source for this.

> Why not clone the official source and add it that way :) ?

Native mojo android code is not in the repos.

Ideally, stuff like this should probably be added via some kind of extension mechanism, so that mojo module code doesn't have to be hacked/modified. But providing such a mechanism for mojo monkey code AND all native targets is a reasonably big job, esp. if you want to be able to share internal native VBs etc.

But this is useful functionality that would be nice to have in core Mojo, although I'd be more inclined to go for something more flexible like:

DrawPoly( verts:Float[],texture:Image,texcoords:Float[] )

My only concern is this probably isn't doable on all targets - well, easily/usefully anyway. Not sure, will look into it.


Skn3(Posted 2013) [#11]
Oh yes texcoords would be good. What about optional vertex colours/alpha too? (For supported targets)


Skn3(Posted 2013) [#12]
Forgot about only public files on repo. How would an extension system potentialy work then?


Erik(Posted 2013) [#13]
I would really like a

DrawPoly( verts:Float[], colors:Int[] )

for simple gradients. You can do a lot with just that, think illustrator images.


Erik(Posted 2013) [#14]
Here is an XNA version of DrawRectColor as an example of what I mean:

public virtual int DrawRectColor( float x,float y,float w,float h,int col1,int col2,int col3,int col4)
  {
		if( primType!=4 || primCount==MAX_QUADS || primTex!=null ){
			Flush();
			primType=4;
			primTex=null;
		}

		float x0=x,x1=x+w,x2=x+w,x3=x;
		float y0=y,y1=y,y2=y+h,y3=y+h;

		if( tformed ){
			float tx0=x0,tx1=x1,tx2=x2,tx3=x3;
			x0=tx0 * ix + y0 * jx + tx;
			y0=tx0 * iy + y0 * jy + ty;
			x1=tx1 * ix + y1 * jx + tx;
			y1=tx1 * iy + y1 * jy + ty;
			x2=tx2 * ix + y2 * jx + tx;
			y2=tx2 * iy + y2 * jy + ty;
			x3=tx3 * ix + y3 * jx + tx;
			y3=tx3 * iy + y3 * jy + ty;
		}

		int vp=primCount++*4;

    var cl1 = new Color((byte)(col1 >> 16), (byte)(col1 >> 8), (byte)(col1 >> 0), (byte)(col1 >> 24));
    var cl2 = new Color((byte)(col2 >> 16), (byte)(col2 >> 8), (byte)(col2 >> 0), (byte)(col2 >> 24));
    var cl3 = new Color((byte)(col3 >> 16), (byte)(col3 >> 8), (byte)(col3 >> 0), (byte)(col3 >> 24));
    var cl4 = new Color((byte)(col4 >> 16), (byte)(col4 >> 8), (byte)(col4 >> 0), (byte)(col4 >> 24));

		vertices[vp  ].Position.X=x0;vertices[vp  ].Position.Y=y0;
		vertices[vp  ].Color=cl1;
		vertices[vp+1].Position.X=x1;vertices[vp+1].Position.Y=y1;
		vertices[vp+1].Color=cl2;
		vertices[vp+2].Position.X=x2;vertices[vp+2].Position.Y=y2;
		vertices[vp+2].Color=cl3;
		vertices[vp+3].Position.X=x3;vertices[vp+3].Position.Y=y3;
		vertices[vp+3].Color=cl4;

		return 0;
	}


Add DrawRectColor to graphicsdevice.mojo, graphics.mojo and the above to mojo.xna.cs then use it like this:


  Function ColorToInt:Int(r,g,b, a:Int = 255)
    Return (a Shl 24) | (r Shl 16) | (g Shl 8) | b
  End

  Method OnRender()
    Cls(0,0,0)
    DrawRectColor(MouseX,MouseY,200,200,ColorToInt(255,0,0),
                                        ColorToInt(0,255,0),
                                        ColorToInt(0,0,255),
                                        ColorToInt(255,255,255))
  End