Files
Raster3D/Raster3D/Renderer.cs
T
2026-07-28 15:11:50 -05:00

39 lines
1.3 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Raster3D.Engine.Graphics;
namespace Raster3D.Engine
{
public class Renderer
{
private Texture2D _frameBufferTexture;
private Color[] _colorData;
public void RenderFrame(Pixel[] pixels, SpriteBatch batch, GraphicsDevice device, int width, int height)
{
if (_frameBufferTexture == null || _frameBufferTexture.Width != width || _frameBufferTexture.Height != height)
{
_frameBufferTexture?.Dispose();
_frameBufferTexture = new Texture2D(device, width, height);
_colorData = new Color[width * height];
}
for (int i = 0; i < _colorData.Length; i++)
{
_colorData[i] = Color.Black;
}
foreach (var p in pixels)
{
if (p.X >= 0 && p.X < width && p.Y >= 0 && p.Y < height)
{
int index = (p.Y * width) + p.X;
_colorData[index] = new Color(p.color.r, p.color.g, p.color.b, 1.0f);
}
}
_frameBufferTexture.SetData(_colorData);
batch.Draw(_frameBufferTexture, Vector2.Zero, Color.White);
}
}
}