Textured Polys : DirectX only at moment
BlitzMax Forums/BlitzMax Module Tweaks/Textured Polys : DirectX only at moment
| ||
Can't be arsed to do a GL version since I'm not going to use it. Make these changes and then "bmk makemods" Driver.bmx Type TImageFrame Method DrawTexturedPoly (xyuv#[],x1#,y1#,tx#,ty#) Abstract Add this function to Max2d.bmx Rem bbdoc: Draw a Textures polygon about: #DrawPoly draws a Textures polygon with corners defined by an array of x#,y#,u#,v# coordinates.<p> BlitzMax commands that affect the drawing of polygons include #SetColor, #SetHandle, #SetScale, #SetRotation, #SetOrigin, #SetViewPort, #SetBlend and #SetAlpha. End Rem Function DrawTexturedPoly( image:TImage,xyuv#[],frame=0) image.Frame(frame).DrawTexturedPoly xyuv,handle_x,handle_y,origin_x,origin_y End Function In glmax2d.bmx add this method to Type TGLImageFrame: Method DrawTexturedPoly (xyuv#[],x1#,y1#,tx#,ty#) ' Not done for OGL yet End Method In d3d7max2d.bmx add this method to Type TD3D7Max2DDriver Method DrawTexturedPoly( frame:TDX7ImageFrame,xyuv#[],handlex#,handley#,tx#,ty# ) If islost Return If xyuv.length<6 Or (xyuv.length&1) Return Local segs=xyuv.length/2 Local uv#[] = New Float[segs*10] '10 Local ii:Int = 0 For Local i=0 Until Len(xyuv) Step 4 Local x# = xyuv[i+0]+handlex Local y# = xyuv[i+1]+handley uv[ii+0] = x*ix+y*iy+tx uv[ii+1] = x*jx+y*jy+ty uv[ii+2] = 0 ' *********** THIS IS THE Z-COORDINATE uv[ii+3] = xyuv[i+2] uv[ii+4] = xyuv[i+3] ii:+5 Next SetActiveFrame frame device.DrawPrimitive(D3DPT_TRIANGLEFAN,D3DFVF_XYZ|D3DFVF_TEX1,uv,segs,0) End Method Now add this Method to Type TDX7ImageFrame Method DrawTexturedPoly(xyuv#[],x1#,y1#,tx#,ty# ) driver.DrawTexturedPoly Self,xyuv,x1#,y1#,tx#,ty# End Method Do the MakeMods stuff and now you can make 2d polygons with any texture you desire. EXAMPLE : http://www.blitzbasic.com/Community/posts.php?topic=51042 |
| ||
Hi there, after following Indiepath's steps above, you can use the following method in glmax2d.bmx so the DrawTexturedPoly() command will work with GL drivers too. Method DrawTexturedPoly (xy#[],handle_x#,handle_y#,origin_x#,origin_y#) If xy.length<6 Or (xy.length&1) Return Assert seq=_max2dGfxSeq Else "Image does not exist" EnableTex name glBegin GL_POLYGON For Local i=0 Until Len xy Step 4 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 End Method |
| ||
Sweet. thanks, both of you. |
| ||
I think I will rebuild this so that you don't need to recompile the max2d module. |
| ||
Hi Indie, don't know if this is a drawtexturepoly problem, or a common problem with textured triangles. On the screenie below I try to draw an textured trapezoid. But texture UVs are, I think, correct but not displayed nice. Do you know a way to draw a trapezoid with nice displayed texture? That would give a cool feature for the shadow system... ![]() |
| ||
Ouch, This is a UV issue as there is no perspective correction. The only way I can think to overcome it would be in increase the amount of polys in the trapezoid, thus increasing the number of uv's. You may also want to change the way the poly is constructed, at the moment it uses trianglefans which are not really suited to the job you need them to do. |
| ||
"Bump" I just came along the same method. (OpenGL) If someone is going to use this for OpenGL must keep in mind that OpenGL uses square images in the power of 2. So the images are: 2 x 2 4 x 4 16 x 16 64 x 64 128 x 128 256 x 256 512 x 512 Don't go further, you may have problems. |
| ||
I wrote an function which can draw a textured poly without modifying any modules(OpenGL onyl): The DrawImage at the end lets GLMax2D change his current internal texture, so you can normaly Draw other images after a call to this function. |
| ||
http://modules.indiepath.com - should have gone there it would have saved you some time. |
| ||
Sorry, but i wasn't able compile the Module on my System. |
| ||
BORNtobeNAMELESS How do I call it ? Function DrawTexturedPoly(tex:TImage,xyuv:Float[],rgba:Int[]=Null,frame:Int=0) DRawtexturedpoly (Texture,100,100,20,20, 122,2? What is frame? |
| ||
You dont seem to need perspective correction, you need to specify the appropriate texture coordinates based on the coordinates of the vertices rather than stretching the polygon image. Also I wonder if a proper `quad` would correct this error. |
| ||
Why DirectX mode is work no correct?'SetGraphicsDriver GLMax2DDriver() uncoment to view right drawing Graphics 800,600 Local Image:TImage = LoadImage("clock.png") SetBlend alphablend Local xyuv:Float[] = [ .. 100.0,100.0, 0.5, 0.5,.. 100.0, 36.0, .5, 0.0, .. 145.2, 54.0, .85, 0.14 ] DrawTexturedPoly Image, xyuv |
| ||
Ops... I find bug.Local segs=xyuv.length/2 repalce to Local segs=xyuv.length/4 |
| ||
If your'e using the code in this thread then it's over a year old and has changed a lot. You should consider getting the latest from Tim's forums |
| ||
my edition. Without changes to modules. With sources ;) http://www.blitzmax.com/codearcs/codearcs.php?code=1812 |