create texture

May 7, 2009 at 7:03 PM
how can i create a polygon texture,
I found functions that helped me to create Circle,Rectangle and Ellipse Texture2d..
can any one help me how to create a triangle texture.
thank you.
Developer
May 7, 2009 at 8:51 PM
@nidall: There actually is no helper to create a polygon texture. I think I will put this on the list of things to include in the 2.1 release. Until then if you download the latest source code check in and take a look at the XNA Water Demo you will see a method for drawing custom polygons (the water is actually a triangle strip). Or you can use PhysicsSimulatorView and set EnableEdgeView to true to see the outline of your polygon. I hope this helps.
May 8, 2009 at 6:35 AM

Hi nadall

I havent looked at matt's code yet, but try using Triangulation, I used it for rendering my water, and you can use it with any shape.

What you do is pass an array of points making a shape and it will transform it into an array of triangles for rendering. Usefull for anyone wanting to draw complex shapes without using textures.

http://xnawiki.com/index.php?title=Polygon_Triangulation
(note: You must apply the fixes noted in the discussion or there are errors)

Theres also this:

http://www.codeplex.com/triangulator

It was on Ziggyware (I think someone also mentioned it in a previous post somewhere) and it does the same thing but has some extras too, like cutting out a hole in a shape.

Hope that helps.

Developer
May 8, 2009 at 11:57 AM

@nidall: I will be adding the Triangulator to the Demos DrawingSystem and finishing up the PolyBrush tonight.

@robertdodd: Triangulation shouldn't be nessesary when drawing the water. I'm not using any triangulation when drawing my water and it renders perfectly. How are you rendering your water? Would you mind sending me a copy of your project so I can see how you have everything implemented, mostly just to see if where both missing something.

May 8, 2009 at 8:18 PM

@ robertdodd: thank you for these ideas.

@matt: I started writing simple function to do Triangle, but it worked only when the triangle is 90 degrees.

I will bw waiting your code, Thank you very much, I hope it will be able to draw polygon as well.

Thank you

Coordinator
May 8, 2009 at 9:39 PM

@Matt. Maybe it should be made generic and included in the vertices class?

I was in the progress of looking over the earclip code from the codeplex site. I've had a look at it before in the Box2D project, but the codeplex code seems perfect.

May 8, 2009 at 10:59 PM

 @Maatt: I downloaded PolyBrush (change set 49872), but I didnt find what I need.

can u explain to me how to use it to creatr Polygon Texture,

Thanks

Developer
May 8, 2009 at 11:56 PM

@nidall: I believe I put it in the DrawingSystem folder for the XNA Simple Demos. It works just like the other brushes. Create it. Load it. Draw it. When I am finished I will include a sample. Right now I only need to add the triangulation code and maybe a custom shader.

May 9, 2009 at 3:27 AM

Matt: EXCELLENT! I tried your rendering teqhnique and it works perfectly! Way faster than triangulating it every step! Thanks a lot!

Coordinator
May 9, 2009 at 11:59 AM

@mattbettcher:

Great work on the polygonbrush. It needs to use the position and rotation given to the draw methods tho.

Also, I made a few minor edits to the polygon brush, you can see the updated version in AdvancedSamples DrawingSystem folder. It uses position and rotation and I moved the vertice color and position code into a property.

Demo8 in AdvancedSamples now use the polygon brush, but there are some bugs somewere. The border is not drawn correctly and when using it on the polygons created by Demo8, it draws out of bounds of the polygon.

Developer
May 9, 2009 at 4:39 PM

@robertdodd: Your welcome. I strive to increase the quality of Farseer.

@genbox: Thanks, I will probably finish that up tonight or tomarrow. Had to get tattoed this morning. The rendering error is because it currently doesn't draw concave polygons correctly, hence the need for the triangulation. Also I need to add a custom shader for drawing lines so I can add a border thickness option. And I want to rewrite the current LineBrush and RectangleBrush to use a cache and a shader, it will probably be less complex and rendering should be way faster and with more options.

Coordinator
May 9, 2009 at 8:08 PM

Mattbettcher: Sounds great. My ideas for a polygon drawing helper were a lot simpler, but probably also a lot slower. Looking forward to see it in action.

May 10, 2009 at 4:11 AM

I just found that the water rendering doesnt work when the nodecount is an odd number, but that shouldnt be too hard for you to fix.

Also another thing that might be good to implement is the ability to draw the water with a gradient.

May 10, 2009 at 6:36 PM

Hi I used PolyBrush finction and it worked... but it gives me wrong positions when I draw it, the error is relative "when i draw at 0,0 it work, but any where else it gives me wrong poistions",

is there a difference to use brush,load and draw it, from creating texture. does it hard to draw CreateTriangleTexture Function.

i wrote a simple code that create 90 degrees Triangle:

 

public static Texture2D CreateTriangleTexture(GraphicsDevice graphicsDevice, int Hieght,int Width,Color color, Color borderColor)
        {
            Texture2D Tri;
            float step=0;
            float y = 0;
            Color[] colors;
            {
                Tri = new Texture2D(graphicsDevice, Hieght, Width, 1, TextureUsage.None,SurfaceFormat.Color);
                step = (float)Hieght / Width;
                colors = new Color[Hieght * Width];
                int a = 0;
                for (int i = 0; y < Hieght; i++)
                {
                    for (int x = 0; x < Hieght; x++)
                    {

                        if (a >= Hieght * Width)
                        {
                            break;
                        }
                            if (x <= y)
                            {
                                if (a == 0 || a == 1)
                                    colors[a] = borderColor;
                                else
                                    colors[a] = color;
                            }
                            else
                                colors[a] = Color.TransparentBlack;

                       

                        a++;
                    }
                    y += step;

                }
            }
            Tri.SetData(colors);
            return Tri;
        }

 

Thank you

Developer
May 10, 2009 at 10:44 PM

@nidall: The PolygonBrush is still not finished. I attempting a reorganization of most of the DrawingSystem to make much easier to use and much more portable.