forked from Inochi2D/inochi2d-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.c
102 lines (80 loc) · 3.21 KB
/
bootstrap.c
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
#define INOCHI2D_GLYES
#include "inochi2d.h"
#include <GLFW/glfw3.h>
#include <stdio.h>
#define WINDOW_WIDTH 480
#define WINDOW_HEIGHT 800
double timingFunc() {
return glfwGetTime();
}
void error_callback(int error, const char* description) {
fprintf(stderr, "Error: %s\n", description);
}
int main() {
glfwSetErrorCallback(error_callback);
if (!glfwInit())
return -1;
// Inochi2D is officially targeted to OpenGL 3.1 and above
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Inochi2D - C Binding", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
// A timing function that returns the current applications runtime in seconds and milliseconds is needed
inInit(&timingFunc);
// viewport size, which is the size of the scene
uint sceneWidth;
uint sceneHeight;
// It is highly recommended to change the viewport with
// inSetViewport to match the viewport you want, otherwise it'll be 640x480
inViewportSet(WINDOW_WIDTH, WINDOW_HEIGHT);
inViewportGet(&sceneWidth, &sceneHeight);
// Also many vtuber textures are pretty big so let's zoom out a bit.
InCamera* camera = inCameraGetCurrent();
inCameraSetZoom(camera, 0.2);
inCameraSetPosition(camera, 0, 1000);
// You can get example models at https://github.com/Inochi2D/example-models
InPuppet* myPuppet = inPuppetLoad("Aka.inx");
struct {
size_t len;
InParameter **cont;
} parameters;
// let D allocate memory (see README)
parameters.cont = NULL;
inPuppetGetParameters(myPuppet, ¶meters.cont, ¶meters.len);
for (size_t i = 0; i < parameters.len; i++) {
char *name = inParameterGetName(parameters.cont[i]);
bool isVec2 = inParameterIsVec2(parameters.cont[i]);
printf("Parameter #%zu: %s is%s vec2.\n", i, name, isVec2 ? "" : " not");
}
// set "Head:: Roll" to -1.0
inParameterSetValue(parameters.cont[1], -1, 0);
while(!glfwWindowShouldClose(window)) {
// NOTE: Inochi2D does not itself clear the main framebuffer
// you have to do that your self.
glClear(GL_COLOR_BUFFER_BIT);
// Run inUpdate first
// This updates various submodules and time managment for animation
inUpdate();
// Imagine there's a lot of rendering code here
// Maybe even some game logic or something
// Begins drawing in to the Inochi2D scene
// NOTE: You *need* to do this otherwise rendering may break
inSceneBegin();
// Draw and update myPuppet.
// Convention for using Inochi2D in D is to put everything
// in a scene block one indent in.
inPuppetUpdate(myPuppet);
inPuppetDraw(myPuppet);
// Ends drawing in to the Inochi2D scene.
inSceneEnd();
// Draw the scene, background is transparent
inSceneDraw(0, 0, sceneWidth, sceneHeight);
// Do the buffer swapping and event polling last
glfwSwapBuffers(window);
glfwPollEvents();
}
inCleanup();
glfwTerminate();
return 0;
}