c# - Draw Rectangle in MonoGame -


How do you draw shapes in mono games, such as rectangular and circles, save a preceding shape in the content folder?

DrawRectangle () and DrawEllipse () are for Windows Forms and do not work in OpenGL, which is what I am using.


"text">

Using 3D primitives and 2D projection

is a simple example with explanation

I have a 10x10 I define the rectangle and set the world matrix to make it look like a 2D projection:

Note: BasicEffect that draws your primitive

  su Protected Override Zero Load Contents () {_vertexPositionColors = new [] {New Vertxposition Collar (New Vector 3 (0, 0, 1), Color. White), New VertixPopiapolar (New Vector 3 (10, 0, 1), Color. White), New VertexPaPaPolar (new vector 3 (0, 10, 1), color. White), new vortexation collar (new vector 3 (0, 10, 1), color. White)}; _basicEffect = new basic incomplete ( Graphics device); _basicEffect.World = Matrix.CreateOrthographicOffCenter (0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1); }   

Then I draw the whole thing: D

  Secure Override Zero Draw (GameTime GameTime) {GraphicsDevice.Clear (Color.CornflowerBlue); Infotechnical EffectsTechnic = _basicEffect.Techniques [0]; ImpactPasswordPrintPashControl = EffectTechnic.pass; Foresh (Effect with Effect Pass Pass) {Pass. Applicable (); Graphics Device. Drawer Pritimitivs (Premit Type. Linestrip, _WorTexProject Corollor, 0, 4); } Base.Draw (gametime); }   

There your rectangle is there!

Enter image details here

Now it

  • To draw fill rectangles: Attract basic elements of 2 triangle
  • See for an ellipse / circle : And

    Or as mentioned in the above steps, you can use a shider instead ...

    I'm coming first and need to scanning this shider:

    < P> As you can see in the post a superheripas not only pulls the oval but other sizes and perhaps the circles (I did not test) so that you can take an interest in it.

    Eventually, you will want some sections / methods to hide all of these details so that you just DrawCircle () .

    Tip: By posting you will get more answers for monogame-related questions

    : D



Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -