-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempmain.cpp
More file actions
109 lines (82 loc) · 2.77 KB
/
tempmain.cpp
File metadata and controls
109 lines (82 loc) · 2.77 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#define SDL_MAIN_USE_CALLBACKS 1
#define GLM_ENABLE_EXPERIMENTAL
#include <iostream>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <glm/glm.hpp>
#include <string>
#include <OpenGL.h>
#include <glm/gtc/type_ptr.inl>
#include "include/Engine.hpp"
#include "core/factory/ShapeFactory.hpp"
#include <OlafAPI.hpp>
#include "glm/gtx/string_cast.hpp"
#include "olaf-api/Book.hpp"
#include "rendering/glFunctions/glMacros.hpp"
#include "rendering/glFunctions/glTextures.hpp"
#include "rendering/textures/TextureRegister.hpp"
using namespace gan;
std::vector<ShapeAPI> boxes;
ShapeFactory* make;
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
SDL_SetHint(SDL_HINT_APP_NAME, "gordie");
// initialize SDL with just video.
SDL_Init(SDL_INIT_VIDEO);
// create our engine/book
auto& engine = *new gan::Book("", 500, 500, gan::WindowResizable);
// store it in the appstate variable so it's given to other functions.
*appstate = &engine;
////////////////////
boxes.push_back(engine.shapes.make<Cylinder3D>(1.f, 1.f));
boxes.push_back(engine.shapes.make<Prism3D>(.5f, .5f, .5f));
constexpr int gridsize = 20;
for (int x = -gridsize; x <= gridsize; x++) {
if (x == 0) {
boxes.push_back(engine.shapes.make<Box3D>(0.1f, 0.1f, gridsize));
} else {
boxes.push_back(engine.shapes.make<Box3D>(0.02f, 0.02f, gridsize));
}
boxes.back().setPos({x, 0.f, 0.f});
}
for (int z = -gridsize; z <= gridsize; z++) {
if (z == 0) {
boxes.push_back(engine.shapes.make<Box3D>(gridsize, 0.1f, .1f));
} else {
boxes.push_back(engine.shapes.make<Box3D>(gridsize, 0.02f, 0.02f));
}
boxes.back().setPos({0.f, 0.f, z});
}
///////////////////////
return SDL_APP_CONTINUE;
}
static Camera cam;
// SDL App Iteration function. Where g_iterate() is called.
SDL_AppResult SDL_AppIterate(void *appstate) {
// re-cast the engine.
auto& engine = *reinterpret_cast<Book*>(appstate);
// updates timer and keyboard state.
engine.iterate();
// clears the renderer.
engine.render.clear(cam);
//auto& keyboard = engine.core.keyboard;
boxes[0].rotateX(1.0f);
boxes[1].rotateY(3.0f);
for (auto& box : boxes) {
engine.render.draw3D(box);
}
engine.render.present();
return SDL_APP_CONTINUE;
}
// Handle events
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
auto& book = *reinterpret_cast<gan::Book*>(appstate);
if (event->type == SDL_EVENT_QUIT)
return SDL_APP_SUCCESS;
book.events.dispatchEvent(*event);
return SDL_APP_CONTINUE;
}
// Cleanup
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
delete static_cast<gan::Book*>(appstate);
SDL_Quit();
}