Skip to content

Commit ee0cb90

Browse files
committed
add lighting
1 parent add7eaa commit ee0cb90

File tree

13 files changed

+324
-264
lines changed

13 files changed

+324
-264
lines changed

CMakelists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required (VERSION 3.8)
22

3-
project ("mini_renderer")
3+
project ("mini_renderer" LANGUAGES C CXX)
44

55
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
66

source/CMakelists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ file(GLOB SOURCES
88
"*.cpp"
99
)
1010

11-
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
11+
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} "renderer.cpp" "math.cpp")
1212

1313
target_link_libraries(${PROJECT_NAME} SDL2 SDL2main SDL2_image SDL2_mixer SDL2_ttf)
1414
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/deps/includes ${CMAKE_SOURCE_DIR}/deps/includes/glm/glm)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#pragma once
22

3+
#include <stdint.h>
4+
35
#define WHITE 0xFFFFFFFF
46
#define BLACK 0xFF000000
57
#define RED 0xFFFF0000
68
#define GREEN 0xFF00FF00
79
#define BLUE 0xFF0000FF
810
#define YELLOW 0xFFFFFF00
911
#define GRAY 0xFF808080
10-
#define PINK 0xFFFF00FF
12+
#define PINK 0xFFFF00FF
13+
14+
#define uint32 uint32_t

source/framebuffer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "framebuffer.hpp"
22

3-
FrameBuffer::FrameBuffer(uint32_t* pixels, float width, float height) : pixels(pixels), width(width), height(height)
3+
FrameBuffer::FrameBuffer(uint32* pixels, float width, float height) : pixels(pixels), width(width), height(height)
44
{
55
numOfPixels = width * height;
66
}
77

8-
void FrameBuffer::DrawPixel(int x, int y, uint32_t Color)
8+
void FrameBuffer::DrawPixel(int x, int y, uint32 Color)
99
{
1010
if (x >= 0 && x < width && y >= 0 && y < height)
1111
{
@@ -14,7 +14,7 @@ void FrameBuffer::DrawPixel(int x, int y, uint32_t Color)
1414
}
1515
}
1616

17-
void FrameBuffer::DrawLine(int x0, int y0, int x1, int y1, uint32_t Color)
17+
void FrameBuffer::DrawLine(int x0, int y0, int x1, int y1, uint32 Color)
1818
{
1919
for (float t = 0.; t < 1.; t += .01) {
2020
int x = (x1 - x0) * t + x0;
@@ -23,7 +23,7 @@ void FrameBuffer::DrawLine(int x0, int y0, int x1, int y1, uint32_t Color)
2323
}
2424
}
2525

26-
void FrameBuffer::DrawLineDDA(int x0, int y0, int x1, int y1, uint32_t Color)
26+
void FrameBuffer::DrawLineDDA(int x0, int y0, int x1, int y1, uint32 Color)
2727
{
2828
int DeltaX = (x1 - x0);
2929
int DeltaY = (y1 - y0);
@@ -44,7 +44,7 @@ void FrameBuffer::DrawLineDDA(int x0, int y0, int x1, int y1, uint32_t Color)
4444
}
4545
}
4646

47-
void FrameBuffer::DrawLineBresenham(int x0, int y0, int x1, int y1, uint32_t Color)
47+
void FrameBuffer::DrawLineBresenham(int x0, int y0, int x1, int y1, uint32 Color)
4848
{
4949
bool steep = false;
5050
if (std::abs(x0 - x1) < std::abs(y0 - y1)) {
@@ -77,7 +77,7 @@ void FrameBuffer::DrawLineBresenham(int x0, int y0, int x1, int y1, uint32_t Col
7777
}
7878
}
7979

80-
void FrameBuffer::DrawRect(int x, int y, int width, int height, uint32_t color)
80+
void FrameBuffer::DrawRect(int x, int y, int width, int height, uint32 color)
8181
{
8282
for (int i = 0; i < width; i++)
8383
{
@@ -90,14 +90,14 @@ void FrameBuffer::DrawRect(int x, int y, int width, int height, uint32_t color)
9090
}
9191
}
9292

93-
void FrameBuffer::DrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t Color)
93+
void FrameBuffer::DrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32 Color)
9494
{
9595
DrawLineBresenham(x0, y0, x1, y1, Color);
9696
DrawLineBresenham(x1, y1, x2, y2, Color);
9797
DrawLineBresenham(x2, y2, x0, y0, Color);
9898
}
9999

