leistungsnachweis-dingo
watch3d.h
1 #ifndef WATCH_3D_H
2 #define WATCH_3D_H
3 
4 #include "TypeDef.h"
5 
6 #include <stdio.h>
7 #include <vector>
8 
9 #include <GL/glew.h>
10 
11 #include <glm.hpp>
12 #include <gtc/matrix_transform.hpp>
13 
14 #include "Chunk.h"
15 
16 struct Camera
17 {
18  glm::vec3 pos;
19  glm::vec3 target;
20  glm::vec3 up;
21  float velocity;
22 };
23 
24 struct W3dContext
25 {
26  SDL_Window* sdlWnd;
27  SDL_GLContext sdlGlCtx;
28  int width, height;
29 };
30 
31 struct Shader
32 {
33  GLuint program;
34 };
35 
36 struct Triangle // CCW (OpenGL's default)
37 {
38  GLfloat vertices[12] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f};
39 };
40 
41 struct Quad // this is CCW! FUCK AUTOFORMAT VS!!!! I AM INTENTIONALLY FORMATTING THE DATA THIS WAY.
42  // FUCK YOU VS!
43 {
44  GLfloat vertices[18] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
45  1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
46 };
47 
49 {
50  int currentIndex = 0;
51  GLuint VAOs[CHUNK_STRIDE * CHUNK_STRIDE * AREA_STRIDE * AREA_STRIDE];
52  GLuint VBOs[CHUNK_STRIDE * CHUNK_STRIDE * AREA_STRIDE * AREA_STRIDE];
53  std::vector<std::vector<Quad>> chunks;
54  std::vector<int> col;
55 };
56 
57 char* load_text(char const* filename);
58 void check_shader_error(GLuint shader);
59 W3dContext initGL(int width, int height);
60 Camera create_camera();
61 void update_mvp(glm::mat4& mvp, Shader& shader);
62 glm::mat4 create_mvp(W3dContext context, Camera camera);
63 Shader create_shader_program();
64 void create_chunk(Shader shader, W3dContext context, Chunk& chunk);
65 void push_chunk(std::vector<Quad>& chunk, Chunk& c);
66 void render(W3dContext context, Shader shader);
67 void render_area(Area& area, W3dContext context, Shader shader);
68 
69 // helper
70 void renderToPGM(std::vector<Chunk>&, std::string const& filename);
71 extern GlChunkData gChunkData;
72 extern float max;
73 extern float min;
74 #endif
Definition: Chunk.h:37
Definition: watch3d.h:31
Definition: watch3d.h:36
Definition: watch3d.h:24
Definition: watch3d.h:48
Definition: watch3d.h:16
Definition: watch3d.h:41
Definition: Area.h:22