Computer graphics in Game development
Ivan Belyavtsev
24.10.2020
[1]
Let’s implement it together
Idea: sort all triangles from farthest to nearest from camera [2]
Let’s implement it together
vector<color> frame_buffer;
vector<float> depth_buffer; //+Infs, for instance
void SetPixel(unsigned short x, unsigned short y, float z, color color)
{
frame_buffer[y * width + x] = color;
depth_buffer[y * width + x] = z;
}
[2]
bool DepthTest(unsigned short x, unsigned short y, float z)
{
return z < depth_buffer[y * width + x]; //Depends on Z-axis directions
}
void SetPixel(unsigned short x, unsigned short y, float z, color color)
{
if (DepthTest(x, y, z))
{
frame_buffer[y * width + x] = color;
depth_buffer[y * width + x] = z;
}
}
[2]
Let’s implement it together