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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#include <stdio.h>
#include <windows.h>
#include "math/math.h"
#include "util/assert.h"
#include "ssr.h"
#include "example/example.h"
#include "extern/wog.h"
#include "shaders/common/core.h"
#include "extend/camera.h"
#include "extend/scene.h"
#define SETTING_IMPLEMENT
#include "settings.h"
#define TITLE "Soft Shade Room"
#define SCREEN_WIDTH 600.f
#define SCREEN_HEIGHT 480.f
static char* instruction =
"/***********************************************/\n"
"/* SoftShadeRoom */\n"
"/* */\n"
"/***********************************************/\n"
"Instructions: \n"
" RightMouseButton+MouseMove look around \n"
" MiddleMouseButton+MouseMove move around \n"
" MouseScroll move forward\\backward\n"
" Shift+Above Operation speed up \n"
" key-a show\\hide axis \n"
" key-g show\\hide grid \n"
" key-b bake scene and save to png file(require -b option)\n"
"Usage: \n"
" SoftShadeRoom <example> \n"
"Examples: \n"
" dot \n"
" cube \n"
" texture \n"
" bloom \n"
" fog \n"
" shadow \n";
typedef void(*Callback)(void*);
Callback onload;
Callback onupdate;
Callback onevent;
Callback ondraw;
bool setup(const char* name) {
HMODULE module = GetModuleHandle(NULL);
char func[32] = {0};
#define _setup(p)\
memset(func, 0, sizeof(func)); \
sprintf(func, "%s_%s", #p, name); \
p = (Callback)GetProcAddress(module, func);
_setup(onload);
_setup(onupdate);
_setup(onevent);
_setup(ondraw);
#undef _setup
return onload && onupdate && onevent && ondraw;
}
int main(int argc, char* argv[]) {
printf(instruction);
if (!setup("texture")) {
printf("no such example");
return 0;
}
wog_Window* wnd = wog_createWindow(TITLE, SCREEN_WIDTH, SCREEN_HEIGHT, 500, 500, 0);
wog_Surface* surface = wog_getsurface(wnd); // ARGB format
/* init ssr */
ssr_Config config = {
SCREEN_WIDTH, SCREEN_HEIGHT,
0,
surface->buffer
};
ssr_init(&config);
/*set up global camera*/
CameraConfig cam_config = {
{0, 10, 800},
{0, 0, 0},
60, SCREEN_WIDTH / SCREEN_HEIGHT, 0.1, 10000,
{5, 5}, {150, 150},
4000,
};
printf("Loading...\n");
onload(&cam_config);
scene.main_camera = camera_create(wnd, &cam_config);
gizmo_init();
wog_show(wnd);
_screen_params.x = SCREEN_WIDTH;
_screen_params.y = SCREEN_HEIGHT;
_screen_params.z = 1 / SCREEN_WIDTH;
_screen_params.w = 1 / SCREEN_HEIGHT;
/* main loop */
uint prev = wog_tick();
uint dt = 0;
float _dt = 0, _duration;
uint frame_count = 0;
uint time_stamp = 0;
wog_Event e;
while (1) {
/*handle events*/
//while (wog_pollEvent(wnd, &e)) {
if (wog_pollEvent(wnd, &e)) {
camera_onevent(scene.main_camera, &e, _dt);
gizmo_onevent(&e, _dt);
if (e.type == WOG_ECLOSE) {
goto quit;
}
else if (e.type == WOG_EKEYDOWN) {
if (e.key == VK_ESCAPE) {
goto quit;
}
} else {
onevent(&e);
}
}
/*frame count*/
dt = wog_tick() - prev;
prev += dt;
time_stamp += dt;
++frame_count;
if (time_stamp >= 1000) {
printf("%3d fps\n", frame_count);
time_stamp -= 1000;
frame_count = 0;
}
_time.x = _dt;
_time.y = prev / 1000.f;
/*update*/
_dt = dt / 1000.f;
camera_onupdate(scene.main_camera, _dt);
gizmo_onupdate(_dt);
onupdate(&_dt);
/*draw*/
camera_ondraw(scene.main_camera);
ondraw(NULL);
gizmo_ondraw();
ssr_present();
wog_updateSurface(wnd);
//Sleep(1); /*reduce cpu using*/
}
quit:
camera_destroy(scene.main_camera);
wog_destroyWindow(wnd);
return 0;
}
|