-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.hpp
More file actions
65 lines (51 loc) · 1.67 KB
/
renderer.hpp
File metadata and controls
65 lines (51 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef RENDERER_H
#define RENDERER_H
#include "camera.hpp"
#include "mesh.hpp"
#include "string_utils.hpp"
#include "triangle.hpp"
#include <SDL3/SDL.h>
#include <chrono>
#include <iostream>
constexpr float FPS_30 = 30.0f;
constexpr float FPS_60 = 60.0f;
constexpr float FRAME_TARGET_TIME_NS = (1.0f / FPS_60) * 1.0e+9f;
enum DisplayFlags {
Vertices = 0x01,
Wireframe = 0x02,
PolygonFill = 0x04,
BackfaceCulling = 0x08,
};
class Renderer {
using enum DisplayFlags;
public:
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Texture* texture;
const SDL_DisplayMode* display_mode;
int w;
int h;
std::vector<uint32_t> c_buf;
std::vector<Mesh> meshes;
Camera camera;
SDL_Event event;
std::vector<Triangle> triangles;
uint64_t prev_frame_time;
// Vec3 global_rot;
uint8_t flags;
Renderer() = default;
void initialize(std::string title, std::string mesh_path);
bool process_input();
void deinitialize();
Vec2 project_orthographic(const Vec3& p) noexcept;
Vec2 project_perspective(const Vec3& p) noexcept;
void update();
void render();
void draw_grid(uint32_t color) noexcept;
void clear_buffer() noexcept;
void draw_pixel(int x, int y, uint32_t color) noexcept;
void draw_line_dda(int x1, int y1, int x2, int y2, uint32_t color) noexcept;
void draw_triangle(const Triangle& t, uint32_t fill_color, uint32_t wire_color, uint32_t vertex_color) noexcept;
void draw_rectangle(int x, int y, int width, int height, uint32_t color) noexcept;
};
#endif