Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

XNA Draw pixel on screen

Can someone write me a quick XNA C# function to render pixels to the screen at any given screen coordinate?
Example:
Code:
renderPixel(x, y, color.pink);
The reason I want this is because I have a screen buffer of colours for each pixel on the screen and I can find no way of converting that to a texture2D to use, so I'm looking for a way to do:
Code:
 

for (int x =1; x<800; x++)

{

    for (int y =1; y<600; y++)

    {

        renderPixel(x, y, buffer[x, y]);

    }

}

 
 

Tdata

Sponsor

Code:
 

 

Color[,] Screen = new Color[800,600]

 

Bitmap Bmp = new Bitmap(800, 600);

for (int x = 0; x < 800; x++)

{

   for (int y = 0; y < 600; y++)

   {

      Bmp.SetPixel(x, y, Screen[x, y]);

   }

}

 

By a screen buffer I assume that you mean that you have an array of colors.
 
The best way is to import several different 1x1 graphics and draw them that way. Or you could even import a 1x1 White pixel. Then when you could try and do something like this.
Code:
Texture2D pixel;

private override LoadContent()

{

    pixel = Content.Load<Texture2D>("white_pixel");

}

private override Draw(GameTime gameTime)

{

    spriteBatch.Draw(pixel, Vector2 position, Color.Blue);

}

Not sure if adding the color blend will do anything but its a thought.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top