About Monkey 2 › Forums › Monkey 2 Programming Help › Textured poly?
This topic contains 7 replies, has 3 voices, and was last updated by
Jesse
2 years, 2 months ago.
-
AuthorPosts
-
January 31, 2017 at 2:57 am #6876
Is there a way to texture a 4 point poly with an image in mojo without having to resort to using direct GL graphics?
February 2, 2017 at 9:27 am #6921Yes, take a look at at Canvas.DrawPrimitives()
http://monkey2.monkey-x.com/mx2-docs/mojo-mojo-graphics-canvas-drawprimitives/
February 2, 2017 at 12:40 pm #6923Guess I didn’t look thoroughly enough. Thanks.
I still have to figure out how to use it.February 7, 2017 at 9:07 pm #7006Little demo of drawing a full-view ‘diamond’.
The command’s a little intense because it’s supposed to handle many combinations of textured/untextured/colored/uncolored/indexed/nonindexed primitives. Uses float ptrs instead of float arrays for max flexibility too, ie: you can draw from DataBuffers etc.
Monkey12345678910'x,y verts to drawLocal verts:=New Float[]( Width/2,0,Width,Height/2,Width/2,Height,0,Height/2 )'params:'4=draw quads (3=tris, 6=hexs etc, prims must be convex!)'1=draw 1 quad.'verts.Data=float ptr to vertex data.'8=pitch, ie: bytes between one vertex and the next, 2 floats=2*4=8.canvas.DrawPrimitives( 4,1,verts.Data,8,Null,0,Null,0,Null,Null )February 8, 2017 at 3:18 pm #7020Thanks Mark. That helped a little. I am trying to plaster an image into a four sided poly or a quad.
February 8, 2017 at 4:26 pm #7021as a test I am trying to plaster an image of a rectangle with an x on it but can quite figure it out.
This is what I got:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960[crayon-5cba8c87a28dd098754989 inline="true" ]Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField image:ImageMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )image = New Image(64,64)Local icanvas:Canvas = New Canvas(image)icanvas.Clear(New Color(0,0,0,0))icanvas.Color = New Color(1,0,0,1)icanvas.LineWidth = 4icanvas.DrawLine(0,0,63,0)icanvas.DrawLine(63,0,63,63)icanvas.DrawLine(63,63,0,63)icanvas.DrawLine(0,63,0,0)icanvas.Color = New Color(0,0,1,1)icanvas.DrawLine(0,0,63,63)icanvas.Color = New Color(0,1,0,1)icanvas.DrawLine(63,0,0,63)icanvas.Flush()EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()'x,y verts to drawLocal verts:=New Float[]( Width/2,0,Width,Height/2,Width/2,Height,0,Height/2 )'params:'4=draw quads (3=tris, 6=hexs etc, prims must be convex!)'1=draw 1 quad.'verts.Data=float ptr to vertex data.'8=pitch, ie: bytes between one vertex and the next, 2 floats=2*4=8.canvas.Color = New Color(1,1,1)canvas.DrawPrimitives( 4,1,verts.Data,8,Null,0,Null,0,image,null )canvas.DrawImage(image,0,0)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndFebruary 8, 2017 at 9:25 pm #7024You need to add texture coordinates if there’s an ‘image’ param (should probably catch this…)
Texture coordinates represent coordinates within the image, where 0,0=top left, 1,0=top right, 1,1=bottom right, 0,1=bottom left, and fractional values are coordinates somewhere in between, eg: .5,.5= center.
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField image:ImageMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )image = New Image(64,64)Local icanvas:Canvas = New Canvas(image)icanvas.Clear(New Color(0,0,0,0))icanvas.Color = New Color(1,0,0,1)icanvas.LineWidth = 4icanvas.DrawLine(0,0,63,0)icanvas.DrawLine(63,0,63,63)icanvas.DrawLine(63,63,0,63)icanvas.DrawLine(0,63,0,0)icanvas.Color = New Color(0,0,1,1)icanvas.DrawLine(0,0,63,63)icanvas.Color = New Color(0,1,0,1)icanvas.DrawLine(63,0,0,63)icanvas.Flush()EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()'x,y verts to draw.Local verts:=New Float[]( Width/2,0,Width,Height/2,Width/2,Height,0,Height/2 )'s,t tex coordinates.Local texcoords:=New Float[]( 0,0,1,0,1,1,0,1 )'params:'4=draw quads (3=tris, 6=hexs etc, prims must be convex!)'1=draw 1 quad.'verts.Data=float ptr to vertex data.'8=verts pitch, ie: bytes between one vertex and the next, 2 floats=2*4=8.'texcoords.Data=float ptr to texture coordinates.'8 texcoords pitch...canvas.Color = New Color(1,1,1)canvas.DrawPrimitives( 4,1,verts.Data,8,texcoords.Data,8,Null,0,image,null )canvas.DrawImage(image,0,0)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndFebruary 8, 2017 at 11:46 pm #7035Thanks, That works perfect.
-
AuthorPosts
You must be logged in to reply to this topic.