Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65017c859c | ||
|
|
f514fc7ffe | ||
|
|
f8eb20c0cf | ||
|
|
33940b7bb6 | ||
|
|
b1897b500b | ||
|
|
fd598255f4 | ||
|
|
733ababde0 | ||
|
|
987ce54429 | ||
|
|
1d254eade5 | ||
|
|
904d686c6e | ||
|
|
a293008137 | ||
|
|
0729388291 | ||
|
|
b19100424d | ||
|
|
0db8ed60ac | ||
|
|
6c322a9759 | ||
|
|
8be2052c45 | ||
|
|
1a0b804b57 | ||
|
|
468f9f951d | ||
|
|
23f98687fe |
22
Makefile
22
Makefile
@@ -2,20 +2,23 @@ BIN = manigraph
|
||||
|
||||
OBJ = \
|
||||
ext/glad/glad.o \
|
||||
src/surface.o \
|
||||
src/context.o \
|
||||
src/texture.o \
|
||||
src/window.o \
|
||||
src/matrix.o \
|
||||
src/shader.o \
|
||||
src/klein.o \
|
||||
src/input.o \
|
||||
src/load.o \
|
||||
src/mesh.o \
|
||||
src/main.o
|
||||
|
||||
EXAMPLES = \
|
||||
example/basic.o
|
||||
|
||||
CFLAGS = \
|
||||
-I./ext/cglm/include \
|
||||
-I./ext/glfw/include \
|
||||
-I./ext/glad \
|
||||
-I./include \
|
||||
-Wall -Wno-unused-function -std=c99 -D_GNU_SOURCE \
|
||||
|
||||
WAYLAND-LIB = \
|
||||
@@ -30,17 +33,16 @@ WAYLAND-LIB = \
|
||||
wayland
|
||||
|
||||
help:
|
||||
@echo "Para compilar el proyecto a tu sistema operativo"
|
||||
@echo "porfavor usa uno de los siguientes comandos:"
|
||||
@echo "Usage:"
|
||||
@echo " $(MAKE) windows"
|
||||
@echo " $(MAKE) linux-x11"
|
||||
@echo " $(MAKE) linux-wayland"
|
||||
@echo " $(MAKE) cocoa"
|
||||
@echo " $(MAKE) CC=emcc wasm"
|
||||
@echo "Para limpiar los archivos compilados se puede usar"
|
||||
@echo "Clean"
|
||||
@echo " $(MAKE) clean"
|
||||
|
||||
src/main.o: src/data/axis.h src/data/shaders.h
|
||||
src/main.o: src/data/shaders.h
|
||||
|
||||
windows: $(OBJ)
|
||||
cd ext; $(MAKE) -f glfw.mk windows; cd -
|
||||
@@ -63,7 +65,7 @@ cocoa: $(OBJ)
|
||||
$(CC) -framework OpenGL -o $(BIN) $(OBJ) ext/glfw.a -lGL -lglfw
|
||||
|
||||
wasm: $(OBJ)
|
||||
$(CC) -sUSE_WEBGL2=1 -sUSE_GLFW=3 -o $(BIN).js $(OBJ)
|
||||
$(CC) -sUSE_WEBGL2=1 -sUSE_GLFW=3 -o $(BIN).html $(OBJ)
|
||||
chmod -x $(BIN).wasm
|
||||
|
||||
libglfw.so:
|
||||
@@ -74,7 +76,9 @@ clean:
|
||||
cd ext; $(MAKE) -f glfw.mk clean; cd -
|
||||
|
||||
|
||||
examples: $(EXAMPLES)
|
||||
|
||||
.SUFFIXES: .c .o
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
$(CC) -Wno-implicit-function-declaration $(CFLAGS) -c -o $@ $<
|
||||
|
||||
92
example/basic.c
Normal file
92
example/basic.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define KLEIN_IMPLEMENT
|
||||
#include <klein/klein.h>
|
||||
#include <klein/norm.h>
|
||||
#include <klein/parm.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
void cube(float *d_surface, int *coord, unsigned char *grid)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
d_surface[i] = (2 * (float)coord[i] / grid[i]) - 1;
|
||||
|
||||
if (4 == 2)
|
||||
d_surface[2] = 0;
|
||||
}
|
||||
|
||||
void mobius(float *d_surface, int *coord, unsigned char *grid)
|
||||
{
|
||||
const float width = 0.5;
|
||||
float u = (2 * M_PI) * ((float)coord[0] / grid[0]);
|
||||
float v = (2 * width) * ((float)coord[1] / grid[1]) - width;
|
||||
|
||||
d_surface[0] = cos(u) + v * cos(u / 2) * cos(u);
|
||||
d_surface[1] = sin(u) + v * cos(u / 2) * sin(u);
|
||||
d_surface[2] = v * sin(u / 2);
|
||||
}
|
||||
|
||||
void torus(float *d_surface, int *coord, unsigned char *grid)
|
||||
{
|
||||
float u = (2 * M_PI) * ((float)coord[0] / grid[0]);
|
||||
float v = (2 * M_PI) * ((float)coord[1] / grid[1]);
|
||||
|
||||
d_surface[0] = (1 + 0.5 * cos(v)) * cos(u);
|
||||
d_surface[1] = (1 + 0.5 * cos(v)) * sin(u);
|
||||
d_surface[2] = 0.5 * sin(v);
|
||||
}
|
||||
|
||||
void klein(float *d_surface, int *coord, unsigned char *grid)
|
||||
{
|
||||
float u = (2 * M_PI) * ((float)coord[0] / grid[0]);
|
||||
float v = (2 * M_PI) * ((float)coord[1] / grid[1]);
|
||||
|
||||
d_surface[0] = (0.5 * cos(v) + 0.5) * cos(u);
|
||||
d_surface[1] = (0.5 * cos(v) + 0.5) * sin(u);
|
||||
d_surface[2] = sin(v) * cos(u / 2);
|
||||
d_surface[3] = sin(v) * sin(u / 2);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char i = 0;
|
||||
const char *file_name[] = {"mobius.klein", "torus.klein", "klein.klein"};
|
||||
struct parm parametrization[] = {{
|
||||
.grid = (unsigned char[]){16, 4},
|
||||
.m = 2,
|
||||
.n = 3,
|
||||
.f = mobius,
|
||||
},
|
||||
{
|
||||
.grid = (unsigned char[]){16, 8},
|
||||
.m = 2,
|
||||
.n = 3,
|
||||
.f = torus,
|
||||
},
|
||||
{
|
||||
.grid = (unsigned char[]){16, 16},
|
||||
.m = 2,
|
||||
.n = 4,
|
||||
.f = klein,
|
||||
}};
|
||||
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
struct klein klein;
|
||||
printf("writing %s\n", file_name[i]);
|
||||
|
||||
klein_parametrize(&klein, parametrization[i]);
|
||||
klein_normalize(&klein);
|
||||
klein_export_file(klein, file_name[i]);
|
||||
|
||||
free(klein.vertex);
|
||||
free(klein.normals);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
50
example/n-cube.c
Normal file
50
example/n-cube.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define KLEIN_IMPLEMENT
|
||||
#include <klein/klein.h>
|
||||
#include <klein/norm.h>
|
||||
#include <klein/parm.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
unsigned char dim = 4;
|
||||
|
||||
void cube(float *d_surface, int *coord, unsigned char *grid)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dim; i++)
|
||||
d_surface[i] = (2 * (float)coord[i] / grid[i]) - 1;
|
||||
|
||||
if (dim == 2)
|
||||
d_surface[2] = 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char i;
|
||||
char file_name[0xff];
|
||||
struct klein klein;
|
||||
struct parm parametrization = {
|
||||
.m = dim,
|
||||
.n = dim,
|
||||
.f = cube,
|
||||
};
|
||||
|
||||
parametrization.grid = malloc(dim);
|
||||
|
||||
for (i = 0; i < dim; ++i)
|
||||
parametrization.grid[i] = 1 << i;
|
||||
|
||||
snprintf(file_name, 0xff, "%03d-cube.klein", dim);
|
||||
printf("writing %s\n", file_name);
|
||||
|
||||
klein_parametrize(&klein, parametrization);
|
||||
klein_normalize(&klein);
|
||||
klein_export_file(klein, file_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
50
example/riemman.c
Normal file
50
example/riemman.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <complex.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define KLEIN_IMPLEMENT
|
||||
#include <klein/klein.h>
|
||||
#include <klein/norm.h>
|
||||
#include <klein/parm.h>
|
||||
|
||||
#ifndef CMPLX
|
||||
#define CMPLX(a, b) (a + I * b)
|
||||
#endif
|
||||
|
||||
complex float f(complex float z) { return csqrt(z); }
|
||||
|
||||
void riemman(float *d_surface, int *coords, unsigned char *grid)
|
||||
{
|
||||
complex float eq;
|
||||
float u = 2 * ((float)coords[0] / grid[0]) - 1;
|
||||
float v = 2 * ((float)coords[1] / grid[1]) - 1;
|
||||
|
||||
eq = f(CMPLX(u, v));
|
||||
|
||||
d_surface[0] = u;
|
||||
d_surface[1] = v;
|
||||
d_surface[2] = creal(eq);
|
||||
d_surface[3] = cimag(eq);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *file_name = "riemman.klein";
|
||||
struct klein klein;
|
||||
struct parm parametrization = {
|
||||
.grid = (unsigned char[]){16, 4},
|
||||
.m = 2,
|
||||
.n = 4,
|
||||
.f = riemman,
|
||||
};
|
||||
|
||||
printf("writing %s\n", file_name);
|
||||
|
||||
klein_parametrize(&klein, parametrization);
|
||||
klein_normalize(&klein);
|
||||
klein_export_file(klein, file_name);
|
||||
|
||||
free(klein.vertex);
|
||||
free(klein.normals);
|
||||
return 0;
|
||||
}
|
||||
48
include/klein/klein.h
Normal file
48
include/klein/klein.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifdef KLEIN_H
|
||||
#error file included twice
|
||||
#endif
|
||||
#define KLEIN_H
|
||||
|
||||
#ifdef KLEIN_IMPLEMENT
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
struct klein
|
||||
{
|
||||
unsigned long vertex_size;
|
||||
float *vertex, *normals;
|
||||
unsigned char dim;
|
||||
};
|
||||
|
||||
/*
|
||||
The klein format must have:
|
||||
5 bytes with klein.
|
||||
1 byte empty for expantions
|
||||
1 byte with the dimention of the surface
|
||||
|
||||
*/
|
||||
|
||||
static inline
|
||||
int klein_export_file(struct klein klein, const char * filename);
|
||||
|
||||
|
||||
#ifdef KLEIN_IMPLEMENT
|
||||
static inline
|
||||
int klein_export_file(struct klein klein, const char * filename)
|
||||
{
|
||||
FILE *file = fopen(filename, "wb");
|
||||
if (!file)
|
||||
return 1;
|
||||
|
||||
fwrite("KLEIN", 1, 5, file);
|
||||
fwrite("\0", 1, 1, file);
|
||||
fwrite(&klein.dim, 1, 1, file);
|
||||
fwrite(&klein.vertex_size, 8, 1, file);
|
||||
fwrite(klein.vertex, 16, klein.vertex_size * klein.dim, file);
|
||||
fwrite(klein.normals, 16, klein.vertex_size * klein.dim, file);
|
||||
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
118
include/klein/norm.h
Normal file
118
include/klein/norm.h
Normal file
@@ -0,0 +1,118 @@
|
||||
static inline
|
||||
void __calculate_normal( float *p1, float *p2, float *p3, float *normal, unsigned char n)
|
||||
{ unsigned char i;
|
||||
float alpha;
|
||||
float *v1, *v2, *v3;
|
||||
float *u1, *u2, *u3;
|
||||
|
||||
v1 = malloc(n * sizeof(float));
|
||||
v2 = malloc(n * sizeof(float));
|
||||
v3 = malloc(n * sizeof(float));
|
||||
u1 = malloc(n * sizeof(float));
|
||||
u2 = malloc(n * sizeof(float));
|
||||
u3 = malloc(n * sizeof(float));
|
||||
|
||||
/*
|
||||
Calculate a normal vector of a plain using Gram-Schmidt process
|
||||
*/
|
||||
{
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
v1[i] = p2[i] - p1[i];
|
||||
v2[i] = p3[i] - p1[i];
|
||||
v3[i] = p1[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
u1[i] = v1[i];
|
||||
}
|
||||
|
||||
{
|
||||
float proj[n];
|
||||
float dot_v2_u1 = 0.0f, dot_u1_u1 = 0.0f;
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
dot_v2_u1 += v2[i] * u1[i];
|
||||
dot_u1_u1 += u1[i] * u1[i];
|
||||
}
|
||||
alpha = dot_v2_u1 / dot_u1_u1;
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
proj[i] = u1[i] * alpha;
|
||||
u2[i] = v2[i] - proj[i];
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
float proj1[n], proj2[n];
|
||||
float dot_v3_u1 = 0.0f, dot_u1_u1 = 0.0f;
|
||||
float dot_v3_u2 = 0.0f, dot_u2_u2 = 0.0f;
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
dot_v3_u1 += v3[i] * u1[i];
|
||||
dot_u1_u1 += u1[i] * u1[i];
|
||||
}
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
proj1[i] = u1[i] * (dot_v3_u1 / dot_u1_u1);
|
||||
}
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
dot_v3_u2 += v3[i] * u2[i];
|
||||
dot_u2_u2 += u2[i] * u2[i];
|
||||
}
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
proj2[i] = u2[i] * (dot_v3_u2 / dot_u2_u2);
|
||||
u3[i] = v3[i] - proj1[i] - proj2[i];
|
||||
}
|
||||
}
|
||||
|
||||
float magnitude = 0.0f;
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
magnitude += u3[i] * u3[i];
|
||||
}
|
||||
magnitude = sqrtf(magnitude);
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
normal[i] = u3[i] / magnitude;
|
||||
}
|
||||
|
||||
free(v1);
|
||||
free(v2);
|
||||
free(v3);
|
||||
free(u1);
|
||||
free(u2);
|
||||
free(u3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void klein_normalize(struct klein * klein)
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned char j;
|
||||
float *norm_vec;
|
||||
|
||||
klein->normals = malloc((klein->dim * klein->vertex_size) * sizeof(float));
|
||||
norm_vec = malloc(klein->dim * sizeof(float));
|
||||
|
||||
for (i = 0; i < klein->vertex_size; i += 3 * klein->dim)
|
||||
{
|
||||
__calculate_normal(klein->vertex + i, klein->vertex + i + klein->dim, klein->vertex + i + 2 * klein->dim, norm_vec, klein->dim);
|
||||
for (j = 0; j < klein->dim; ++j )
|
||||
{
|
||||
(klein->normals + i)[j]=norm_vec[j];
|
||||
(klein->normals + i + klein->dim)[j]=norm_vec[j];
|
||||
(klein->normals + i + 2*klein->dim)[j]=norm_vec[j];
|
||||
}
|
||||
}
|
||||
|
||||
free(norm_vec);
|
||||
}
|
||||
134
include/klein/parm.h
Normal file
134
include/klein/parm.h
Normal file
@@ -0,0 +1,134 @@
|
||||
#ifndef KLEIN_H
|
||||
#warning Please include klein/klein.h before klein/parm.h
|
||||
#endif
|
||||
|
||||
#ifdef KLEIN_PARM_H
|
||||
#error file included twice
|
||||
#endif
|
||||
#define KLEIN_PARM_H
|
||||
|
||||
|
||||
typedef void (*function_t)(float *, int *, unsigned char *);
|
||||
|
||||
struct parm
|
||||
{
|
||||
unsigned char *grid;
|
||||
unsigned char m, n;
|
||||
function_t f;
|
||||
};
|
||||
|
||||
|
||||
void klein_parametrize( struct klein * klein, struct parm parm );
|
||||
|
||||
#ifdef KLEIN_IMPLEMENT
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
static inline int __factorial(int n)
|
||||
{
|
||||
if (n == 1)
|
||||
return 1;
|
||||
|
||||
return n * __factorial(n - 1);
|
||||
}
|
||||
|
||||
static inline int __face(int n)
|
||||
{
|
||||
if (n == 2)
|
||||
return 1;
|
||||
|
||||
return (1 << (n - 3)) * __factorial(n) / __factorial(n - 2);
|
||||
}
|
||||
|
||||
void klein_parametrize( struct klein * klein, struct parm parm)
|
||||
{
|
||||
unsigned int i, j, k, o, p, n;
|
||||
unsigned long size, q = 0;
|
||||
int *face;
|
||||
|
||||
#ifdef TEST
|
||||
assert(__face(2) == 1);
|
||||
assert(__face(3) == 6);
|
||||
assert(__face(4) == 24);
|
||||
#endif
|
||||
|
||||
klein->dim = parm.n;
|
||||
klein->vertex_size = 0;
|
||||
{
|
||||
unsigned char test = 0;
|
||||
for (o = 0; o < parm.m; o++)
|
||||
{
|
||||
for (p = 0; p < o; p++)
|
||||
{
|
||||
test += 1;
|
||||
klein->vertex_size += parm.grid[p] * parm.grid[o] * 6 * __face(parm.m);
|
||||
}
|
||||
}
|
||||
klein->vertex_size /= test;
|
||||
}
|
||||
|
||||
size = (klein->dim) * (klein->vertex_size);
|
||||
klein->vertex = malloc(size * sizeof(float));
|
||||
|
||||
face = malloc(parm.m * sizeof(int));
|
||||
|
||||
for (o = 0; o < parm.m; o++)
|
||||
{
|
||||
for (p = 0; p < o; p++)
|
||||
{
|
||||
for (k = 0; k < (1 << (parm.m - 2)); k++)
|
||||
{
|
||||
unsigned char skip = 0;
|
||||
for (n = 0; n < parm.m; n++)
|
||||
{
|
||||
if (n == o || n == p)
|
||||
skip++;
|
||||
|
||||
face[n] = (k & (1 << (n - skip))) ? parm.grid[n] : 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < parm.grid[p]; i++)
|
||||
{
|
||||
for (j = 0; j < parm.grid[o]; j++)
|
||||
{
|
||||
face[p] = i;
|
||||
face[o] = j;
|
||||
parm.f(&klein->vertex[q], face, parm.grid);
|
||||
q += parm.n;
|
||||
|
||||
face[p] = i + 1;
|
||||
face[o] = j;
|
||||
parm.f(&klein->vertex[q], face, parm.grid);
|
||||
q += parm.n;
|
||||
|
||||
face[p] = i + 1;
|
||||
face[o] = j + 1;
|
||||
parm.f(&klein->vertex[q], face, parm.grid);
|
||||
q += parm.n;
|
||||
|
||||
face[p] = i;
|
||||
face[o] = j;
|
||||
parm.f(&klein->vertex[q], face, parm.grid);
|
||||
q += parm.n;
|
||||
|
||||
face[p] = i;
|
||||
face[o] = j + 1;
|
||||
parm.f(&klein->vertex[q], face, parm.grid);
|
||||
q += parm.n;
|
||||
|
||||
face[p] = i + 1;
|
||||
face[o] = j + 1;
|
||||
parm.f(&klein->vertex[q], face, parm.grid);
|
||||
q += parm.n;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
assert(q == size);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -3,12 +3,8 @@
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <GL/gl.h>
|
||||
#else
|
||||
#ifdef GLAD
|
||||
#include <glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void set_clean_color_context(unsigned char r, unsigned char g, unsigned char b)
|
||||
@@ -22,12 +18,7 @@ int init_context(void)
|
||||
#ifdef EMSCRIPTEN
|
||||
return 1;
|
||||
#else
|
||||
#ifdef GLAD
|
||||
|
||||
return gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
#else
|
||||
return glewInit();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#undef A
|
||||
#undef B
|
||||
#undef C
|
||||
#undef D
|
||||
#undef E
|
||||
#undef F
|
||||
#undef G
|
||||
#undef H
|
||||
|
||||
#define A -2.0,-0.05,-0.05,
|
||||
#define B -2.0,-0.05, 0.05,
|
||||
#define C -2.0, 0.05,-0.05,
|
||||
#define D -2.0, 0.05, 0.05,
|
||||
#define E 2.0,-0.05,-0.05,
|
||||
#define F 2.0,-0.05, 0.05,
|
||||
#define G 2.0, 0.05,-0.05,
|
||||
#define H 2.0, 0.05, 0.05,
|
||||
|
||||
float d_axis[] =
|
||||
{
|
||||
3*3*2*6,
|
||||
|
||||
A C E
|
||||
G E C
|
||||
|
||||
E G F
|
||||
H F G
|
||||
|
||||
F H B
|
||||
D B H
|
||||
|
||||
B D A
|
||||
C A D
|
||||
|
||||
C D G
|
||||
H G D
|
||||
|
||||
E B A
|
||||
B E F
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
const char * vs =
|
||||
const char *vs =
|
||||
#ifdef EMSCRIPTEN
|
||||
"#version 300 es\n"
|
||||
"precision highp float;"
|
||||
@@ -15,94 +15,84 @@ const char * vs =
|
||||
"layout (location = 6) in float aNormal_z;"
|
||||
"layout (location = 7) in float aNormal_w;"
|
||||
|
||||
"uniform uint idx;"
|
||||
|
||||
"uniform uint i;"
|
||||
"uniform float angle;"
|
||||
"uniform float i;"
|
||||
"uniform vec4 color;"
|
||||
|
||||
"uniform mat4 fix;"
|
||||
"uniform mat4 rot;"
|
||||
"uniform mat4 mdl;"
|
||||
|
||||
"flat out uint index;"
|
||||
"out vec3 Normal;"
|
||||
"out vec3 FragPos;"
|
||||
"out vec4 Color;"
|
||||
|
||||
"mat2 rotate2d( float angle )"
|
||||
"{"
|
||||
"return mat2( cos(angle), sin(angle), -sin(angle), cos(angle) );"
|
||||
"return mat2( cos(angle), sin(angle), -sin(angle), cos(angle) );"
|
||||
"}"
|
||||
|
||||
"void main()"
|
||||
"{"
|
||||
" index=idx;"
|
||||
" Color=color;"
|
||||
|
||||
" vec3 aNormal = vec3(aNormal_x,aNormal_y,aNormal_z);"
|
||||
" vec3 aPos = vec3(aPos_x,aPos_y,aPos_z);"
|
||||
|
||||
" aNormal[i] = (vec2(aNormal[i], aNormal_w) * rotate2d(angle))[0];"
|
||||
" aPos[i] = (vec2(aPos[i], aPos_w) * rotate2d(angle))[0];"
|
||||
" aNormal[int(i)] = (vec2(aNormal[int(i)], aNormal_w) * "
|
||||
"rotate2d(angle))[0];"
|
||||
" aPos[int(i)] = (vec2(aPos[int(i)], aPos_w) * rotate2d(angle))[0];"
|
||||
|
||||
" Normal = mat3(transpose(inverse(rot*mdl))) * aNormal;"
|
||||
" gl_Position = fix * rot * mdl * vec4( aPos, 1.0 );\n"
|
||||
" FragPos = vec3( rot * mdl * vec4(aPos, 1.0));"
|
||||
" Normal = mat3(transpose(inverse(rot))) * aNormal;"
|
||||
" gl_Position = fix * rot * vec4( aPos, 1.0 );\n"
|
||||
" FragPos = vec3( rot * vec4(aPos, 1.0));"
|
||||
"}";
|
||||
|
||||
|
||||
const char * fs_plain =
|
||||
const char *fs_plain =
|
||||
#ifdef EMSCRIPTEN
|
||||
"#version 300 es\n"
|
||||
|
||||
"precision highp float;"
|
||||
"precision highp sampler2DArray;"
|
||||
#else
|
||||
"#version 330 core\n"
|
||||
#endif
|
||||
"uniform sampler2DArray palette;"
|
||||
|
||||
"flat in uint index;"
|
||||
"out vec4 FragColor;"
|
||||
"in vec3 Normal;"
|
||||
"in vec3 FragPos;"
|
||||
"in vec4 Color;"
|
||||
|
||||
"void main()"
|
||||
"{"
|
||||
" vec4 color = texture( palette, vec3(0,0,index)).rgba;"
|
||||
" FragColor = vec4(pow(vec3(color),vec3(1.0/2.2)),color.a);"
|
||||
" FragColor = vec4(pow(vec3(Color),vec3(1.0/2.2)),Color.a);"
|
||||
"}";
|
||||
|
||||
const char * fs =
|
||||
const char *fs =
|
||||
#ifdef EMSCRIPTEN
|
||||
"#version 300 es\n"
|
||||
"#version 300 es\n"
|
||||
"precision highp float;"
|
||||
"precision highp sampler2DArray;"
|
||||
#else
|
||||
"#version 330 core\n"
|
||||
"#version 330 core\n"
|
||||
#endif
|
||||
|
||||
"uniform sampler2DArray palette;"
|
||||
"in vec3 Normal;"
|
||||
"in vec3 FragPos;"
|
||||
"in vec4 Color;"
|
||||
|
||||
"flat in uint index;"
|
||||
"in vec3 Normal;"
|
||||
"in vec3 FragPos;"
|
||||
"out vec4 FragColor;"
|
||||
|
||||
"out vec4 FragColor;"
|
||||
"void main()"
|
||||
"{"
|
||||
|
||||
"void main()"
|
||||
"{"
|
||||
" vec4 color = texture(palette, vec3(0, 0, index));\n"
|
||||
" vec3 viewPos = vec3(0, 0, -15);\n"
|
||||
" vec3 viewDir = normalize(viewPos - FragPos);\n"
|
||||
|
||||
" vec3 viewPos = vec3(0, 0, -15);\n"
|
||||
" vec3 viewDir = normalize(viewPos - FragPos);\n"
|
||||
" vec3 lightPos = viewPos;\n"
|
||||
" vec3 lightDir = normalize(lightPos - FragPos);\n"
|
||||
|
||||
" vec3 lightPos = viewPos;\n"
|
||||
" vec3 lightDir = normalize(lightPos - FragPos);\n"
|
||||
" vec3 halfwayDir = normalize(lightDir + viewDir);\n"
|
||||
|
||||
" vec3 halfwayDir = normalize(lightDir + viewDir);\n"
|
||||
" float specular = pow(abs(dot(normalize(Normal), halfwayDir)), 32.0);\n"
|
||||
" float diffuse = abs(dot(normalize(Normal), lightDir));\n"
|
||||
|
||||
" float specular = pow(abs(dot(normalize(Normal), halfwayDir)), 32.0);\n"
|
||||
" float diffuse = abs(dot(normalize(Normal), lightDir));\n"
|
||||
|
||||
" vec3 result = pow((0.5 + 0.5*diffuse + 1.5*specular) * color.rgb, vec3(1.0/2.2));\n"
|
||||
" FragColor = vec4(result, color.a);\n"
|
||||
"}";
|
||||
" vec3 result = pow((0.5 + 0.5*diffuse + 1.5*specular) * Color.rgb, "
|
||||
"vec3(1.0/2.2));\n"
|
||||
" FragColor = vec4(result, Color.a);\n"
|
||||
"}";
|
||||
|
||||
37
src/input.c
37
src/input.c
@@ -9,7 +9,7 @@ unsigned char selected_axis = 0;
|
||||
int window_width;
|
||||
int window_height;
|
||||
|
||||
unsigned char animate_index=0;
|
||||
unsigned char animate_index = 0;
|
||||
|
||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
@@ -56,23 +56,22 @@ void __key_callback_input(
|
||||
projection.w = projection.x;
|
||||
projection.x = tmp;
|
||||
|
||||
animate_index=1;
|
||||
animate_index = 1;
|
||||
break;
|
||||
case GLFW_KEY_O:
|
||||
tmp = projection.w;
|
||||
projection.w = projection.y;
|
||||
projection.y = tmp;
|
||||
animate_index=2;
|
||||
animate_index = 2;
|
||||
break;
|
||||
case GLFW_KEY_P:
|
||||
tmp = projection.w;
|
||||
projection.w = projection.z;
|
||||
projection.z = tmp;
|
||||
animate_index=3;
|
||||
animate_index = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -114,9 +113,9 @@ void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset)
|
||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||
versor r = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
//glm_quatv(p, yoffset * ANGLE, axis[selected_axis]);
|
||||
glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1,0,0});
|
||||
glm_quatv(r, xoffset * ANGLE * 2, (vec3){0,1,0});
|
||||
// glm_quatv(p, yoffset * ANGLE, axis[selected_axis]);
|
||||
glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1, 0, 0});
|
||||
glm_quatv(r, xoffset * ANGLE * 2, (vec3){0, 1, 0});
|
||||
glm_quat_mul(p, q, q);
|
||||
glm_quat_mul(r, q, q);
|
||||
|
||||
@@ -129,6 +128,23 @@ void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset)
|
||||
glm_quat_rotatev(r, axis[2], axis[2]);
|
||||
}
|
||||
|
||||
void __drop_callback_input(GLFWwindow *window, int count, char **path)
|
||||
{
|
||||
struct surface surface;
|
||||
|
||||
if (create_surface_klein(*path, &surface))
|
||||
return;
|
||||
|
||||
if (!(projection.mesh = create_mesh(surface)))
|
||||
return;
|
||||
|
||||
projection.m = surface.dim;
|
||||
set_projection_mesh(projection);
|
||||
|
||||
free(surface.norm);
|
||||
free(surface.data);
|
||||
}
|
||||
|
||||
quat_t poll_input(window_t window)
|
||||
{
|
||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||
@@ -172,10 +188,11 @@ end:
|
||||
glm_quat_normalize(q);
|
||||
|
||||
// LOG INFO
|
||||
if(0)
|
||||
if (0)
|
||||
{
|
||||
printf("QUAT: %2.5f %2.5f %2.5f %2.5f\n", q[0], q[1], q[2], q[3]);
|
||||
printf("PROY: %3d %3d %3d (%3d)\n", projection.x, projection.y, projection.z, projection.w );
|
||||
printf("PROY: %3d %3d %3d (%3d)\n", projection.x, projection.y,
|
||||
projection.z, projection.w);
|
||||
printf("\n");
|
||||
}
|
||||
return q;
|
||||
|
||||
44
src/klein.c
Normal file
44
src/klein.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "main.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
KLEIN Format:
|
||||
5 bytes with KLEIN
|
||||
1 byte empty for scaling
|
||||
1 byte with the dimention of the surface
|
||||
8 bytes interprated as a long with the number of vertex
|
||||
n bytes with the vertex data of the surface
|
||||
n bytes with the normal data of the surface
|
||||
|
||||
where n is the size of the vertex and normal data that could be
|
||||
calculated as the dimention of the surface time the number of vertes
|
||||
time the size of a 16 bytes float.
|
||||
*/
|
||||
|
||||
int create_surface_klein(unsigned char *path, struct surface *surface)
|
||||
{
|
||||
unsigned long size;
|
||||
char buffer[5];
|
||||
FILE *file = fopen(path, "rb");
|
||||
if (!file)
|
||||
return 1;
|
||||
|
||||
fread(buffer, 1, 5, file);
|
||||
|
||||
if (strncmp(buffer, "KLEIN", 5))
|
||||
return 1;
|
||||
|
||||
fread(buffer, 1, 1, file);
|
||||
fread(&surface->dim, 1, 1, file);
|
||||
fread(&surface->vertex, 8, 1, file);
|
||||
|
||||
size = surface->dim * surface->vertex;
|
||||
|
||||
surface->data = malloc(16 * size);
|
||||
fread(surface->data, 16, size, file);
|
||||
|
||||
surface->norm = malloc(16 * size);
|
||||
fread(surface->norm, 16, size, file);
|
||||
return 0;
|
||||
}
|
||||
34
src/load.c
Normal file
34
src/load.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "main.h"
|
||||
#include <cglm/cam.h>
|
||||
#include <cglm/mat4.h>
|
||||
#include <cglm/quat.h>
|
||||
|
||||
void fix_matrix_load(id_t shader, float ratio)
|
||||
{
|
||||
mat4 m, n;
|
||||
const int d = 7;
|
||||
|
||||
glm_lookat((vec3){0, 0, -d}, (vec3){0, 0, 0}, (vec3){0, 1, 0}, m);
|
||||
glm_perspective(CGLM_PI / 6, ratio, d - 3, d + 3, n);
|
||||
glm_mat4_mul(n, m, m);
|
||||
|
||||
load_mat4_to_shader(shader, "fix", (mat4_t)m);
|
||||
}
|
||||
|
||||
void rot_matrix_load(id_t shader, quat_t q)
|
||||
{
|
||||
mat4 m;
|
||||
glm_quat_mat4(q, m);
|
||||
load_mat4_to_shader(shader, "rot", (mat4_t)m);
|
||||
}
|
||||
|
||||
void color_load(id_t shader, unsigned char color[4])
|
||||
{
|
||||
float res[4];
|
||||
|
||||
res[0] = (float)color[0] / 0xff;
|
||||
res[1] = (float)color[1] / 0xff;
|
||||
res[2] = (float)color[2] / 0xff;
|
||||
res[3] = (float)color[3] / 0xff;
|
||||
load_float4_to_shader(shader, "color", res);
|
||||
}
|
||||
121
src/main.c
121
src/main.c
@@ -1,5 +1,4 @@
|
||||
#include "main.h"
|
||||
#include "data/axis.h"
|
||||
#include "data/shaders.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -16,19 +15,11 @@
|
||||
#define M_PI 3.14159
|
||||
#endif
|
||||
|
||||
float *generate_data_surface(unsigned int, unsigned char *);
|
||||
float *generate_normals_surface(float *, unsigned char);
|
||||
|
||||
struct projection projection = {.x = 0, .y=1, .z=2, .w=3 };
|
||||
struct projection projection = {.x = 0, .y = 1, .z = 2, .w = 3, .mesh = NULL};
|
||||
|
||||
const char *wname = "manigraph: manifold grapher";
|
||||
|
||||
unsigned char palette[][4] = {
|
||||
{0xEB, 0xD3, 0xF8, 0xff},
|
||||
{0xEB, 0xD4, 0xF8, 0xff},
|
||||
{0xEB, 0xD5, 0xF8, 0xff},
|
||||
{0x2F, 0x3C, 0x7E, 0xff},
|
||||
};
|
||||
unsigned char color[4] = {0x2F, 0x3C, 0x7E, 0xff};
|
||||
|
||||
void mlog(char *msg)
|
||||
{
|
||||
@@ -38,7 +29,6 @@ void mlog(char *msg)
|
||||
}
|
||||
|
||||
window_t window;
|
||||
mesh_t m_surface, m_axis;
|
||||
id_t shader, shader_plain;
|
||||
|
||||
extern volatile unsigned char animate_index;
|
||||
@@ -46,6 +36,7 @@ extern volatile unsigned char animate_index;
|
||||
#ifndef EMSCRIPTEN
|
||||
static inline
|
||||
#endif
|
||||
|
||||
void
|
||||
main_loop(void)
|
||||
{
|
||||
@@ -53,56 +44,45 @@ static inline
|
||||
|
||||
q = poll_input(window);
|
||||
|
||||
load_rot_matrix(shader, q);
|
||||
load_rot_matrix(shader_plain, q);
|
||||
rot_matrix_load(shader, q);
|
||||
rot_matrix_load(shader_plain, q);
|
||||
color_load(shader, color);
|
||||
color_load(shader_plain, color);
|
||||
|
||||
{
|
||||
static float angle = 0;
|
||||
|
||||
if( angle > M_PI/2 )
|
||||
if (angle > M_PI / 2)
|
||||
{
|
||||
animate_index=0;
|
||||
animate_index = 0;
|
||||
angle = 0;
|
||||
|
||||
load_float_to_shader( shader, "angle", angle);
|
||||
load_float_to_shader( shader_plain, "angle", angle);
|
||||
set_projection_mesh( projection );
|
||||
load_float_to_shader(shader, "angle", angle);
|
||||
load_float_to_shader(shader_plain, "angle", angle);
|
||||
set_projection_mesh(projection);
|
||||
}
|
||||
|
||||
if( animate_index )
|
||||
if (animate_index)
|
||||
{
|
||||
load_uint_to_shader( shader, "i", animate_index-1 );
|
||||
load_uint_to_shader( shader_plain, "i", animate_index-1 );
|
||||
load_float_to_shader(shader, "i", animate_index - 1);
|
||||
load_float_to_shader(shader_plain, "i", animate_index - 1);
|
||||
|
||||
angle+=0.01;
|
||||
load_float_to_shader( shader, "angle", angle);
|
||||
load_float_to_shader( shader_plain, "angle", angle);
|
||||
angle += 0.01;
|
||||
load_float_to_shader(shader, "angle", angle);
|
||||
load_float_to_shader(shader_plain, "angle", angle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
clean_context();
|
||||
|
||||
#ifndef DEBUG
|
||||
load_mdl_matrix(shader_plain, 0, 0);
|
||||
draw_mesh(m_axis, 1);
|
||||
load_mdl_matrix(shader_plain, 1, 1);
|
||||
draw_mesh(m_axis, 1);
|
||||
load_mdl_matrix(shader_plain, 2, 2);
|
||||
draw_mesh(m_axis, 1);
|
||||
#endif
|
||||
load_mdl_matrix(shader, 0, 3);
|
||||
draw_mesh(m_surface,0);
|
||||
|
||||
load_mdl_matrix(shader_plain, 0, 3);
|
||||
draw_mesh(m_surface,1);
|
||||
if (!projection.mesh)
|
||||
return;
|
||||
|
||||
draw_mesh(shader, projection.mesh);
|
||||
draw_mesh_lines(shader_plain, projection.mesh);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
id_t texture;
|
||||
|
||||
mlog("[VENTANA] Inicializando...\n");
|
||||
{
|
||||
@@ -125,12 +105,6 @@ int main(void)
|
||||
set_clean_color_context(0xFF, 0xFF, 0xFF);
|
||||
}
|
||||
|
||||
mlog("[TEXTURE] Inicializando...\n");
|
||||
{
|
||||
texture = create_palette_texture(palette, 4);
|
||||
use_texture(texture);
|
||||
}
|
||||
|
||||
mlog("[SHADER] Inicializando...\n");
|
||||
{
|
||||
if (!(shader = create_shader()))
|
||||
@@ -140,7 +114,7 @@ int main(void)
|
||||
}
|
||||
load_program_to_shader(shader, vs, VERTEX);
|
||||
load_program_to_shader(shader, fs, FRAGMENT);
|
||||
load_fix_matrix(shader, (float)WIDTH / HEIGHT);
|
||||
fix_matrix_load(shader, (float)WIDTH / HEIGHT);
|
||||
}
|
||||
|
||||
mlog("[SHADER] Inicializando...\n");
|
||||
@@ -152,38 +126,7 @@ int main(void)
|
||||
}
|
||||
load_program_to_shader(shader_plain, vs, VERTEX);
|
||||
load_program_to_shader(shader_plain, fs_plain, FRAGMENT);
|
||||
load_fix_matrix(shader_plain, (float)WIDTH / HEIGHT);
|
||||
}
|
||||
|
||||
mlog("[MESH] Inicializando...\n");
|
||||
{
|
||||
unsigned char m;
|
||||
float *n_surface, *d_surface;
|
||||
d_surface = generate_data_surface(16, &m);
|
||||
n_surface = generate_normals_surface(d_surface, m);
|
||||
|
||||
if (!(m_surface = create_mesh(d_surface, n_surface, m)))
|
||||
{
|
||||
mlog("[MESH] Error al inicializar...\n");
|
||||
goto error_mesh_surface;
|
||||
}
|
||||
|
||||
projection.m = m;
|
||||
projection.mesh = m_surface;
|
||||
set_projection_mesh( projection );
|
||||
|
||||
|
||||
free(n_surface);
|
||||
free(d_surface);
|
||||
}
|
||||
|
||||
mlog("[MESH] Inicializando...\n");
|
||||
{
|
||||
if (!(m_axis = create_mesh(d_axis, NULL, 3)))
|
||||
{
|
||||
mlog("[MESH] Error al inicializar...\n");
|
||||
goto error_mesh_axis;
|
||||
}
|
||||
fix_matrix_load(shader_plain, (float)WIDTH / HEIGHT);
|
||||
}
|
||||
|
||||
mlog("[MAIN LOOP] Inicializando...\n");
|
||||
@@ -197,34 +140,22 @@ int main(void)
|
||||
mlog("[MAIN LOOP] Terminando...\n");
|
||||
|
||||
mlog("[MESH] Destruyendo...\n");
|
||||
destroy_mesh(m_axis);
|
||||
mlog("[MESH] Destruyendo...\n");
|
||||
destroy_mesh(m_surface);
|
||||
destroy_mesh(projection.mesh);
|
||||
mlog("[SHADER] Destruyendo...\n");
|
||||
destroy_shader(shader_plain);
|
||||
mlog("[SHADER] Destruyendo...\n");
|
||||
destroy_shader(shader);
|
||||
mlog("[TEXTURE] Destruyendo...\n");
|
||||
destroy_texture(texture);
|
||||
mlog("[WINDOW] Destruyendo...\n");
|
||||
close_window(window);
|
||||
return 0;
|
||||
|
||||
mlog("[MESH] Destruyendo...\n");
|
||||
destroy_mesh(m_axis);
|
||||
error_mesh_axis:
|
||||
mlog("[MESH] Destruyendo...\n");
|
||||
destroy_mesh(m_surface);
|
||||
error_mesh_surface:
|
||||
error_context:
|
||||
mlog("[SHADER] Destruyendo...\n");
|
||||
destroy_shader(shader_plain);
|
||||
error_shader_plain:
|
||||
mlog("[SHADER] Destruyendo...\n");
|
||||
destroy_shader(shader);
|
||||
error_shader:
|
||||
mlog("[TEXTURE] Destruyendo...\n");
|
||||
destroy_texture(texture);
|
||||
error_context:
|
||||
mlog("[WINDOW] Destruyendo...\n");
|
||||
close_window(window);
|
||||
error_window:
|
||||
|
||||
87
src/main.h
87
src/main.h
@@ -4,14 +4,13 @@
|
||||
error of the shaders.
|
||||
*/
|
||||
|
||||
/* #define DEBUG */
|
||||
#define GLAD
|
||||
#define DEBUG
|
||||
|
||||
typedef const void * window_t;
|
||||
typedef const void *window_t;
|
||||
typedef unsigned int id_t;
|
||||
typedef void * mesh_t;
|
||||
typedef float * quat_t;
|
||||
typedef float * mat4_t;
|
||||
typedef void *mesh_t;
|
||||
typedef float *quat_t;
|
||||
typedef float *mat4_t;
|
||||
|
||||
/*
|
||||
This struct represent the proyection, where:
|
||||
@@ -29,6 +28,22 @@ struct projection
|
||||
unsigned char m, x, y, z, w;
|
||||
};
|
||||
|
||||
/*
|
||||
this structure has all the information to generate
|
||||
a mesh, where:
|
||||
data: the buffer with the vertex coords
|
||||
norm: the buffer with the norm coords
|
||||
vertex: the number of vertex
|
||||
dim: the dimentions of the surface
|
||||
*/
|
||||
|
||||
struct surface
|
||||
{
|
||||
float *data, *norm;
|
||||
unsigned long vertex;
|
||||
unsigned char dim;
|
||||
};
|
||||
|
||||
/*
|
||||
Init window:
|
||||
w: default width;
|
||||
@@ -36,7 +51,9 @@ struct projection
|
||||
name: Name of the window.
|
||||
*/
|
||||
|
||||
window_t init_window(unsigned int w, unsigned int h, const char * name);
|
||||
int create_surface_klein( unsigned char *, struct surface * );
|
||||
|
||||
window_t init_window(unsigned int w, unsigned int h, const char *name);
|
||||
|
||||
void use_window(window_t window);
|
||||
|
||||
@@ -51,13 +68,15 @@ void close_window(window_t window);
|
||||
m: Dimention of mesh
|
||||
*/
|
||||
|
||||
mesh_t create_mesh( float * d, float * n, unsigned char m );
|
||||
mesh_t create_mesh(struct surface);
|
||||
|
||||
void set_projection_mesh( struct projection );
|
||||
void set_projection_mesh(struct projection);
|
||||
|
||||
void destroy_mesh(mesh_t p);
|
||||
|
||||
void draw_mesh(mesh_t p, char lines);
|
||||
void draw_mesh(id_t, mesh_t p);
|
||||
|
||||
void draw_mesh_lines(id_t, mesh_t p);
|
||||
|
||||
/*
|
||||
Set background color:
|
||||
@@ -70,7 +89,7 @@ void set_clean_color_context(unsigned char r, unsigned char g, unsigned char b);
|
||||
|
||||
void clean_context(void);
|
||||
|
||||
int init_context( void );
|
||||
int init_context(void);
|
||||
|
||||
void destroy_shader(id_t shader);
|
||||
|
||||
@@ -80,7 +99,8 @@ void use_shader(id_t shader);
|
||||
|
||||
enum
|
||||
{
|
||||
VERTEX, FRAGMENT
|
||||
VERTEX,
|
||||
FRAGMENT
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -89,7 +109,8 @@ enum
|
||||
type: VERTEX or FRAGMENT
|
||||
*/
|
||||
|
||||
unsigned char load_program_to_shader(id_t shader, const char * src, unsigned int type);
|
||||
unsigned char load_program_to_shader(
|
||||
id_t shader, const char *src, unsigned int type);
|
||||
|
||||
/*
|
||||
load float to shader:
|
||||
@@ -97,7 +118,7 @@ unsigned char load_program_to_shader(id_t shader, const char * src, unsigned int
|
||||
f: float to load
|
||||
*/
|
||||
|
||||
void load_float_to_shader(id_t shader, char * var, float f);
|
||||
void load_float_to_shader(id_t shader, char *var, float f);
|
||||
|
||||
/*
|
||||
load unsigned int to shader:
|
||||
@@ -105,7 +126,15 @@ void load_float_to_shader(id_t shader, char * var, float f);
|
||||
u: unsigned int to load
|
||||
*/
|
||||
|
||||
void load_uint_to_shader(id_t shader, char * var, unsigned int u);
|
||||
void load_uint_to_shader(id_t shader, char *var, unsigned int u);
|
||||
|
||||
/*
|
||||
load float[4] to shader:
|
||||
var: name of glsl variable.
|
||||
f: float[4] to load
|
||||
*/
|
||||
|
||||
void load_float4_to_shader(id_t shader, char *var, float f[4]);
|
||||
|
||||
/*
|
||||
load matrix 4 to shader:
|
||||
@@ -113,7 +142,7 @@ void load_uint_to_shader(id_t shader, char * var, unsigned int u);
|
||||
m: Matrix to load
|
||||
*/
|
||||
|
||||
void load_mat4_to_shader(id_t shader, char * var, mat4_t m);
|
||||
void load_mat4_to_shader(id_t shader, char *var, mat4_t m);
|
||||
|
||||
/*
|
||||
Generate and load fix matrix, this matrix
|
||||
@@ -122,23 +151,19 @@ void load_mat4_to_shader(id_t shader, char * var, mat4_t m);
|
||||
|
||||
ratio: default ratio of window.
|
||||
*/
|
||||
void load_fix_matrix(id_t shader, float ratio);
|
||||
|
||||
/*
|
||||
Generate and load model matrix, it also sets the color
|
||||
to draw.
|
||||
i: From {0,1,2} select one of 3 ortogonal rotations,
|
||||
One for each axis.
|
||||
c: Color index of the pallete.
|
||||
*/
|
||||
void load_mdl_matrix(id_t shader, unsigned char i, unsigned char c);
|
||||
void fix_matrix_load(id_t shader, float ratio);
|
||||
|
||||
/*
|
||||
Generate and load rotation matrix.
|
||||
q: quaterinon describing the rotation.
|
||||
*/
|
||||
|
||||
void load_rot_matrix(id_t shader, quat_t q);
|
||||
void rot_matrix_load(id_t shader, quat_t q);
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
void color_load(id_t shader, unsigned char color[4]);
|
||||
|
||||
id_t config_texture(unsigned short type);
|
||||
|
||||
@@ -151,12 +176,6 @@ void destroy_texture(id_t texture);
|
||||
colors: array of color values (rgba in hex ).
|
||||
n: number of color on colors.
|
||||
*/
|
||||
id_t create_palette_texture(const unsigned char colors[][4], unsigned char n );
|
||||
id_t create_palette_texture(const unsigned char colors[][4], unsigned char n);
|
||||
|
||||
quat_t poll_input(window_t window);
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#ifdef GLAD
|
||||
#error undefine GLAD on src/main.h please
|
||||
#endif
|
||||
#endif
|
||||
|
||||
BIN
src/main.o
BIN
src/main.o
Binary file not shown.
50
src/matrix.c
50
src/matrix.c
@@ -1,50 +0,0 @@
|
||||
#include "main.h"
|
||||
#include <cglm/cam.h>
|
||||
#include <cglm/mat4.h>
|
||||
#include <cglm/quat.h>
|
||||
|
||||
mat4 ortho[] = {
|
||||
{
|
||||
{1, 0, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
},
|
||||
{
|
||||
{0, 1, 0, 0},
|
||||
{-1, 0, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
},
|
||||
{
|
||||
{0, 0, 1, 0},
|
||||
{0, 1, 0, 0},
|
||||
{-1, 0, 0, 0},
|
||||
{0, 0, 0, 1},
|
||||
},
|
||||
};
|
||||
|
||||
void load_fix_matrix(id_t shader, float ratio)
|
||||
{
|
||||
mat4 m, n;
|
||||
const int d = 7;
|
||||
|
||||
glm_lookat((vec3){0, 0, -d}, (vec3){0, 0, 0}, (vec3){0, 1, 0}, m);
|
||||
glm_perspective(CGLM_PI / 6, ratio, d - 3, d + 3, n);
|
||||
glm_mat4_mul(n, m, m);
|
||||
|
||||
load_mat4_to_shader(shader, "fix", (mat4_t)m);
|
||||
}
|
||||
|
||||
void load_mdl_matrix(id_t shader, unsigned char i, unsigned char c)
|
||||
{
|
||||
load_uint_to_shader(shader, "idx", c);
|
||||
load_mat4_to_shader(shader, "mdl", (mat4_t)ortho[i]);
|
||||
}
|
||||
|
||||
void load_rot_matrix(id_t shader, quat_t q)
|
||||
{
|
||||
mat4 m;
|
||||
glm_quat_mat4(q, m);
|
||||
load_mat4_to_shader(shader, "rot", (mat4_t)m);
|
||||
}
|
||||
58
src/mesh.c
58
src/mesh.c
@@ -1,9 +1,11 @@
|
||||
#include "main.h"
|
||||
#ifdef GLAD
|
||||
#include <glad.h>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <GL/gl.h>
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#include <glad.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -47,36 +49,34 @@ void set_projection_mesh(struct projection projection)
|
||||
This trick can be done with glVertexAttribPointer.
|
||||
*/
|
||||
|
||||
mesh_t create_mesh(float *d, float *n, unsigned char m)
|
||||
mesh_t create_mesh(struct surface surface)
|
||||
{
|
||||
unsigned char i;
|
||||
struct obj *p;
|
||||
|
||||
p = malloc(sizeof(struct obj));
|
||||
|
||||
p->vertex = (*d) / m;
|
||||
p->vertex = surface.vertex;
|
||||
|
||||
glGenVertexArrays(1, &p->vao);
|
||||
glBindVertexArray(p->vao);
|
||||
|
||||
glGenBuffers(1, &p->d_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, p->d_vbo);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER, p->vertex * m * sizeof(float), d + 1, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, p->vertex * surface.dim * sizeof(float),
|
||||
surface.data, GL_STATIC_DRAW);
|
||||
|
||||
if (n)
|
||||
if (surface.norm)
|
||||
{
|
||||
glGenBuffers(1, &p->n_vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p->n_vbo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, p->vertex * m * sizeof(float),
|
||||
n + 1, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
|
||||
p->vertex * surface.dim * sizeof(float), surface.norm,
|
||||
GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i)
|
||||
{
|
||||
for (i = 0; i < 8; ++i)
|
||||
glEnableVertexAttribArray(i);
|
||||
glEnableVertexAttribArray(i + 4);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
@@ -91,19 +91,27 @@ void destroy_mesh(mesh_t p)
|
||||
free(p);
|
||||
}
|
||||
|
||||
void draw_mesh(mesh_t p, char lines )
|
||||
void draw_mesh(id_t shader, mesh_t p)
|
||||
{
|
||||
struct obj *obj = p;
|
||||
|
||||
glUseProgram(shader);
|
||||
glBindVertexArray(obj->vao);
|
||||
if( lines )
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < obj->vertex; i += 3)
|
||||
glDrawArrays(GL_LINE_LOOP, i, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(GL_TRIANGLES, 0, obj->vertex);
|
||||
}
|
||||
#ifndef EMSCRIPTEN
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
#endif
|
||||
glDrawArrays(GL_TRIANGLES, 0, obj->vertex);
|
||||
}
|
||||
void draw_mesh_lines(id_t shader, mesh_t p)
|
||||
{
|
||||
struct obj *obj = p;
|
||||
|
||||
glUseProgram(shader);
|
||||
glBindVertexArray(obj->vao);
|
||||
#ifndef EMSCRIPTEN
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glDrawArrays(GL_TRIANGLES, 0, obj->vertex);
|
||||
#else
|
||||
glDrawArrays(GL_LINES, 0, obj->vertex);
|
||||
#endif
|
||||
}
|
||||
|
||||
21
src/shader.c
21
src/shader.c
@@ -1,20 +1,20 @@
|
||||
#include "main.h"
|
||||
|
||||
#ifdef GLAD
|
||||
#ifndef EMSCRIPTEN
|
||||
#include <glad.h>
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
void destroy_shader(unsigned int shader) { return glDeleteProgram(shader); }
|
||||
void destroy_shader(unsigned int shader) { glDeleteProgram(shader); }
|
||||
|
||||
unsigned int create_shader(void) { return glCreateProgram(); }
|
||||
|
||||
void use_shader(unsigned int program) { return glUseProgram(program); }
|
||||
void use_shader(unsigned int program) { glUseProgram(program); }
|
||||
|
||||
unsigned char load_program_to_shader(
|
||||
unsigned int program, const char *src, unsigned int i)
|
||||
@@ -54,14 +54,15 @@ void load_float_to_shader(unsigned int program, char *var, float f)
|
||||
glUniform1f(glGetUniformLocation(program, var), f);
|
||||
}
|
||||
|
||||
void load_uint_to_shader(unsigned int program, char *var, unsigned int u)
|
||||
{
|
||||
glUseProgram(program);
|
||||
glUniform1ui(glGetUniformLocation(program, var), u);
|
||||
}
|
||||
|
||||
void load_mat4_to_shader(unsigned int program, char *var, float *mat)
|
||||
{
|
||||
glUseProgram(program);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, var), 1, 0, mat);
|
||||
}
|
||||
|
||||
void load_float4_to_shader(unsigned int program, char *var, float float4[4])
|
||||
{
|
||||
glUseProgram(program);
|
||||
glUniform4f(glGetUniformLocation(program, var), float4[0], float4[1],
|
||||
float4[2], float4[3]);
|
||||
}
|
||||
|
||||
263
src/surface.c
263
src/surface.c
@@ -1,263 +0,0 @@
|
||||
#include <complex.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CGLM_ALL_UNALIGNED
|
||||
#include <cglm/vec3.h>
|
||||
#include <cglm/vec4.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#ifndef CMPLX
|
||||
#define CMPLX(a,b) (a+I*b)
|
||||
#endif
|
||||
|
||||
void riemman(float *d_surface, int * coords, int grid_size)
|
||||
{
|
||||
complex double eq;
|
||||
float u = 2 * ((float)coords[0] / grid_size) - 1;
|
||||
float v = 2 * ((float)coords[1] / grid_size) - 1;
|
||||
|
||||
eq = csqrt(CMPLX(u,v));
|
||||
|
||||
d_surface[0] = u;
|
||||
d_surface[1] = v;
|
||||
d_surface[2] = creal(eq);
|
||||
d_surface[3] = cimag(eq);
|
||||
}
|
||||
|
||||
|
||||
void cube( float *d_surface, int * coord, int grid_size )
|
||||
{
|
||||
unsigned char i;
|
||||
|
||||
for(int i=0; i<4; i++ )
|
||||
d_surface[i]=(float)coord[i]/grid_size;
|
||||
}
|
||||
|
||||
void mobius(float *d_surface, int * coord, int grid_size)
|
||||
{
|
||||
const float width = 0.5;
|
||||
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
|
||||
float v = (2 * width) * ((float)coord[1] / grid_size) - width;
|
||||
|
||||
d_surface[0] = cos(u) + v * cos(u / 2) * cos(u);
|
||||
d_surface[1] = sin(u) + v * cos(u / 2) * sin(u);
|
||||
d_surface[2] = v * sin(u / 2);
|
||||
}
|
||||
|
||||
void torus(float *d_surface, int * coord, int grid_size)
|
||||
{
|
||||
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
|
||||
float v = (2 * M_PI) * ((float)coord[1] / grid_size);
|
||||
|
||||
d_surface[0] = (1 + 0.5 * cos(v)) * cos(u);
|
||||
d_surface[1] = (1 + 0.5 * cos(v)) * sin(u);
|
||||
d_surface[2] = 0.5 * sin(v);
|
||||
}
|
||||
|
||||
void klein(float *d_surface, int * coord, int grid_size)
|
||||
{
|
||||
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
|
||||
float v = (2 * M_PI) * ((float)coord[1]/ grid_size);
|
||||
|
||||
d_surface[0] = (0.5 * cos(v) + 0.5) * cos(u);
|
||||
d_surface[1] = (0.5 * cos(v) + 0.5) * sin(u);
|
||||
d_surface[2] = sin(v) * cos(u / 2);
|
||||
d_surface[3] = sin(v) * sin(u / 2);
|
||||
}
|
||||
|
||||
typedef void (*function_t)(float *, int *, int);
|
||||
|
||||
float *generate_data_surface(int grid_size, unsigned char *s)
|
||||
{
|
||||
unsigned int i, j, k, o, p, l, n, m;
|
||||
long size, q=0;
|
||||
function_t f;
|
||||
float *d_surface;
|
||||
|
||||
const int dim =2;
|
||||
int cara[dim];
|
||||
char bits[dim+1];
|
||||
bits[dim]=0;
|
||||
|
||||
f =klein ;
|
||||
*s = 4;
|
||||
|
||||
size = grid_size * grid_size * 6 * (*s) * 24;
|
||||
d_surface = malloc((size + 1) * sizeof(float));
|
||||
d_surface[0] = size;
|
||||
|
||||
for(o = 0; o < dim; o ++)
|
||||
{
|
||||
for (p = 0; p < o; p++)
|
||||
{
|
||||
for (k = 0; k < (1 << (dim-2)); k++)
|
||||
{
|
||||
unsigned char skip=0;
|
||||
for(n = 0; n < dim-2; n++)
|
||||
{
|
||||
if( n==(o-1) || n==p )
|
||||
skip++;
|
||||
|
||||
cara[n+skip] = (k & (1<<n))?grid_size:0;
|
||||
}
|
||||
|
||||
for(i = 0; i < grid_size; i++)
|
||||
{
|
||||
for (j = 0; j < grid_size; j++)
|
||||
{
|
||||
cara[o] = i;
|
||||
cara[p] = j;
|
||||
f(&d_surface[q + 1], cara, grid_size);
|
||||
q += *s;
|
||||
|
||||
cara[o] = i + 1;
|
||||
cara[p] = j;
|
||||
f(&d_surface[q + 1], cara, grid_size);
|
||||
q += *s;
|
||||
|
||||
cara[o] = i + 1;
|
||||
cara [p] = j + 1;
|
||||
f(&d_surface[q + 1], cara, grid_size);
|
||||
q += *s;
|
||||
|
||||
cara[o] = i;
|
||||
cara [p] = j;
|
||||
f(&d_surface[q + 1], cara, grid_size);
|
||||
q += *s;
|
||||
|
||||
cara[o] = i;
|
||||
cara [p] = j + 1;
|
||||
f(&d_surface[q + 1], cara, grid_size);
|
||||
q += *s;
|
||||
|
||||
cara[o] = i + 1;
|
||||
cara [p] = j + 1;
|
||||
f(&d_surface[q + 1], cara, grid_size);
|
||||
q += *s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return d_surface;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void __calculate_normal(
|
||||
float *p1, float *p2, float *p3, float *normal, unsigned char n)
|
||||
{
|
||||
unsigned char i;
|
||||
float alpha;
|
||||
float *v1, *v2, *v3;
|
||||
float *u1, *u2, *u3;
|
||||
|
||||
v1 = malloc(n * sizeof(float));
|
||||
v2 = malloc(n * sizeof(float));
|
||||
v3 = malloc(n * sizeof(float));
|
||||
u1 = malloc(n * sizeof(float));
|
||||
u2 = malloc(n * sizeof(float));
|
||||
u3 = malloc(n * sizeof(float));
|
||||
|
||||
/*
|
||||
Calculate a normal vector of a plain using Gram-Schmidt process
|
||||
*/
|
||||
{
|
||||
for (i = 0; i < n; ++i) {
|
||||
v1[i] = p2[i] - p1[i];
|
||||
v2[i] = p3[i] - p1[i];
|
||||
v3[i] = p1[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
u1[i] = v1[i];
|
||||
}
|
||||
|
||||
{
|
||||
float proj[n];
|
||||
float dot_v2_u1 = 0.0f, dot_u1_u1 = 0.0f;
|
||||
for (i = 0; i < n; ++i) {
|
||||
dot_v2_u1 += v2[i] * u1[i];
|
||||
dot_u1_u1 += u1[i] * u1[i];
|
||||
}
|
||||
alpha = dot_v2_u1 / dot_u1_u1;
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
proj[i] = u1[i] * alpha;
|
||||
u2[i] = v2[i] - proj[i];
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
float proj1[n], proj2[n];
|
||||
float dot_v3_u1 = 0.0f, dot_u1_u1 = 0.0f;
|
||||
float dot_v3_u2 = 0.0f, dot_u2_u2 = 0.0f;
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
dot_v3_u1 += v3[i] * u1[i];
|
||||
dot_u1_u1 += u1[i] * u1[i];
|
||||
}
|
||||
for (i = 0; i < n; ++i) {
|
||||
proj1[i] = u1[i] * (dot_v3_u1 / dot_u1_u1);
|
||||
}
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
dot_v3_u2 += v3[i] * u2[i];
|
||||
dot_u2_u2 += u2[i] * u2[i];
|
||||
}
|
||||
for (i = 0; i < n; ++i) {
|
||||
proj2[i] = u2[i] * (dot_v3_u2 / dot_u2_u2);
|
||||
u3[i] = v3[i] - proj1[i] - proj2[i];
|
||||
}
|
||||
}
|
||||
|
||||
float magnitude = 0.0f;
|
||||
for (i = 0; i < n; ++i) {
|
||||
magnitude += u3[i] * u3[i];
|
||||
}
|
||||
magnitude = sqrtf(magnitude);
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
normal[i] = u3[i] / magnitude;
|
||||
}
|
||||
|
||||
free(v1);
|
||||
free(v2);
|
||||
free(v3);
|
||||
free(u1);
|
||||
free(u2);
|
||||
free(u3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float *generate_normals_surface(float *d, unsigned char m)
|
||||
{
|
||||
float *n;
|
||||
n = malloc((*d + 1) * sizeof(float));
|
||||
*n = *d;
|
||||
|
||||
float * norm_vec;
|
||||
norm_vec=malloc(m*sizeof(float));
|
||||
|
||||
for (int i = 0; i < *d; i += 3 * m)
|
||||
{
|
||||
|
||||
|
||||
__calculate_normal(
|
||||
(d + 1) + i, (d + 1) + i + m, (d + 1) + i + 2 * m, norm_vec, m);
|
||||
glm_vec3_copy(norm_vec, (n + 1) + i);
|
||||
glm_vec3_copy(norm_vec, (n + 1) + i + m);
|
||||
glm_vec3_copy(norm_vec, (n + 1) + i + 2 * m);
|
||||
}
|
||||
|
||||
free(norm_vec);
|
||||
return n;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
#include "main.h"
|
||||
#ifdef GLAD
|
||||
#include <glad.h>
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#define TYPE GL_TEXTURE_2D_ARRAY
|
||||
|
||||
static id_t __config_texture(unsigned short type)
|
||||
{
|
||||
id_t texture;
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(TYPE, texture);
|
||||
|
||||
{
|
||||
glTexParameteri(TYPE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(TYPE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
void use_texture(id_t texture) { return glBindTexture(TYPE, texture); }
|
||||
|
||||
void destroy_texture(unsigned int texture)
|
||||
{
|
||||
return glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
id_t create_palette_texture(const unsigned char colors[][4], unsigned char n)
|
||||
{
|
||||
id_t texture = __config_texture(TYPE);
|
||||
glTexImage3D(
|
||||
TYPE, 0, GL_RGBA, 1, 1, n, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors);
|
||||
return texture;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ void __window_callback_input(GLFWwindow *, int, int);
|
||||
void __mouse_callback_input(GLFWwindow *, int, int, int);
|
||||
void __scroll_callback_input(GLFWwindow *, double, double);
|
||||
void __key_callback_input(GLFWwindow *, int, int, int, int);
|
||||
void __drop_callback_input(GLFWwindow *, int, const char **);
|
||||
|
||||
window_t init_window(unsigned int w, unsigned int h, const char *name);
|
||||
|
||||
@@ -64,6 +65,7 @@ window_t init_window(unsigned int width, unsigned int height, const char *title)
|
||||
glfwSetMouseButtonCallback((GLFWwindow *)window, __mouse_callback_input);
|
||||
glfwSetScrollCallback((GLFWwindow *)window, __scroll_callback_input);
|
||||
glfwSetKeyCallback((GLFWwindow *)window, __key_callback_input);
|
||||
glfwSetDropCallback((GLFWwindow *)window, __drop_callback_input);
|
||||
|
||||
__window_callback_input((GLFWwindow *)window, width, height);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user