diff --git a/raycaster.c b/raycaster.c index 0b82724..2b695c0 100644 --- a/raycaster.c +++ b/raycaster.c @@ -397,13 +397,58 @@ void drawRays3D() } } +// * Draw ceiling +void drawCeiling() +{ + float halfHeight = (float)(gameHeight / 2); + + glBegin(GL_QUADS); + for (float distance = 0; distance < halfHeight; distance += 1.0f) + { + // Normalize color from 0.0 to 1.0 based on distance, multiplied by relative intensity + float colorIntensity = 0.5f + (distance / halfHeight); + glColor3f(0.25 * colorIntensity, 0.25 * colorIntensity, 0.25 * colorIntensity); + + // Draw a horizontal strip at the current distance + glVertex2f(MAP_WIDTH + GAP, distance); + glVertex2f(MAP_WIDTH + GAP, distance + 1.0f); + glVertex2f(TOTAL_WIDTH, distance + 1.0f); + glVertex2f(TOTAL_WIDTH, distance); + } + glEnd(); +} + +// * Draw floor +void drawFloor() +{ + float halfHeight = (float)(gameHeight / 2); + + glBegin(GL_QUADS); + for (float distance = 0; distance < halfHeight; distance += 1.0f) + { + + float colorIntensity = 0.5f + (distance / halfHeight); + glColor3f(0.25 * colorIntensity, 0.25 * colorIntensity, 0.0f); + + float y = halfHeight + distance; + glVertex2f(MAP_WIDTH + GAP, y); + glVertex2f(MAP_WIDTH + GAP, y + 1.0f); + glVertex2f(TOTAL_WIDTH, y + 1.0f); + glVertex2f(TOTAL_WIDTH, y); + } + glEnd(); +} + // * Main rendering void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + drawCeiling(); + drawFloor(); drawMap2D(); drawRays3D(); drawPlayer(); + glutSwapBuffers(); }