100-
void FrameBuffer::DrawFilledTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t Color)
100+
void FrameBuffer::DrawFilledTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32 Color)
101101
{
102102
if (y0 > y1)
103103
{
@@ -137,7 +137,7 @@ void FrameBuffer::DrawFilledTriangle(int x0, int y0, int x1, int y1, int x2, int
137137

138138
}
139139

140-
void FrameBuffer::DrawFlatBottomTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t Color)
140+
void FrameBuffer::DrawFlatBottomTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32 Color)
141141
{
142142
float leftLine = (float)(x1 - x0) / (y1 - y0);
143143
float rightLine = (float)(x2 - x0) / (y2 - y0);
@@ -153,7 +153,7 @@ void FrameBuffer::DrawFlatBottomTriangle(int x0, int y0, int x1, int y1, int x2,
153153
}
154154
}
155155

156-
void FrameBuffer::DrawFlatTopTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t Color)
156+
void FrameBuffer::DrawFlatTopTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32 Color)
157157
{
158158
float leftLine = (float)(x2 - x0) / (y2 - y0);
159159
float rightLine = (float)(x2 - x1) / (y2 - y1);
@@ -168,7 +168,7 @@ void FrameBuffer::DrawFlatTopTriangle(int x0, int y0, int x1, int y1, int x2, in
168168
}
169169
}
170170

171-
void FrameBuffer::ClearFrameBuffer(uint32_t Color)
171+
void FrameBuffer::ClearFrameBuffer(uint32 Color)
172172
{
173173
for (int y = 0; y < height; y++)
174174
{

source/framebuffer.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#pragma once
22
#include <iostream>
33
#include <SDL2/SDL.h>
4+
#include "common.hpp"
45

56
struct FrameBuffer
67
{
7-
uint32_t* pixels;
8+
uint32* pixels;
89
float numOfPixels;
910
float width;
1011
float height;
1112

12-
FrameBuffer(uint32_t* pixels, float width, float height);
13-
void DrawPixel(int x, int y, uint32_t Color);
14-
void DrawLine(int x0, int y0, int x1, int y1, uint32_t Color);
15-
void DrawLineDDA(int x0, int y0, int x1, int y1, uint32_t Color);
16-
void DrawLineBresenham(int x0, int y0, int x1, int y1, uint32_t Color);
17-
void DrawRect(int x, int y, int width, int height, uint32_t color);
18-
void DrawTriangle(int x0, int y0,int x1,int y1, int x2, int y2, uint32_t Color);
19-
void DrawFilledTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t Color);
20-
void DrawFlatBottomTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t Color);
21-
void DrawFlatTopTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t Color);
22-
void ClearFrameBuffer(uint32_t Color);
13+
FrameBuffer(uint32* pixels, float width, float height);
14+
void DrawPixel(int x, int y, uint32 Color);
15+
void DrawLine(int x0, int y0, int x1, int y1, uint32 Color);
16+
void DrawLineDDA(int x0, int y0, int x1, int y1, uint32 Color);
17+
void DrawLineBresenham(int x0, int y0, int x1, int y1, uint32 Color);
18+
void DrawRect(int x, int y, int width, int height, uint32 color);
19+
void DrawTriangle(int x0, int y0,int x1,int y1, int x2, int y2, uint32 Color);
20+
void DrawFilledTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32 Color);
21+
void DrawFlatBottomTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32 Color);
22+
void DrawFlatTopTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32 Color);
23+
void ClearFrameBuffer(uint32 Color);
2324
};

source/main.cpp

Lines changed: 0 additions & 222 deletions
This file was deleted.

0 commit comments

Comments
 (0)