57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using Raylib_cs;
|
|
|
|
class SoftwareRasterizer
|
|
{
|
|
|
|
const int screenWidth = 1280 * 2;
|
|
const int screenHeight = 800 * 2;
|
|
|
|
const int scale = 8;
|
|
|
|
private RenderDevice renderer;
|
|
|
|
static void Main()
|
|
{
|
|
SoftwareRasterizer sr = new SoftwareRasterizer();
|
|
sr.start();
|
|
}
|
|
|
|
public void start()
|
|
{
|
|
|
|
Raylib.InitWindow(screenWidth, screenHeight, "Software Rasterizer");
|
|
Raylib.SetTargetFPS(0);
|
|
|
|
renderer = new RenderDevice(screenWidth / scale, screenHeight / scale, screenWidth, screenHeight);
|
|
|
|
int frameCounter = 0;
|
|
|
|
Random rand = new Random();
|
|
|
|
while (!Raylib.WindowShouldClose())
|
|
{
|
|
for (int i = 0; i < renderer.height; i++)
|
|
{
|
|
for (int j = 0; j < renderer.width; j++)
|
|
{
|
|
renderer.SetPixel(j, i, new float3((j / (float)(renderer.width)) * 255, (i / (float)(renderer.height)) * 255, rand.Next(1,256)));
|
|
}
|
|
}
|
|
// Render
|
|
Raylib.BeginDrawing();
|
|
Raylib.ClearBackground(Color.Black);
|
|
//
|
|
renderer.render();
|
|
//
|
|
Raylib.DrawText($"FPS: {Raylib.GetFPS()}", 10, 10, 20, Color.White);
|
|
Raylib.EndDrawing();
|
|
frameCounter += 2;
|
|
}
|
|
|
|
// Cleanup
|
|
renderer.cleanup();
|
|
Raylib.CloseWindow();
|
|
}
|
|
}
|
|
|