]> git.localhorst.tv Git - blobs.git/blob - src/graphics/viewport.cpp
simple planet render
[blobs.git] / src / graphics / viewport.cpp
1 #include "Camera.hpp"
2 #include "Viewport.hpp"
3
4 #include "const.hpp"
5
6 #include <GL/glew.h>
7 #include <glm/gtx/transform.hpp>
8
9
10 namespace blobs {
11 namespace graphics {
12
13 Camera::Camera() noexcept
14 : fov(PI_0p25)
15 , aspect(1.0f)
16 , near(0.1f)
17 , far(256.0f)
18 , projection(glm::perspective(fov, aspect, near, far))
19 , view(1.0f) {
20
21 }
22
23 Camera::~Camera() noexcept {
24 }
25
26 void Camera::FOV(float f) noexcept {
27         fov = f;
28         UpdateProjection();
29 }
30
31 void Camera::Aspect(float r) noexcept {
32         aspect = r;
33         UpdateProjection();
34 }
35
36 void Camera::Aspect(float w, float h) noexcept {
37         Aspect(w / h);
38 }
39
40 void Camera::Clip(float n, float f) noexcept {
41         near = n;
42         far = f;
43         UpdateProjection();
44 }
45
46 void Camera::View(const glm::mat4 &v) noexcept {
47         view = v;
48 }
49
50 void Camera::UpdateProjection() noexcept {
51         projection = glm::perspective(fov, aspect, near, far);
52 }
53
54
55 Viewport::Viewport(int w, int h)
56 : width(w)
57 , height(h) {
58         Resize(w, h);
59         glClearColor(0.0, 0.0, 0.0, 1.0);
60 }
61
62 Viewport::~Viewport() {
63 }
64
65
66 void Viewport::Resize(int w, int h) {
67         width = w;
68         height = h;
69         glViewport(0, 0, w, h);
70 }
71
72 void Viewport::Clear() {
73         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
74 }
75
76 }
77 }