Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4273494
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:43:14+00:00 2026-05-21T07:43:14+00:00

In another thread on XNA, Callum Rogers wrote some code which creates a texture

  • 0

In another thread on XNA, Callum Rogers wrote some code which creates a texture with the outline of a circle, but I’m trying to create a circle filled with a color. What I have to modify on this code to fill the circle with color?

public Texture2D CreateCircle(int radius)
{
    int outerRadius = radius*2 + 2; // So circle doesn't go out of bounds
    Texture2D texture = new Texture2D(GraphicsDevice, outerRadius, outerRadius);

    Color[] data = new Color[outerRadius * outerRadius];

    // Colour the entire texture transparent first.
    for (int i = 0; i < data.Length; i++)
        data[i] = Color.Transparent;

    // Work out the minimum step necessary using trigonometry + sine approximation.
    double angleStep = 1f/radius;

    for (double angle = 0; angle < Math.PI*2; angle += angleStep)
    {
        // Use the parametric definition of a circle: http://en.wikipedia.org/wiki/Circle#Cartesian_coordinates
        int x = (int)Math.Round(radius + radius * Math.Cos(angle));
        int y = (int)Math.Round(radius + radius * Math.Sin(angle));

        data[y * outerRadius + x + 1] = Color.White;
    }

    texture.SetData(data);
    return texture;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:43:15+00:00Added an answer on May 21, 2026 at 7:43 am

    Don’t use a texture for stuff like this (especially for things being in one single color!) – also don’t try to do it pixel by pixel. You’ve got 3D acceleration for a reason.

    Just draw the circle similar to a pie using a triangle fan. You’ll need the following vertices.

    • Center of the circle
    • x points on the circle’s border.

    The first two points will define a line between the center of the circle and its border. The third vertex will define the first polygon. Vertices 1, 3 and 4 will then define the second polygon, etc.

    To get the points on the circle’s border use the formulas from your example. The first angle will be 0°, the following ones multiples of (360° / points on circle). To get a full circle you’ll need one additional point that matches the second point (the first point on the border).

    Depending on the number of vertices on the circle you’ll get different n-gons. The more vertices you use the rounder the shape will look (at some performance cost):

    • (Less than 2 vertices aren’t possible as a polygon requires at least 3 vertices to be drawn.)
    • Total of 4 points (3 points on circle) will result in a triangle.
    • Total of 5 points (4 point on circle) will result in a square.
    • Total of 6 points (5 points on circle) will result in a pentagon
    • …

    Actually the XNA example for drawing primites show how to draw a circle (or n-gon) using a triangle fan.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There was another thread about this , which I've tried. But there is one
I have called a native program which creates another thread, which attaches itself to
I got this code off another thread on here and it works perfectly, but
[Note: There is another thread about this problem but it did not answer the
I originally started this question in another thread, but that thread was sorta, kinda
I am tring to setText in another thread, that is, child thread. But for
I made another thread which solved my problem, however I got the report reviewed
I saw this bit of code in another thread void foo { int *n
This is the code from another thread. It activates a function only when the
Had another thread regarding this but it wasn't resolved probably because I wasn't very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.