直接上代码:
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
int ScreenSizeX = 200;
int ScreenSizeY = 100;
ofstream fout("OutputImage.ppm");
fout << "P3\n" << ScreenSizeX << " " << ScreenSizeY << "\n255\n";
cout << "开始渲染" << endl;
for (int j = ScreenSizeY - 1; j >= 0; j--)
{
for (int i = 0; i < ScreenSizeX; i++)
{
int ir = int(255.99f * 1);
int ig = int(255.99f * 1);
int ib = int(255.99f * 0);
fout << ir << " " << ig << " " << ib << "\n";
}
}
cout << "渲染完毕" << endl;
fout.close();
return 0;
}
可以用Photoshop打开
还可以直接这样在上面画东西。
其实这就是个基于cpu的管线追踪渲染器了。