Setting up the back buffer:
Code: Select all
BackBuffer = malloc(framebuffer->Width * framebuffer->Height * 4);
Code: Select all
void Graphics::draw_pixel(int x, int y, int color)
{
*(unsigned int*)((unsigned int*)BackBuffer + x + (y * buffer->PixelsPerScanLine)) = color;
}
void Graphics::draw_rect(int x, int y, int w, int h, int color)
{
for (int Y = y; Y < y + h; Y++)
{
for (int X = x; X < x + w; X++)
{
draw_pixel(X, Y, color);
}
}
}
Code: Select all
memcpy((uint64_t*)buffer->BaseAddress, (uint64_t*)BackBuffer, buffer->Width * buffer->Height * 4);
Code: Select all
void* memcpy(uint64_t* dest, uint64_t* source, int count)
{
for (int i = 0; i < count; i++)
{
dest[i] = source[i];
}
return dest;
}
Code: Select all
g.draw_rect(0, 0, 50, 50, 0xFFFFFF);
g.update(); // Draws white square successfully but then freezes the system
// This doesn't draw!
g.draw_rect(0, 0, 50, 50, 0xFF0000);
g.update();