Compare commits
108 Commits
alan
...
crisel-nuk
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b83f0f07e3 | ||
|
|
52aa9d4ac2 | ||
|
|
bc537cf9f2 | ||
|
|
533109fbcd | ||
|
|
3997613d16 | ||
|
|
f21121b88d | ||
|
|
86480fe9b1 | ||
|
|
e9bd748dd8 | ||
|
|
ad4f5cb077 | ||
|
|
a08b17e975 | ||
|
|
d97a35b898 | ||
|
|
b2f6707efc | ||
|
|
7344c6bfcb | ||
|
|
b928dcd82d | ||
|
|
f687117fed | ||
|
|
65017c859c | ||
|
|
f514fc7ffe | ||
|
|
f8eb20c0cf | ||
|
|
33940b7bb6 | ||
|
|
b1897b500b | ||
|
|
81eb79662e | ||
|
|
d2e2c6eef7 | ||
|
|
57091d3408 | ||
|
|
fd598255f4 | ||
|
|
733ababde0 | ||
|
|
987ce54429 | ||
|
|
1d254eade5 | ||
|
|
904d686c6e | ||
|
|
6d1223d79e | ||
|
|
3e3c6e676e | ||
|
|
f33b8f67b5 | ||
|
|
a293008137 | ||
|
|
0729388291 | ||
|
|
eb59f5346a | ||
|
|
b19100424d | ||
|
|
0db8ed60ac | ||
|
|
6c322a9759 | ||
|
|
8be2052c45 | ||
|
|
1a0b804b57 | ||
|
|
468f9f951d | ||
|
|
ee144f2286 | ||
|
|
df5ae70aa2 | ||
|
|
565afe2f7d | ||
|
|
23f98687fe | ||
|
|
465d7acb3a | ||
|
|
56339e9e10 | ||
|
|
590fa22658 | ||
|
|
6c7c22ce50 | ||
|
|
1e009d5bdf | ||
|
|
814f0c94a4 | ||
|
|
2c8795bd9f | ||
|
|
7888c06c41 | ||
|
|
61388252ae | ||
|
|
8a4e95fdd3 | ||
|
|
e95ef9d127 | ||
|
|
4840b0c8ba | ||
|
|
8d1f54604e | ||
|
|
589721a953 | ||
|
|
a8ae6aaef6 | ||
|
|
805ff18e21 | ||
|
|
e4a4a8c603 | ||
|
|
8811c4e0b7 | ||
|
|
6c5e2a9a29 | ||
|
|
d967550dd8 | ||
|
|
61b014a803 | ||
|
|
793c11757d | ||
|
|
c4016d239a | ||
|
|
4bc45f4eea | ||
|
|
6dbc758cc3 | ||
|
|
569a8d0f42 | ||
|
|
52ef897137 | ||
|
|
03796fdaff | ||
|
|
46869cbcde | ||
|
|
25df66b5f8 | ||
|
|
583c0cb92f | ||
|
|
c37614ae52 | ||
|
|
fb2cbe20db | ||
|
|
88495c1068 | ||
|
|
303f16d155 | ||
|
|
8c565ffd25 | ||
|
|
3fa4eed366 | ||
|
|
3e27f0d165 | ||
|
|
2a5a101080 | ||
|
|
6727c5fa9a | ||
|
|
7787daa2da | ||
|
|
74f4f7c7eb | ||
|
|
c513320714 | ||
|
|
96df57fc90 | ||
|
|
b50fbf9d2d | ||
|
|
6eedd09e2c | ||
|
|
17e1cf8804 | ||
|
|
fe3b99d480 | ||
|
|
b164d15927 | ||
|
|
e79c4abe83 | ||
|
|
6e54aa9fea | ||
|
|
0552616bf9 | ||
|
|
7c8cfcbfce | ||
|
|
7c1f691b46 | ||
|
|
03d446cdaf | ||
|
|
9dabea34d2 | ||
|
|
5fc19db1a9 | ||
|
|
7c76e3901a | ||
|
|
fda999bfb1 | ||
|
|
3137c23479 | ||
|
|
6218c5d576 | ||
|
|
502ff0daeb | ||
|
|
c2adfc2bda | ||
|
|
29ab40e33d |
19
.clang-format
Normal file
19
.clang-format
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
PointerAlignment: Right
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
|
||||||
|
UseTab: Always
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
ColumnLimit: 80
|
||||||
|
|
||||||
|
AlignAfterOpenBracket: false
|
||||||
|
AlignOperands: AlignAfterOperator
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
BreakStringLiterals: true
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentGotoLabels: false
|
||||||
|
InsertBraces: false
|
||||||
|
...
|
||||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
manigraph
|
||||||
|
**.o
|
||||||
|
**.so
|
||||||
|
**.exe
|
||||||
|
**.dll
|
||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
|||||||
[submodule "ext/glfw"]
|
[submodule "ext/glfw"]
|
||||||
path = ext/glfw
|
path = ext/glfw
|
||||||
url = https://github.com/glfw/glfw
|
url = https://github.com/glfw/glfw
|
||||||
|
[submodule "ext/nuklear"]
|
||||||
|
path = ext/nuklear
|
||||||
|
url = https://github.com/Immediate-Mode-UI/Nuklear
|
||||||
|
|||||||
73
Makefile
73
Makefile
@@ -1,64 +1,81 @@
|
|||||||
BIN = manigraph
|
BIN = manigraph
|
||||||
|
|
||||||
OBJ = \
|
OBJ = \
|
||||||
|
ext/glad/glad.o \
|
||||||
src/context.o \
|
src/context.o \
|
||||||
src/texture.o \
|
|
||||||
src/window.o \
|
src/window.o \
|
||||||
src/matrix.o \
|
|
||||||
src/shader.o \
|
src/shader.o \
|
||||||
|
src/klein.o \
|
||||||
src/input.o \
|
src/input.o \
|
||||||
|
src/load.o \
|
||||||
src/mesh.o \
|
src/mesh.o \
|
||||||
src/alan.o \
|
src/gui.o \
|
||||||
src/main.o
|
src/main.o
|
||||||
|
|
||||||
|
EXAMPLES = \
|
||||||
|
example/basic \
|
||||||
|
example/riemman \
|
||||||
|
example/n-cube \
|
||||||
|
example/n-hilbert-cube \
|
||||||
|
example/lens
|
||||||
|
|
||||||
CFLAGS = \
|
CFLAGS = \
|
||||||
-I./ext/cglm/include \
|
-I./ext/cglm/include \
|
||||||
-I./ext/glfw/include \
|
-I./ext/glfw/include \
|
||||||
-Wall -Wno-unused-function -std=c99 \
|
-I./ext/glad \
|
||||||
|
-I./ext/nuklear \
|
||||||
|
-I./include \
|
||||||
|
-Wall -Wno-unused-function -std=c99 -D_GNU_SOURCE \
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo "Para compilar el proyecto a tu sistema operativo"
|
@echo "Usage:"
|
||||||
@echo "porfavor usa uno de los siguientes comandos:"
|
|
||||||
@echo " $(MAKE) windows"
|
@echo " $(MAKE) windows"
|
||||||
@echo " $(MAKE) linux-x11"
|
@echo " $(MAKE) linux-x11"
|
||||||
@echo " $(MAKE) linux-wayland"
|
@echo " $(MAKE) linux-wayland"
|
||||||
@echo " $(MAKE) cocoa"
|
@echo " $(MAKE) cocoa"
|
||||||
@echo "Para limpiar los archivos compilados se puede usar"
|
@echo " $(MAKE) CC=emcc wasm"
|
||||||
|
@echo "Examples"
|
||||||
|
@echo " $(MAKE) examples"
|
||||||
|
@echo "Clean"
|
||||||
@echo " $(MAKE) clean"
|
@echo " $(MAKE) clean"
|
||||||
@echo "Para ejecturar el programa sin instalarlos se puede usar:"
|
|
||||||
@echo " $(MAKE) run-linux"
|
|
||||||
|
|
||||||
# WINDOWS
|
src/main.o: src/data/shaders.h
|
||||||
windows: $(OBJ) glfw.dll
|
|
||||||
$(CC) $(CFLAGS) $(OBJ) -o $(BIN) -L. -lglfw -lopengl32 -lglew32
|
windows: $(OBJ)
|
||||||
|
cd ext; $(MAKE) -f glfw.mk windows; cd -
|
||||||
|
$(CC) $(CFLAGS) $(OBJ) -o $(BIN) -L. -lglfw -lopengl32
|
||||||
|
|
||||||
glfw.dll:
|
glfw.dll:
|
||||||
$(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@ -lgdi32
|
$(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@ -lgdi32
|
||||||
|
|
||||||
# LINUX
|
# LINUX
|
||||||
linux-x11: $(OBJ)
|
|
||||||
$(MAKE) BKN=_GLFW_X11 libglfw.so
|
|
||||||
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
|
|
||||||
|
|
||||||
linux-wayland: $(OBJ)
|
linux-wayland: $(OBJ)
|
||||||
$(MAKE) BKN=_GLFW_WAYLAND libglfw.so
|
cd ext; $(MAKE) -f glfw.mk linux-wayland; cd -
|
||||||
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
|
$(CC) -o $(BIN) $(OBJ) ext/libglfw.a -lm
|
||||||
|
|
||||||
run-linux:
|
linux-x11: $(OBJ)
|
||||||
LD_LIBRARY_PATH=. ./$(BIN)
|
cd ext; $(MAKE) -f glfw.mk linux-x11; cd -
|
||||||
|
$(CC) -o $(BIN) $(OBJ) ext/libglfw.a -lm
|
||||||
|
|
||||||
# COCOA
|
|
||||||
cocoa: $(OBJ)
|
cocoa: $(OBJ)
|
||||||
$(MAKE) BKN=_GLFW_COCOA libglfw.so
|
cd ext; $(MAKE) -f glfw.mk cocoa; cd -
|
||||||
$(CC) -framework OpenGL -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
|
$(CC) -framework OpenGL -o $(BIN) $(OBJ) ext/glfw.a -lGL -lglfw
|
||||||
|
|
||||||
libglfw.so:
|
wasm: $(OBJ)
|
||||||
$(CC) -fPIC -shared -D$(BKN) -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@
|
$(CC) -sUSE_WEBGL2=1 -sUSE_GLFW=3 -o $(BIN).html $(OBJ)
|
||||||
|
chmod -x $(BIN).wasm
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJ) $(BIN)
|
rm $(OBJ) $(BIN) $(EXAMPLES)
|
||||||
|
cd ext; $(MAKE) -f glfw.mk clean; cd -
|
||||||
|
|
||||||
.SUFFIXES: .c .o
|
|
||||||
|
examples: $(EXAMPLES)
|
||||||
|
|
||||||
|
.SUFFIXES: .c .o
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) -Wno-implicit-function-declaration $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
.c:
|
||||||
|
$(CC) -I include -o $@ $< -lm
|
||||||
|
|||||||
110
README.md
110
README.md
@@ -1,92 +1,62 @@
|
|||||||
# Manigraph: Graficadora de variedades
|
# Manigraph
|
||||||
Diaz Camacho Pedro Emilio
|
Manigraph is a cutting-edge tool for multidimentional surface visualization,
|
||||||
|
capable of handling over a hundred dimensions. It allows users to interactively
|
||||||
|
explore each dimension in an intuitive and dynamic way.
|
||||||
|
Import your .klein files, which represents multidimentional surface.
|
||||||
|
|
||||||
# Resumen
|
# Building
|
||||||
manigraph es un graficador interactiva de variedades que lee archivos binarios, con la información de
|
Manigraph is written in C99, and uses OpenGL 2.0 for the rendering. So you just
|
||||||
una variedad multidimensional y grafica esta variedad en una proyección tridimensional.
|
need a C compiler to build this project.
|
||||||
|
|
||||||
# Dependencias
|
## Source code
|
||||||
Para poder compilar el proyecto hace falta lo siguiente.
|
|
||||||
## Programas
|
|
||||||
- `cc`: Cualquier compilador de C.
|
|
||||||
- `git`: Gestor de dependencias. (Opcional)
|
|
||||||
- `make`: Herramienta para compilar automáticamente. (Opcional)
|
|
||||||
|
|
||||||
## Librerías
|
|
||||||
- `openGL`: A cross-platform API for rendering 2D and 3D graphics. (no incluida)
|
|
||||||
- `glew`: The OpenGL Extension Wrangler Library (no incluida)
|
|
||||||
- `glfw`: A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input.
|
|
||||||
- `cglm`: Highly Optimized 2D / 3D Graphics Math (glm) for C.
|
|
||||||
### Linux
|
|
||||||
Para compilar `glfw` en linux hacen falta las siguientes librerías según el caso. (no incluidas)
|
|
||||||
- `x11`: libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel
|
|
||||||
- `wayland`: libwayland-dev libxkbcommon-dev wayland-protocols
|
|
||||||
|
|
||||||
# Descargas
|
|
||||||
- [git](https://git-scm.com/downloads/win)
|
|
||||||
- [MinGW](https://github.com/niXman/mingw-builds-binaries/releases)
|
|
||||||
- [glew](https://glew.sourceforge.net/)
|
|
||||||
|
|
||||||
# Clonar el código fuente
|
|
||||||
```
|
```
|
||||||
git clone https://gitea.adles.top/software/manigraph.git
|
git clone https://gitea.axiolutions.top/software/manigraph.git
|
||||||
cd manigraph
|
cd manigraph
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
```
|
```
|
||||||
|
|
||||||
# Compilación
|
## Dependecies
|
||||||
Para compilar manualmente el proyecto se puede usar `make` o ejecutar los comandos manualmente
|
You may need system specific dependecies to build *Manigraph*.
|
||||||
en el código fuente de `manigraph`.
|
[Reference](https://www.glfw.org/docs/3.3/compile.html#compile_deps)
|
||||||
|
|
||||||
## Make
|
### Linux
|
||||||
Los siguientes comandos sirven para compilar `manigraph` deacuerdo al sistema operativo.
|
- `x11`: libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel
|
||||||
|
- `wayland`: libwayland-dev libxkbcommon-dev wayland-protocols
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
A C compiler is needed for building *Manigraph*. and any of those commands
|
||||||
|
|
||||||
```
|
```
|
||||||
make windows
|
make windows
|
||||||
|
./compile.bat
|
||||||
make linux-x11
|
make linux-x11
|
||||||
make linux-wayland
|
make linux-wayland
|
||||||
make cocoa
|
make cocoa
|
||||||
|
make CC=emcc wasm
|
||||||
```
|
```
|
||||||
|
|
||||||
## Manualmente
|
# Flow of Manigraph
|
||||||
se pueden compilar el proyecto manualmente sin necesidad del programa `make`.
|

|
||||||
|
|
||||||
### GLFW
|
# Design
|
||||||
Si tienes problemas compilando `GLFW` puedes checar su página web oficial
|
Manigraph is a program designed with sustainability in mind. It is built to be
|
||||||
explicando el tema: [Compiling GLFW](https://www.glfw.org/docs/3.3/compile.html).
|
portable, resource-efficient, and easy to maintain and scale. The program
|
||||||
|
follows a Data-Oriented Programming (DOP) paradigm, where each file is
|
||||||
|
responsible for a specific data type and manages its own dependencies. Each
|
||||||
|
function is named after the file it resides in, ensuring a clear organization
|
||||||
|
and structure.
|
||||||
|
|
||||||
#### Windows
|
The independence of data types allows for efficient scaling and maintenance.
|
||||||
```
|
The main file is a special case in this design: it is responsible for combining
|
||||||
cc -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o glfw.dll -lgdi32
|
all the data types in a comprehensive manner, actng as the workflow of the program.
|
||||||
```
|
|
||||||
|
|
||||||
#### Linux
|
# Contributing
|
||||||
```
|
Before commiting use `clang-format`, for coding style consistency. Your
|
||||||
cc -fPIC -shared -D_GLFW_X11 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o libglfw.so
|
contribution must be whitin the design principles and the concept of Manigraph.
|
||||||
cc -fPIC -shared -D_GLFW_WAYLAND -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o libglfw.so
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Mac
|
The following diagram illustrates the relationships between files, showing how
|
||||||
```
|
they are connected through dependencies. It also highlights the scenarios where
|
||||||
cc -fPIC -shared -D_GLFW_COCOA -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o libglfw.so
|
files are not independent of one another,
|
||||||
```
|
|
||||||
|
|
||||||
### Manigraph
|

|
||||||
#### Windows
|
|
||||||
```
|
|
||||||
cc -I ext/cglm/include/ -I ext/glfw/include/ src/*.c -o manigraph -L. -lglfw -lopengl32 -lglew32
|
|
||||||
```
|
|
||||||
#### Linux
|
|
||||||
```
|
|
||||||
cc -I ext/cglm/include/ -I ext/glfw/include/ src/*.c -o manigraph -L. -lglfw -lGL -lGLEW
|
|
||||||
```
|
|
||||||
#### Mac
|
|
||||||
```
|
|
||||||
cc -framework GL -I ext/cglm/include/ -I ext/glfw/include/ src/*.c -o manigraph -L. -lglfw -lGLEW
|
|
||||||
```
|
|
||||||
|
|
||||||
# Ejecutar
|
|
||||||
En linux se puede ejecutar el programa sin instalar la libreria de glfw usando:
|
|
||||||
```
|
|
||||||
LD_LIBRARY_PATH=. ./manigraph
|
|
||||||
```
|
|
||||||
|
|||||||
3
compile.bat
Normal file
3
compile.bat
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
:: git submodule update --init --recursive
|
||||||
|
:: gcc -fPIC -shared -Iext/glfw/deps/MinGW -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o glfw.dll -lgdi32
|
||||||
|
gcc -I ext/glad -I ext/cglm/include -I ext/nuklear -I ext/glfw/include src/*.c ext/glad/glad.c -o manigraph -L . -lglfw -lopengl32
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
# Estructura de archivos
|
|
||||||
Díaz Camacho Pedro Emilio
|
|
||||||
|
|
||||||
# Headers
|
|
||||||
## main.h
|
|
||||||
Este archivo incluye los prototipos internos, que va a usar el programa
|
|
||||||
funge como api interna para los desarrolladores y debe estar bien documentada.
|
|
||||||
|
|
||||||
# codigo fuente
|
|
||||||
|
|
||||||
## main.c
|
|
||||||
Este archivo debe configurar el programa antes de iniciarse, avisar de los problemas
|
|
||||||
que eviten que el programa se ejecute correctamente, iniciar y terminar los objetos que use el
|
|
||||||
programa, así como ejecutar la función principal
|
|
||||||
### Depende de
|
|
||||||
- <GL/gl.h>
|
|
||||||
|
|
||||||
## context.c
|
|
||||||
En este archivo se escoge un color para limpiar la pantalla y tiene una función para limpiar
|
|
||||||
tanto lo dibujado en pantalla, como distintos buffers gráficos.
|
|
||||||
### Depende de
|
|
||||||
- <GL/gl.h>
|
|
||||||
|
|
||||||
## input.c
|
|
||||||
Incluye la función `poll_input`, que se ejecuta en cada ciclo del programa y devuelve un
|
|
||||||
cuaternion de tipo `float *` que representa la rotación total del cubo, después de interactuar
|
|
||||||
con el programa.
|
|
||||||
### Depende de
|
|
||||||
- <GLFW/glfw3.h>
|
|
||||||
- <cglm/quat.h>
|
|
||||||
|
|
||||||
## matrix.c
|
|
||||||
Incluye las funciónes para configurar y cargar en la GPU las 3 matrices principales.
|
|
||||||
- `fix_matrix` esta matriz no cambia y se usa para configurar la perspectiva y la vista que
|
|
||||||
va a usar el programa en todo momento.
|
|
||||||
- `mdl_matrix` esta matriz depende de cada mesh y describe la rotación única de cada objeto,
|
|
||||||
se usa para rotar los ejes ortogonamente con un indice.
|
|
||||||
- `rot_matrix` esta matriz describe la rotación total de todos los objetos y se configura con
|
|
||||||
un cuaternio
|
|
||||||
### Depende de
|
|
||||||
- <cglm/mat4.h>
|
|
||||||
- <cglm/cam.h>
|
|
||||||
- <cglm/quat.h>
|
|
||||||
|
|
||||||
## mesh.c
|
|
||||||
Este archivo se usa para crear, destruir y dibujar objetos de tipo `mesh`, un `mesh` es una
|
|
||||||
colección de triángulos que describen un objeto multidimensional.
|
|
||||||
### Depende de
|
|
||||||
- <GL/gl.h>
|
|
||||||
- <stdlib.h>
|
|
||||||
|
|
||||||
## shader.c
|
|
||||||
Debe crear, destruir y usar los shaders, estos shaders son programas para la gpu escritos en glsl para
|
|
||||||
además aquí se carga memoria en gpu con las funciónes `gload_`
|
|
||||||
### Depende de
|
|
||||||
- <GL/gl.h>
|
|
||||||
|
|
||||||
## texture.c
|
|
||||||
Debe cargar, usar y destruir las texturas, que va a usar la gpu, también crea una textura
|
|
||||||
para una paleta de colores definida, esto para manipular fácilmente los colores que usará el programa.
|
|
||||||
### Depende de
|
|
||||||
- <GL/gl.h>
|
|
||||||
|
|
||||||
## window.c
|
|
||||||
Crea, usa, limpie y cierra una ventana, una ventana tiene un contexto de OpenGL asociado para poder
|
|
||||||
dibujar objetos en ella, tiene una función especial para avisar si la ventana está abierta para
|
|
||||||
dibujar.
|
|
||||||
### Depende de
|
|
||||||
- <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
# Datos
|
|
||||||
## data/cube.h
|
|
||||||
Aquí esta la información del mesh de un cubo, este se va a borrar cuando podamos
|
|
||||||
importar meshes para graficarlos.
|
|
||||||
|
|
||||||
## data/axis.h
|
|
||||||
Aquí está el mesh de un solo eje, este se va a rotar para hacer los otros 2 ejes.
|
|
||||||
|
|
||||||
## data/shaders.h
|
|
||||||
Aquí estan los shaders en glsl para dibujar en pantalla
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
# Tipos de datos del proyecto
|
|
||||||
Díaz Camacho Pedro Emilio
|
|
||||||
|
|
||||||
# Introducción
|
|
||||||
En este archivo vamos a detallar los tipos de datos únicos del programa, estos
|
|
||||||
tipos de datos son estructuras que representan objetos computacionales y son
|
|
||||||
necesarios para integrar las distintas partes del programa.
|
|
||||||
|
|
||||||
## window_t
|
|
||||||
En `window.c` tenemos una estructura que es la ventana y esta se representa por `window_t`,
|
|
||||||
este tipo de dato es un pointer que es manejado por `glfw`.
|
|
||||||
|
|
||||||
## id_t
|
|
||||||
`id_t` es un tipo de dato que representa objetos de `OpenGL`, estos datos
|
|
||||||
normalmente vienen enumerados, y en `manigraph` se usan para representar `shaders`,
|
|
||||||
`programs` y `texture`.
|
|
||||||
|
|
||||||
## mesh_t
|
|
||||||
Este es un tipo de dato usado para interactuar con `mesh.c`, este representa la triangulación de un
|
|
||||||
objeto gráfico y funciona ocultando las variables que `OpenGL` necesita en un `void *`.
|
|
||||||
|
|
||||||
## mat4_t
|
|
||||||
`mat4_t` se usará para representar las matrices, se usará este tipo de dato exclusivamente
|
|
||||||
en `matrix.c` y funcionará con el tipo de dato `mat4` de `cglm`.
|
|
||||||
|
|
||||||
## quat_t
|
|
||||||
Este tipo de dato sirve para representar un quaternio, este quaternio representa la rotación
|
|
||||||
del objeto gráficado en la proyección tridimensional, y se usará para crear una matriz que
|
|
||||||
pueda entender `glsl`.
|
|
||||||
|
|
||||||
## narray
|
|
||||||
`narray` es un tipo de dato que funciona como un `array` enumerado, esto significa que el primer
|
|
||||||
elemento del `array` dice cuantos elementos tiene este, sin contar el primer elemento, y los demas elementos
|
|
||||||
funcionan como un `array` normal.
|
|
||||||
|
|
||||||
esta estructura nos ayuda a trabajar con arrays de tamaños arbitrario de forma óptima y sin tener que marcar el
|
|
||||||
último elemento de forma especial.
|
|
||||||
|
|
||||||
### narray_u8_t
|
|
||||||
es un `narray` para `char` y `unsigned char`.
|
|
||||||
### narray_float_t
|
|
||||||
es un `narray` para `float`.
|
|
||||||
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
# Manual de Diseño
|
|
||||||
Diaz Camacho Pedro Emilio
|
|
||||||
|
|
||||||
# Objetivos
|
|
||||||
## Prioridad alta
|
|
||||||
- [ ] El programa debe actualizarse cuando interactuan con el.
|
|
||||||
- [ ] El usuario quiere:
|
|
||||||
- [X] Ver 3 ejes en todo momento.
|
|
||||||
- [ ] Ver que ejes esta viendo.
|
|
||||||
- [ ] Ver cuantos ejes hay.
|
|
||||||
- [X] El usuario quiere:
|
|
||||||
- [X] Rotar estos ejes,
|
|
||||||
- [X] Ver donde quedan los ejes despues de la rotados.
|
|
||||||
- [ ] El usuario experimentado quiere ejecutar el programa y pasar la variedad:
|
|
||||||
- [ ] Como argumento del programa.
|
|
||||||
- [ ] Desde la entrada estandar del programa.
|
|
||||||
|
|
||||||
## Prioridad media
|
|
||||||
|
|
||||||
- [ ] El usuario quiere:
|
|
||||||
- [ ] Cambiar los ejes que se ven por pares.
|
|
||||||
- [ ] Cambiar los ejes donde esta la informacion de los ejes.
|
|
||||||
- [ ] El usuario quiere interactuar con el programa:
|
|
||||||
- [ ] Usando solo el mouse.
|
|
||||||
- [ ] Usando solo el teclado.
|
|
||||||
|
|
||||||
## Prioridad baja
|
|
||||||
- [ ] El usuario quiere guardar las transformaciones como un archivo GIF.
|
|
||||||
|
|
||||||
# Camino
|
|
||||||
|
|
||||||
0. Graficadora de un cubo.
|
|
||||||
1. Se hace un programa que muestre un cubo.
|
|
||||||
1. Se muestran los 3 ejes del cubo
|
|
||||||
1. Se rota el cubo en sus 3 ejes usando el teclado.
|
|
||||||
1. Se rota el cubo en sus 3 ejes usando el mouse.
|
|
||||||
1. Se muestran la etiqueta de los ejes.
|
|
||||||
1. Se hace el formato de objetos multidimensionales.
|
|
||||||
0. Programa ejemplo
|
|
||||||
1. Se hace un programa que divida un cuadrado en triangulos.
|
|
||||||
1. Se mapea cada vertice del triangulo en un punto de la cinta de
|
|
||||||
mobius usando una parametrizacion
|
|
||||||
1. Se mapea cada vertice del triangulo en un punto de la botella de
|
|
||||||
klein usando una parametrizacion
|
|
||||||
1. Se divide cada lado de un cubo de n dimensiones, en triangulos.
|
|
||||||
|
|
||||||
0. Graficadora de variedades
|
|
||||||
1. Se generaliza el programa para usar este formato.
|
|
||||||
1. Se muestran la informacion de los ejes mostrados y cuantos hay.
|
|
||||||
1. Se pueden cambiar los ejes por pares
|
|
||||||
1. Usando el mouse.
|
|
||||||
1. Usando el teclado.
|
|
||||||
0. Detalles.
|
|
||||||
1. Se anima el cambio de eje.
|
|
||||||
1. Se hace el generador de GIF.
|
|
||||||
1. Se puede cambiar el shader
|
|
||||||
1. Documentacion
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# Problemas esperados al desarrollar
|
|
||||||
Diaz Camacho Pedro Emilio
|
|
||||||
|
|
||||||
## OpenGL esperan objetos tridimensionales, no de n dimensiones.
|
|
||||||
|
|
||||||
Usando glVertexAttribPointer podemos pasar las coordenadas que
|
|
||||||
queramos de los puntos de las variedades, y con ello usar objetos 3D en
|
|
||||||
el shader.
|
|
||||||
|
|
||||||
## Rotar ejes por pares en una animacion continua.
|
|
||||||
- Con glVertexAttribPointer podemos pasar las coordenadas del eje
|
|
||||||
seleccionado, al shader.
|
|
||||||
- Con la funcion mix del shader y bloqueando el input, podemos hacer
|
|
||||||
una animacion pasando una variable con la cpu.
|
|
||||||
- Cuando la animacion termine intercambiar los indices del layout,
|
|
||||||
usando glVertexAttribPointer otra vez.
|
|
||||||
|
|
||||||
## Volumen de la variedad.
|
|
||||||
Dado que la funcion parametrizadora es continua, mandamos la frontera
|
|
||||||
de un n-cubo a la frontera de una variedad, por lo que solo basta
|
|
||||||
graficar la frontera de la variedad.
|
|
||||||
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# Manual de usario para Manigraph
|
|
||||||
Manigraph es un graficador interactivo de variedades que lee archivos
|
|
||||||
binarios de una variedad multidimensional y los proyecta a 3 dimensiones.
|
|
||||||
|
|
||||||
# Glosario
|
|
||||||
Llamaremos a los 3 ejes de la proyección tridimensional `X`, `Y` y `Z`,
|
|
||||||
este sistema de coordenadas es derecho con el eje `Z` apuntando afuera de la pantalla
|
|
||||||
|
|
||||||
# Controles
|
|
||||||
## Teclado
|
|
||||||
- `Q` Rota el eje `X` de forma horaria.
|
|
||||||
- `W` Rota el eje `X` de forma antihoraria.
|
|
||||||
- `A` Rota el eje `Y` de forma horaria.
|
|
||||||
- `S` Rota el eje `Y` de forma antihoraria.
|
|
||||||
- `Z` Rota el eje `Z` de forma horaria.
|
|
||||||
- `X` Rota el eje `Z` de forma antihoraria.
|
|
||||||
## Mouse
|
|
||||||
- Hacer `click` en un eje lo selecciona.
|
|
||||||
- El `scroll` del mouse hace girar al eje seleccionado.
|
|
||||||
10
doc/file_layout.svg
Normal file
10
doc/file_layout.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 39 KiB |
10
doc/flow.svg
Normal file
10
doc/flow.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 107 KiB |
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;
|
||||||
|
}
|
||||||
54
example/lens.c
Normal file
54
example/lens.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define KLEIN_IMPLEMENT
|
||||||
|
#include <klein/klein.h>
|
||||||
|
#include <klein/norm.h>
|
||||||
|
#include <klein/parm.h>
|
||||||
|
|
||||||
|
int p = 37;
|
||||||
|
int q = 7;
|
||||||
|
|
||||||
|
void lens(float *d_surface, int *coord, unsigned char * grid)
|
||||||
|
{
|
||||||
|
|
||||||
|
float norm = 0;
|
||||||
|
float sphere[4];
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
sphere[i] = ((float)coord[i] / grid[i]) - 0.5;
|
||||||
|
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
norm += sphere[i] * sphere[i];
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
sphere[i] = sphere[i] / sqrt(norm);
|
||||||
|
|
||||||
|
d_surface[0] = (sphere[0] * cos(2 * M_PI / p)) - (sphere[1] * sin(2 * M_PI / p));
|
||||||
|
d_surface[1] = (sphere[0] * sin(2 * M_PI / p)) + (sphere[1] * cos(2 * M_PI / p));
|
||||||
|
d_surface[2] = (sphere[2] * cos(2 * M_PI * q / p)) - (sphere[3] * sin(2 * M_PI * q / p));
|
||||||
|
d_surface[3] = (sphere[2] * sin(2 * M_PI * q / p)) + (sphere[3] * cos(2 * M_PI * q / p));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
char file_name[0xff];
|
||||||
|
struct klein klein;
|
||||||
|
struct parm parametrization = {
|
||||||
|
.grid = (unsigned char[]){8, 8,8,8},
|
||||||
|
.m = 4,
|
||||||
|
.n = 4,
|
||||||
|
.f = lens,
|
||||||
|
};
|
||||||
|
|
||||||
|
snprintf(file_name, 0xff, "lens-%03d-%03d.klein", p, q);
|
||||||
|
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;
|
||||||
|
}
|
||||||
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 = 10;
|
||||||
|
|
||||||
|
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, "cube-%03d.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;
|
||||||
|
}
|
||||||
1641
ext/glad/glad.c
Normal file
1641
ext/glad/glad.c
Normal file
File diff suppressed because it is too large
Load Diff
3191
ext/glad/glad.h
Normal file
3191
ext/glad/glad.h
Normal file
File diff suppressed because it is too large
Load Diff
311
ext/glad/khrplatform.h
Normal file
311
ext/glad/khrplatform.h
Normal file
@@ -0,0 +1,311 @@
|
|||||||
|
#ifndef __khrplatform_h_
|
||||||
|
#define __khrplatform_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||||
|
**
|
||||||
|
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
** copy of this software and/or associated documentation files (the
|
||||||
|
** "Materials"), to deal in the Materials without restriction, including
|
||||||
|
** without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
** permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
** the following conditions:
|
||||||
|
**
|
||||||
|
** The above copyright notice and this permission notice shall be included
|
||||||
|
** in all copies or substantial portions of the Materials.
|
||||||
|
**
|
||||||
|
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Khronos platform-specific types and definitions.
|
||||||
|
*
|
||||||
|
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||||
|
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||||
|
* The last semantic modification to khrplatform.h was at commit ID:
|
||||||
|
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||||
|
*
|
||||||
|
* Adopters may modify this file to suit their platform. Adopters are
|
||||||
|
* encouraged to submit platform specific modifications to the Khronos
|
||||||
|
* group so that they can be included in future versions of this file.
|
||||||
|
* Please submit changes by filing pull requests or issues on
|
||||||
|
* the EGL Registry repository linked above.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* See the Implementer's Guidelines for information about where this file
|
||||||
|
* should be located on your system and for more details of its use:
|
||||||
|
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||||
|
*
|
||||||
|
* This file should be included as
|
||||||
|
* #include <KHR/khrplatform.h>
|
||||||
|
* by Khronos client API header files that use its types and defines.
|
||||||
|
*
|
||||||
|
* The types in khrplatform.h should only be used to define API-specific types.
|
||||||
|
*
|
||||||
|
* Types defined in khrplatform.h:
|
||||||
|
* khronos_int8_t signed 8 bit
|
||||||
|
* khronos_uint8_t unsigned 8 bit
|
||||||
|
* khronos_int16_t signed 16 bit
|
||||||
|
* khronos_uint16_t unsigned 16 bit
|
||||||
|
* khronos_int32_t signed 32 bit
|
||||||
|
* khronos_uint32_t unsigned 32 bit
|
||||||
|
* khronos_int64_t signed 64 bit
|
||||||
|
* khronos_uint64_t unsigned 64 bit
|
||||||
|
* khronos_intptr_t signed same number of bits as a pointer
|
||||||
|
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||||
|
* khronos_ssize_t signed size
|
||||||
|
* khronos_usize_t unsigned size
|
||||||
|
* khronos_float_t signed 32 bit floating point
|
||||||
|
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||||
|
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||||
|
* nanoseconds
|
||||||
|
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||||
|
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||||
|
* only be used as a base type when a client API's boolean type is
|
||||||
|
* an enum. Client APIs which use an integer or other type for
|
||||||
|
* booleans cannot use this as the base type for their boolean.
|
||||||
|
*
|
||||||
|
* Tokens defined in khrplatform.h:
|
||||||
|
*
|
||||||
|
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||||
|
*
|
||||||
|
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||||
|
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||||
|
*
|
||||||
|
* Calling convention macros defined in this file:
|
||||||
|
* KHRONOS_APICALL
|
||||||
|
* KHRONOS_APIENTRY
|
||||||
|
* KHRONOS_APIATTRIBUTES
|
||||||
|
*
|
||||||
|
* These may be used in function prototypes as:
|
||||||
|
*
|
||||||
|
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||||
|
* int arg1,
|
||||||
|
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||||
|
# define KHRONOS_STATIC 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APICALL
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This precedes the return type of the function in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(KHRONOS_STATIC)
|
||||||
|
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||||
|
* header compatible with static linking. */
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
# define KHRONOS_APICALL __declspec(dllimport)
|
||||||
|
#elif defined (__SYMBIAN32__)
|
||||||
|
# define KHRONOS_APICALL IMPORT_C
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIENTRY
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the return type of the function and precedes the function
|
||||||
|
* name in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||||
|
/* Win32 but not WinCE */
|
||||||
|
# define KHRONOS_APIENTRY __stdcall
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APIENTRY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIATTRIBUTES
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the closing parenthesis of the function prototype arguments.
|
||||||
|
*/
|
||||||
|
#if defined (__ARMCC_2__)
|
||||||
|
#define KHRONOS_APIATTRIBUTES __softfp
|
||||||
|
#else
|
||||||
|
#define KHRONOS_APIATTRIBUTES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* basic type definitions
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <stdint.h>
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
/*
|
||||||
|
* To support platform where unsigned long cannot be used interchangeably with
|
||||||
|
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||||
|
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||||
|
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||||
|
* unsigned long long or similar (this results in different C++ name mangling).
|
||||||
|
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||||
|
* platforms where the size of a pointer is larger than the size of long.
|
||||||
|
*/
|
||||||
|
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||||
|
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||||
|
#define KHRONOS_USE_INTPTR_T
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__VMS ) || defined(__sgi)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <inttypes.h>
|
||||||
|
*/
|
||||||
|
#include <inttypes.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Win32
|
||||||
|
*/
|
||||||
|
typedef __int32 khronos_int32_t;
|
||||||
|
typedef unsigned __int32 khronos_uint32_t;
|
||||||
|
typedef __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(__sun__) || defined(__digital__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sun or Digital
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#if defined(__arch64__) || defined(_LP64)
|
||||||
|
typedef long int khronos_int64_t;
|
||||||
|
typedef unsigned long int khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef long long int khronos_int64_t;
|
||||||
|
typedef unsigned long long int khronos_uint64_t;
|
||||||
|
#endif /* __arch64__ */
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hypothetical platform with no float or int64 support
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 0
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic fallback
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that are (so far) the same on all platforms
|
||||||
|
*/
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||||
|
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||||
|
* to be the only LLP64 architecture in current use.
|
||||||
|
*/
|
||||||
|
#ifdef KHRONOS_USE_INTPTR_T
|
||||||
|
typedef intptr_t khronos_intptr_t;
|
||||||
|
typedef uintptr_t khronos_uintptr_t;
|
||||||
|
#elif defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef unsigned long long int khronos_uintptr_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef unsigned long int khronos_uintptr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
typedef unsigned long long int khronos_usize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
typedef unsigned long int khronos_usize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_FLOAT
|
||||||
|
/*
|
||||||
|
* Float type
|
||||||
|
*/
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_INT64
|
||||||
|
/* Time types
|
||||||
|
*
|
||||||
|
* These types can be used to represent a time interval in nanoseconds or
|
||||||
|
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||||
|
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||||
|
* time the system booted). The Unadjusted System Time is an unsigned
|
||||||
|
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||||
|
* may be either signed or unsigned.
|
||||||
|
*/
|
||||||
|
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||||
|
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dummy value used to pad enum types to 32 bits.
|
||||||
|
*/
|
||||||
|
#ifndef KHRONOS_MAX_ENUM
|
||||||
|
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enumerated boolean type
|
||||||
|
*
|
||||||
|
* Values other than zero should be considered to be true. Therefore
|
||||||
|
* comparisons should not be made against KHRONOS_TRUE.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
KHRONOS_FALSE = 0,
|
||||||
|
KHRONOS_TRUE = 1,
|
||||||
|
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||||
|
} khronos_boolean_enum_t;
|
||||||
|
|
||||||
|
#endif /* __khrplatform_h_ */
|
||||||
71
ext/glfw.mk
Normal file
71
ext/glfw.mk
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
BIN = libglfw.a
|
||||||
|
OBJ = \
|
||||||
|
glfw/src/context.o \
|
||||||
|
glfw/src/egl_context.o \
|
||||||
|
glfw/src/glx_context.o \
|
||||||
|
glfw/src/init.o \
|
||||||
|
glfw/src/input.o \
|
||||||
|
glfw/src/linux_joystick.o \
|
||||||
|
glfw/src/monitor.o \
|
||||||
|
glfw/src/null_init.o \
|
||||||
|
glfw/src/null_joystick.o \
|
||||||
|
glfw/src/null_monitor.o \
|
||||||
|
glfw/src/null_window.o \
|
||||||
|
glfw/src/osmesa_context.o \
|
||||||
|
glfw/src/platform.o \
|
||||||
|
glfw/src/posix_module.o \
|
||||||
|
glfw/src/posix_poll.o \
|
||||||
|
glfw/src/posix_thread.o \
|
||||||
|
glfw/src/posix_time.o \
|
||||||
|
glfw/src/vulkan.o \
|
||||||
|
glfw/src/wgl_context.o \
|
||||||
|
glfw/src/win32_init.o \
|
||||||
|
glfw/src/win32_joystick.o \
|
||||||
|
glfw/src/win32_module.o \
|
||||||
|
glfw/src/win32_monitor.o \
|
||||||
|
glfw/src/win32_thread.o \
|
||||||
|
glfw/src/win32_time.o \
|
||||||
|
glfw/src/win32_window.o \
|
||||||
|
glfw/src/window.o \
|
||||||
|
glfw/src/wl_init.o \
|
||||||
|
glfw/src/wl_monitor.o \
|
||||||
|
glfw/src/wl_window.o \
|
||||||
|
glfw/src/x11_init.o \
|
||||||
|
glfw/src/x11_monitor.o \
|
||||||
|
glfw/src/x11_window.o \
|
||||||
|
glfw/src/xkb_unicode.o
|
||||||
|
|
||||||
|
WAYLAND-LIB = \
|
||||||
|
xdg-shell \
|
||||||
|
relative-pointer-unstable-v1 \
|
||||||
|
xdg-decoration-unstable-v1 \
|
||||||
|
pointer-constraints-unstable-v1 \
|
||||||
|
viewporter \
|
||||||
|
idle-inhibit-unstable-v1 \
|
||||||
|
fractional-scale-v1 \
|
||||||
|
xdg-activation-v1 \
|
||||||
|
wayland
|
||||||
|
|
||||||
|
windows:
|
||||||
|
$(MAKE) $(OBJ) CFLAGS="-D_GLFW_WIN32 -Iglfw/deps/wayland"
|
||||||
|
$(AR) rsc $(BIN) $(OBJ)
|
||||||
|
|
||||||
|
linux-x11:
|
||||||
|
$(MAKE) $(OBJ) CFLAGS="-D_GLFW_X11 -Iglfw/deps/wayland"
|
||||||
|
$(AR) rsc $(BIN) $(OBJ)
|
||||||
|
|
||||||
|
|
||||||
|
linux-wayland:
|
||||||
|
for i in $(WAYLAND-LIB); \
|
||||||
|
do \
|
||||||
|
wayland-scanner client-header glfw/deps/wayland/$$i.xml glfw/deps/wayland/$$i-client-protocol.h; \
|
||||||
|
wayland-scanner private-code glfw/deps/wayland/$$i.xml glfw/deps/wayland/$$i-client-protocol-code.h; \
|
||||||
|
done
|
||||||
|
$(MAKE) $(OBJ) CFLAGS="-D_GLFW_WAYLAND -fPIC -Iglfw/deps/wayland"
|
||||||
|
$(AR) rsc $(BIN) $(OBJ)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm $(OBJ) $(BIN)
|
||||||
|
rm glfw/deps/wayland/*.h
|
||||||
1
ext/nuklear
Submodule
1
ext/nuklear
Submodule
Submodule ext/nuklear added at 6566d9075d
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, 4, klein.vertex_size * klein.dim, file);
|
||||||
|
fwrite(klein.normals, 4, klein.vertex_size * klein.dim, file);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
132
include/klein/norm.h
Normal file
132
include/klein/norm.h
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
#ifdef KLEIN_NORM_H
|
||||||
|
#error file included twice
|
||||||
|
#endif
|
||||||
|
#define KLEIN_NORM_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef KLEIN_H
|
||||||
|
#warning Please include klein/klein.h
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void klein_normalize(struct klein * klein);
|
||||||
|
|
||||||
|
#ifdef KLEIN_IMPLEMENT
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
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
|
||||||
@@ -1,13 +1,31 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#else
|
||||||
|
#include <glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void set_clean_color_context( unsigned char r, unsigned char g, unsigned char b )
|
void set_clean_color_context(unsigned char r, unsigned char g, unsigned char b)
|
||||||
{
|
{
|
||||||
glEnable( GL_DEPTH_TEST );
|
glClearColor((float)r / 0xff, (float)g / 0xff, (float)b / 0xff, 1.0);
|
||||||
glClearColor( (float)r/0xff, (float)g/0xff, (float)b/0xff, 1.0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clean_context( void )
|
int init_context(void)
|
||||||
{
|
{
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
#ifdef EMSCRIPTEN
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
|
return gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void clean_context(void)
|
||||||
|
{
|
||||||
|
/* This is important cos, Nuklear Disable DEPTH TEST */
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
#undef A
|
|
||||||
#undef B
|
|
||||||
#undef C
|
|
||||||
#undef D
|
|
||||||
#undef E
|
|
||||||
#undef F
|
|
||||||
#undef G
|
|
||||||
#undef H
|
|
||||||
|
|
||||||
const float X = 2.0;
|
|
||||||
const float Y = 0.05;
|
|
||||||
const float Z = 0.05;
|
|
||||||
|
|
||||||
#define A -X,-Y,-Z,
|
|
||||||
#define B -X,-Y, Z,
|
|
||||||
#define C -X, Y,-Z,
|
|
||||||
#define D -X, Y, Z,
|
|
||||||
#define E X,-Y,-Z,
|
|
||||||
#define F X,-Y, Z,
|
|
||||||
#define G X, Y,-Z,
|
|
||||||
#define H X, Y, Z,
|
|
||||||
|
|
||||||
narray_float_t d_axis =
|
|
||||||
{
|
|
||||||
3*3*2*6,
|
|
||||||
|
|
||||||
A C E
|
|
||||||
C E G
|
|
||||||
|
|
||||||
E G F
|
|
||||||
G F H
|
|
||||||
|
|
||||||
F H B
|
|
||||||
H B D
|
|
||||||
|
|
||||||
B D A
|
|
||||||
D A C
|
|
||||||
|
|
||||||
C D G
|
|
||||||
D G H
|
|
||||||
|
|
||||||
A B E
|
|
||||||
B E F
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -1,30 +1,98 @@
|
|||||||
const char * vs =
|
const char *vs =
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
"#version 300 es\n"
|
||||||
|
"precision highp float;"
|
||||||
|
#else
|
||||||
"#version 330 core\n"
|
"#version 330 core\n"
|
||||||
|
#endif
|
||||||
|
"layout (location = 0) in float aPos_x;"
|
||||||
|
"layout (location = 1) in float aPos_y;"
|
||||||
|
"layout (location = 2) in float aPos_z;"
|
||||||
|
"layout (location = 3) in float aPos_w;"
|
||||||
|
|
||||||
"layout (location = 0) in vec3 aPos;"
|
"layout (location = 4) in float aNormal_x;"
|
||||||
|
"layout (location = 5) in float aNormal_y;"
|
||||||
|
"layout (location = 6) in float aNormal_z;"
|
||||||
|
"layout (location = 7) in float aNormal_w;"
|
||||||
|
|
||||||
|
"uniform float angle;"
|
||||||
|
"uniform float i;"
|
||||||
|
"uniform vec4 color;"
|
||||||
|
|
||||||
"uniform float idx;"
|
|
||||||
"uniform mat4 fix;"
|
"uniform mat4 fix;"
|
||||||
"uniform mat4 rot;"
|
"uniform mat4 rot;"
|
||||||
"uniform mat4 mdl;"
|
|
||||||
|
|
||||||
"out float index;"
|
"out vec3 Normal;"
|
||||||
|
"out vec3 FragPos;"
|
||||||
|
"out vec4 Color;"
|
||||||
|
|
||||||
|
"mat2 rotate2d( float angle )"
|
||||||
|
"{"
|
||||||
|
"return mat2( cos(angle), sin(angle), -sin(angle), cos(angle) );"
|
||||||
|
"}"
|
||||||
|
|
||||||
"void main()"
|
"void main()"
|
||||||
"{"
|
"{"
|
||||||
" index=idx;"
|
" Color=color;"
|
||||||
" gl_Position = fix * rot * mdl * vec4( aPos, 1.0 );\n"
|
|
||||||
|
" vec3 aNormal = vec3(aNormal_x,aNormal_y,aNormal_z);"
|
||||||
|
" vec3 aPos = vec3(aPos_x,aPos_y,aPos_z);"
|
||||||
|
|
||||||
|
" 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))) * aNormal;"
|
||||||
|
" gl_Position = fix * rot * vec4( aPos, 1.0 );\n"
|
||||||
|
" FragPos = vec3( rot * vec4(aPos, 1.0));"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
const char * fs =
|
const char *fs_plain =
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
"#version 300 es\n"
|
||||||
|
"precision highp float;"
|
||||||
|
#else
|
||||||
"#version 330 core\n"
|
"#version 330 core\n"
|
||||||
|
#endif
|
||||||
|
"out vec4 FragColor;"
|
||||||
|
"in vec3 Normal;"
|
||||||
|
"in vec3 FragPos;"
|
||||||
|
"in vec4 Color;"
|
||||||
|
|
||||||
"uniform sampler2DArray palette;"
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" FragColor = vec4(pow(vec3(Color),vec3(1.0/1.0)),Color.a);"
|
||||||
|
"}";
|
||||||
|
|
||||||
|
const char *fs =
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
"#version 300 es\n"
|
||||||
|
"precision highp float;"
|
||||||
|
#else
|
||||||
|
"#version 330 core\n"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
"in vec3 Normal;"
|
||||||
|
"in vec3 FragPos;"
|
||||||
|
"in vec4 Color;"
|
||||||
|
|
||||||
"in float index;"
|
|
||||||
"out vec4 FragColor;"
|
"out vec4 FragColor;"
|
||||||
|
|
||||||
"void main()"
|
"void main()"
|
||||||
"{"
|
"{"
|
||||||
" FragColor = texture( palette, vec3( 0, 0, index ) ).rgba;"
|
|
||||||
|
" vec3 viewPos = vec3(0, 0, -15);\n"
|
||||||
|
" vec3 viewDir = normalize(viewPos - FragPos);\n"
|
||||||
|
|
||||||
|
" vec3 lightPos = viewPos;\n"
|
||||||
|
" vec3 lightDir = normalize(lightPos - FragPos);\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"
|
||||||
|
|
||||||
|
" vec3 result = pow((0.5 + 0.5*diffuse + 1*specular) * Color.rgb, "
|
||||||
|
"vec3(1.0/2.2));\n"
|
||||||
|
" FragColor = vec4(result, Color.a);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|||||||
83
src/gui.c
Normal file
83
src/gui.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#include <glad.h>
|
||||||
|
#include "main.h"
|
||||||
|
#define MAX_VERTEX_BUFFER 512 * 1024
|
||||||
|
#define MAX_ELEMENT_BUFFER 128 * 1024
|
||||||
|
#define NK_INCLUDE_FIXED_TYPES
|
||||||
|
#define NK_INCLUDE_STANDARD_IO
|
||||||
|
#define NK_INCLUDE_STANDARD_VARARGS
|
||||||
|
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||||
|
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||||
|
#define NK_INCLUDE_FONT_BAKING
|
||||||
|
#define NK_INCLUDE_DEFAULT_FONT
|
||||||
|
#define NK_IMPLEMENTATION
|
||||||
|
#define NK_GLFW_GL3_IMPLEMENTATION
|
||||||
|
#include <nuklear.h>
|
||||||
|
#include <demo/glfw_opengl3/nuklear_glfw_gl3.h>
|
||||||
|
|
||||||
|
struct gui gui =
|
||||||
|
{
|
||||||
|
.file_name = {0},
|
||||||
|
.projection = (struct projection){ .mesh=NULL, .x =0, .y=1, .z=2 },
|
||||||
|
};
|
||||||
|
|
||||||
|
float surface_color[4] = {(float)0x2F/0xFF, (float)0x3C/0xFF, (float)0x7E/0xFF, (float)0xff/0xFF};
|
||||||
|
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void restore_surface_color( void )
|
||||||
|
{
|
||||||
|
gui.picked_color[0] = surface_color[0];
|
||||||
|
gui.picked_color[1] = surface_color[1];
|
||||||
|
gui.picked_color[2] = surface_color[2];
|
||||||
|
gui.picked_color[3] = surface_color[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
struct nk_glfw glfw ={0};
|
||||||
|
struct nk_context * context;
|
||||||
|
|
||||||
|
void draw_gui( void )
|
||||||
|
{
|
||||||
|
nk_glfw3_new_frame(&glfw);
|
||||||
|
|
||||||
|
if (nk_begin(context, "MANIGRAPH", nk_rect(10, 10, 256, 256),
|
||||||
|
NK_WINDOW_BORDER |NK_WINDOW_SCALABLE | NK_WINDOW_MOVABLE | NK_WINDOW_MINIMIZABLE) )
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Color picker para personalización */
|
||||||
|
{
|
||||||
|
struct nk_colorf * p = (void*)&gui.picked_color;
|
||||||
|
nk_layout_row_dynamic(context, 120, 1);
|
||||||
|
*p = nk_color_picker(context, *p, NK_RGBA);
|
||||||
|
}
|
||||||
|
|
||||||
|
nk_layout_row_dynamic(context, 20, 1);
|
||||||
|
if (nk_button_label(context, "Restablecer"))
|
||||||
|
restore_surface_color();
|
||||||
|
|
||||||
|
|
||||||
|
nk_layout_row_dynamic(context, 12, 1);
|
||||||
|
nk_label(context, (char*)gui.file_name, NK_TEXT_ALIGN_LEFT);
|
||||||
|
|
||||||
|
nk_label_colored(context, "Atajos de teclado:", NK_TEXT_ALIGN_LEFT, nk_rgb(255, 255, 255)); // Encabezado
|
||||||
|
nk_label(context, " - W/S: Rotar eje X", NK_TEXT_ALIGN_LEFT);
|
||||||
|
nk_label(context, " - A/D: Rotar eje Y", NK_TEXT_ALIGN_LEFT);
|
||||||
|
nk_label(context, " - Z/X: Rotar eje Z", NK_TEXT_ALIGN_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
nk_end(context);
|
||||||
|
nk_glfw3_render(&glfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_gui( window_t window )
|
||||||
|
{
|
||||||
|
struct nk_font_atlas * atlas;
|
||||||
|
|
||||||
|
restore_surface_color();
|
||||||
|
|
||||||
|
{
|
||||||
|
context = nk_glfw3_init(&glfw,(GLFWwindow*) window, NK_GLFW3_DEFAULT );
|
||||||
|
nk_glfw3_font_stash_begin(&glfw, &atlas);
|
||||||
|
nk_glfw3_font_stash_end(&glfw);
|
||||||
|
}
|
||||||
|
}
|
||||||
153
src/input.c
153
src/input.c
@@ -1,23 +1,90 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <cglm/quat.h>
|
#include <glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cglm/quat.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define ANGLE ((float)0x01/0xff*2*GLM_PI)
|
#define ANGLE ((float)0x01 / 0xff * 2 * GLM_PI)
|
||||||
|
|
||||||
unsigned char selected_axis = 0;
|
unsigned char selected_axis = 0;
|
||||||
int window_width;
|
int window_width = 512;
|
||||||
int window_height;
|
int window_height = 512;
|
||||||
|
|
||||||
|
unsigned char animate_index = 0;
|
||||||
|
extern struct gui gui;
|
||||||
|
|
||||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
vec3 axis[3] =
|
vec3 axis[3] = {
|
||||||
{
|
|
||||||
{1, 0, 0},
|
{1, 0, 0},
|
||||||
{0, 1, 0},
|
{0, 1, 0},
|
||||||
{0, 0, 1},
|
{0, 0, 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
void __window_callback(GLFWwindow * window, int w, int h)
|
|
||||||
|
void __error_callback_input(int x, const char * msg )
|
||||||
|
{
|
||||||
|
mlog("[GLFW] ");
|
||||||
|
mlog(msg);
|
||||||
|
mlog("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __key_callback_input(
|
||||||
|
GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
if (action != GLFW_PRESS)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (GLFW_KEY_0 < key && key <= GLFW_KEY_9)
|
||||||
|
{
|
||||||
|
unsigned char selected_coord;
|
||||||
|
|
||||||
|
selected_coord = key - GLFW_KEY_0 - 1;
|
||||||
|
|
||||||
|
if (selected_coord >= gui.projection.m)
|
||||||
|
return;
|
||||||
|
if (selected_coord == gui.projection.x)
|
||||||
|
return;
|
||||||
|
if (selected_coord == gui.projection.y)
|
||||||
|
return;
|
||||||
|
if (selected_coord == gui.projection.z)
|
||||||
|
return;
|
||||||
|
|
||||||
|
selected_coord = gui.projection.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gui.projection.w >= gui.projection.m)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
unsigned char tmp;
|
||||||
|
case GLFW_KEY_I:
|
||||||
|
tmp = gui.projection.w;
|
||||||
|
gui.projection.w = gui.projection.x;
|
||||||
|
gui.projection.x = tmp;
|
||||||
|
|
||||||
|
animate_index = 1;
|
||||||
|
break;
|
||||||
|
case GLFW_KEY_O:
|
||||||
|
tmp = gui.projection.w;
|
||||||
|
gui.projection.w = gui.projection.y;
|
||||||
|
gui.projection.y = tmp;
|
||||||
|
animate_index = 2;
|
||||||
|
break;
|
||||||
|
case GLFW_KEY_P:
|
||||||
|
tmp = gui.projection.w;
|
||||||
|
gui.projection.w = gui.projection.z;
|
||||||
|
gui.projection.z = tmp;
|
||||||
|
animate_index = 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __window_callback_input(GLFWwindow *window, int w, int h)
|
||||||
{
|
{
|
||||||
int m;
|
int m;
|
||||||
|
|
||||||
@@ -28,80 +95,108 @@ void __window_callback(GLFWwindow * window, int w, int h)
|
|||||||
glViewport((w - m) / 2, (h - m) / 2, m, m);
|
glViewport((w - m) / 2, (h - m) / 2, m, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __mouse_callback(GLFWwindow* window, int button, int action, int mods)
|
void __mouse_callback_input(
|
||||||
|
GLFWwindow *window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
unsigned char green_value;
|
unsigned char green_value;
|
||||||
double xpos, ypos;
|
double xpos, ypos;
|
||||||
|
|
||||||
if( button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS )
|
if (button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glfwGetCursorPos(window, &xpos, &ypos);
|
glfwGetCursorPos(window, &xpos, &ypos);
|
||||||
glReadPixels((int)xpos, (int)(window_height - ypos), 1, 1, GL_GREEN, GL_UNSIGNED_BYTE, &green_value);
|
glReadPixels((int)xpos, (int)(window_height - ypos), 1, 1, GL_GREEN,
|
||||||
|
GL_UNSIGNED_BYTE, &green_value);
|
||||||
|
|
||||||
|
switch (green_value)
|
||||||
switch(green_value)
|
|
||||||
{
|
{
|
||||||
case 0xD3:
|
case 0xD3:
|
||||||
case 0xD4:
|
case 0xD4:
|
||||||
case 0xD5:
|
case 0xD5:
|
||||||
selected_axis = green_value-0xD3;
|
selected_axis = green_value - 0xD3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void __scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
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, 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(p, q, q);
|
||||||
|
glm_quat_mul(r, q, q);
|
||||||
|
|
||||||
glm_quat_rotatev(p, axis[0], axis[0]);
|
glm_quat_rotatev(p, axis[0], axis[0]);
|
||||||
glm_quat_rotatev(p, axis[1], axis[1]);
|
glm_quat_rotatev(p, axis[1], axis[1]);
|
||||||
glm_quat_rotatev(p, axis[2], axis[2]);
|
glm_quat_rotatev(p, axis[2], axis[2]);
|
||||||
|
|
||||||
|
glm_quat_rotatev(r, axis[0], axis[0]);
|
||||||
|
glm_quat_rotatev(r, axis[1], axis[1]);
|
||||||
|
glm_quat_rotatev(r, axis[2], axis[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __drop_callback_input(GLFWwindow *window, int count, unsigned char **path)
|
||||||
|
{
|
||||||
|
struct surface surface;
|
||||||
|
|
||||||
|
if (create_surface_klein(*path, &surface))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!(gui.projection.mesh = create_mesh(surface)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
strcpy(gui.file_name, *path);
|
||||||
|
|
||||||
|
gui.projection.m = surface.dim;
|
||||||
|
set_projection_mesh(gui.projection);
|
||||||
|
|
||||||
|
free(surface.norm);
|
||||||
|
free(surface.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
quat_t poll_input(window_t window)
|
quat_t poll_input(window_t window)
|
||||||
{
|
{
|
||||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
if( glfwGetKey((GLFWwindow*)window, 'Q') == GLFW_PRESS )
|
if (glfwGetKey((GLFWwindow *)window, 'Q') == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glm_quatv(p, ANGLE, axis[0]);
|
glm_quatv(p, ANGLE, axis[0]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if( glfwGetKey((GLFWwindow*)window, 'W') == GLFW_PRESS )
|
if (glfwGetKey((GLFWwindow *)window, 'W') == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glm_quatv(p, -ANGLE, axis[0]);
|
glm_quatv(p, -ANGLE, axis[0]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if( glfwGetKey((GLFWwindow*)window, 'A') == GLFW_PRESS )
|
if (glfwGetKey((GLFWwindow *)window, 'A') == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glm_quatv(p, ANGLE, axis[1]);
|
glm_quatv(p, ANGLE, axis[1]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if( glfwGetKey((GLFWwindow*)window, 'S') == GLFW_PRESS )
|
if (glfwGetKey((GLFWwindow *)window, 'S') == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glm_quatv(p, -ANGLE, axis[1]);
|
glm_quatv(p, -ANGLE, axis[1]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if( glfwGetKey((GLFWwindow*)window, 'Z') == GLFW_PRESS )
|
if (glfwGetKey((GLFWwindow *)window, 'Z') == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glm_quatv(p, ANGLE, axis[2]);
|
glm_quatv(p, ANGLE, axis[2]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if( glfwGetKey((GLFWwindow*)window, 'X') == GLFW_PRESS )
|
if (glfwGetKey((GLFWwindow *)window, 'X') == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glm_quatv(p, -ANGLE, axis[2]);
|
glm_quatv(p, -ANGLE, axis[2]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
glm_quat_mul( p, q, q );
|
glm_quat_mul(p, q, q);
|
||||||
glm_quat_rotatev( p, axis[0], axis[0] );
|
glm_quat_rotatev(p, axis[0], axis[0]);
|
||||||
glm_quat_rotatev( p, axis[1], axis[1] );
|
glm_quat_rotatev(p, axis[1], axis[1]);
|
||||||
glm_quat_rotatev( p, axis[2], axis[2] );
|
glm_quat_rotatev(p, axis[2], axis[2]);
|
||||||
glm_quat_normalize( q );
|
glm_quat_normalize(q);
|
||||||
|
|
||||||
return q;
|
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(4 * size);
|
||||||
|
fread(surface->data, 4, size, file);
|
||||||
|
|
||||||
|
surface->norm = malloc(4 * size);
|
||||||
|
fread(surface->norm, 4, size, file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
28
src/load.c
Normal file
28
src/load.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#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, float res[4])
|
||||||
|
{
|
||||||
|
load_float4_to_shader(shader, "color", res);
|
||||||
|
}
|
||||||
235
src/main.c
235
src/main.c
@@ -1,88 +1,179 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "data/cube.h"
|
|
||||||
#include "data/axis.h"
|
|
||||||
#include "data/shaders.h"
|
#include "data/shaders.h"
|
||||||
#include <GL/glew.h>
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define WIDTH 512
|
#define WIDTH 512
|
||||||
#define HEIGHT 512
|
#define HEIGHT 512
|
||||||
|
|
||||||
unsigned char palette[] =
|
#include <glad.h>
|
||||||
{
|
|
||||||
16,
|
|
||||||
0xEB,0xD3,0xF8,0xff,
|
|
||||||
0xEB,0xD4,0xF8,0xff,
|
|
||||||
0xEB,0xD5,0xF8,0xff,
|
|
||||||
0x7A,0x1C,0xAC,0xff,
|
|
||||||
};
|
|
||||||
|
|
||||||
const char * wname = "manigraph: manifold grapher";
|
float *generate_data_surface(unsigned int, unsigned char *);
|
||||||
|
float *generate_normals_surface(float *, unsigned char);
|
||||||
|
|
||||||
int main( void )
|
#ifdef EMSCRIPTEN
|
||||||
{
|
#include <emscripten.h>
|
||||||
id_t shader, texture;
|
|
||||||
mesh_t m_cube, m_axis;
|
|
||||||
window_t window;
|
|
||||||
|
|
||||||
if( !( window = init_window( WIDTH, HEIGHT, wname ) ) )
|
|
||||||
goto error_window;
|
|
||||||
|
|
||||||
use_window( window );
|
|
||||||
set_clean_color_context( 0x2E, 0x07, 0x3F );
|
|
||||||
|
|
||||||
glewInit();
|
|
||||||
|
|
||||||
if( !( shader = create_shader() ) )
|
|
||||||
goto error_shader;
|
|
||||||
|
|
||||||
gload_program( shader, vs, VERTEX );
|
|
||||||
gload_program( shader, fs, FRAGMENT );
|
|
||||||
use_shader( shader );
|
|
||||||
|
|
||||||
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
|
|
||||||
|
|
||||||
if( !( m_cube = create_mesh( d_cube ) ) )
|
|
||||||
goto error_mesh_cube;
|
|
||||||
|
|
||||||
if( !( m_axis = create_mesh( d_axis ) ) )
|
|
||||||
goto error_mesh_axis;
|
|
||||||
|
|
||||||
texture=create_palette_texture( palette );
|
|
||||||
use_texture( texture );
|
|
||||||
|
|
||||||
while( is_open_window( window ) )
|
|
||||||
{
|
|
||||||
quat_t q;
|
|
||||||
|
|
||||||
q=poll_input( window );
|
|
||||||
load_rot_matrix( shader, q );
|
|
||||||
|
|
||||||
clean_context();
|
|
||||||
#ifndef DEBUG
|
|
||||||
load_mdl_matrix( shader, 0, 0 );
|
|
||||||
draw_mesh( m_axis );
|
|
||||||
load_mdl_matrix( shader, 1, 1 );
|
|
||||||
draw_mesh( m_axis );
|
|
||||||
load_mdl_matrix( shader, 2, 2 );
|
|
||||||
draw_mesh( m_axis );
|
|
||||||
#endif
|
#endif
|
||||||
load_mdl_matrix( shader, 0, 3 );
|
|
||||||
draw_mesh( m_cube );
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159
|
||||||
|
#endif
|
||||||
|
|
||||||
|
window_t window;
|
||||||
|
id_t shader, shader_plain;
|
||||||
|
|
||||||
|
const char *wname = "manigraph: manifold grapher";
|
||||||
|
|
||||||
|
extern volatile unsigned char animate_index;
|
||||||
|
extern struct gui gui;
|
||||||
|
|
||||||
|
void mlog(char *msg)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf(msg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef EMSCRIPTEN
|
||||||
|
static inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
main_loop(void)
|
||||||
|
{
|
||||||
|
quat_t q;
|
||||||
|
|
||||||
|
q = poll_input(window);
|
||||||
|
|
||||||
|
gui.quat[0] = q[0];
|
||||||
|
gui.quat[1] = q[1];
|
||||||
|
gui.quat[2] = q[2];
|
||||||
|
gui.quat[3] = q[3];
|
||||||
|
|
||||||
|
|
||||||
|
rot_matrix_load(shader, q);
|
||||||
|
rot_matrix_load(shader_plain, q);
|
||||||
|
color_load(shader, gui.picked_color);
|
||||||
|
color_load(shader_plain, gui.picked_color);
|
||||||
|
|
||||||
|
{
|
||||||
|
static float angle = 0;
|
||||||
|
|
||||||
|
if (angle > M_PI / 2)
|
||||||
|
{
|
||||||
|
animate_index = 0;
|
||||||
|
angle = 0;
|
||||||
|
|
||||||
|
load_float_to_shader(shader, "angle", angle);
|
||||||
|
load_float_to_shader(shader_plain, "angle", angle);
|
||||||
|
set_projection_mesh(gui.projection);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animate_index)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clean_context();
|
||||||
|
|
||||||
|
|
||||||
|
if (gui.projection.mesh)
|
||||||
|
{
|
||||||
|
draw_mesh(shader, gui.projection.mesh);
|
||||||
|
draw_mesh_lines(shader_plain, gui.projection.mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy_texture( texture );
|
draw_gui();
|
||||||
destroy_mesh( m_axis );
|
|
||||||
destroy_mesh( m_cube );
|
}
|
||||||
destroy_shader( shader );
|
|
||||||
close_window( window );
|
int main(void)
|
||||||
|
{
|
||||||
|
mlog("[VENTANA] Inicializando...\n");
|
||||||
|
{
|
||||||
|
if (!(window = init_window(WIDTH, HEIGHT, wname)))
|
||||||
|
{
|
||||||
|
mlog("[VENTANA] Error al inicializar...\n");
|
||||||
|
goto error_window;
|
||||||
|
}
|
||||||
|
|
||||||
|
use_window(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlog("[CONTEXT] Inicializando...\n");
|
||||||
|
{
|
||||||
|
if (!(init_context()))
|
||||||
|
{
|
||||||
|
mlog("[CONTEXT] Error al inicializar...\n");
|
||||||
|
goto error_context;
|
||||||
|
}
|
||||||
|
set_clean_color_context(0xFF, 0xFF, 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlog("[SHADER] Inicializando...\n");
|
||||||
|
{
|
||||||
|
if (!(shader = create_shader()))
|
||||||
|
{
|
||||||
|
mlog("[SHADER] Error al inicializar...\n");
|
||||||
|
goto error_shader;
|
||||||
|
}
|
||||||
|
load_program_to_shader(shader, vs, VERTEX);
|
||||||
|
load_program_to_shader(shader, fs, FRAGMENT);
|
||||||
|
fix_matrix_load(shader, (float)WIDTH / HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlog("[SHADER] Inicializando...\n");
|
||||||
|
{
|
||||||
|
if (!(shader_plain = create_shader()))
|
||||||
|
{
|
||||||
|
mlog("[SHADER] Error al inicializar...\n");
|
||||||
|
goto error_shader_plain;
|
||||||
|
}
|
||||||
|
load_program_to_shader(shader_plain, vs, VERTEX);
|
||||||
|
load_program_to_shader(shader_plain, fs_plain, FRAGMENT);
|
||||||
|
fix_matrix_load(shader_plain, (float)WIDTH / HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlog("[GUI] Inicializando...\n");
|
||||||
|
{
|
||||||
|
init_gui(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlog("[MAIN LOOP] Inicializando...\n");
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
emscripten_set_main_loop(&main_loop, 60, 1);
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
while (is_open_window(window))
|
||||||
|
main_loop();
|
||||||
|
#endif
|
||||||
|
mlog("[MAIN LOOP] Terminando...\n");
|
||||||
|
|
||||||
|
mlog("[MESH] Destruyendo...\n");
|
||||||
|
destroy_mesh(gui.projection.mesh);
|
||||||
|
mlog("[SHADER] Destruyendo...\n");
|
||||||
|
destroy_shader(shader_plain);
|
||||||
|
mlog("[SHADER] Destruyendo...\n");
|
||||||
|
destroy_shader(shader);
|
||||||
|
mlog("[WINDOW] Destruyendo...\n");
|
||||||
|
close_window(window);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_mesh_axis:
|
error_context:
|
||||||
destroy_mesh( m_cube );
|
mlog("[SHADER] Destruyendo...\n");
|
||||||
error_mesh_cube:
|
destroy_shader(shader);
|
||||||
destroy_shader( shader );
|
|
||||||
error_shader:
|
error_shader:
|
||||||
close_window( window );
|
mlog("[SHADER] Destruyendo...\n");
|
||||||
|
destroy_shader(shader_plain);
|
||||||
|
error_shader_plain:
|
||||||
|
mlog("[WINDOW] Destruyendo...\n");
|
||||||
|
close_window(window);
|
||||||
error_window:
|
error_window:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
174
src/main.h
174
src/main.h
@@ -1,21 +1,67 @@
|
|||||||
#include <GL/glew.h>
|
/*
|
||||||
#include <GLFW/glfw3.h>
|
If DEBUG is set, we show the triangles of the mesh,
|
||||||
|
without illumination, and we write the compilation
|
||||||
|
error of the shaders.
|
||||||
|
*/
|
||||||
|
|
||||||
typedef const void * window_t;
|
#define DEBUG
|
||||||
|
#define GLFW_INCLUDE_NONE
|
||||||
|
|
||||||
|
typedef const void *window_t;
|
||||||
typedef unsigned int id_t;
|
typedef unsigned int id_t;
|
||||||
typedef void * mesh_t;
|
typedef void *mesh_t;
|
||||||
typedef float * quat_t;
|
typedef float *quat_t;
|
||||||
typedef float * mat4_t;
|
typedef float *mat4_t;
|
||||||
|
|
||||||
typedef float narray_float_t[];
|
/*
|
||||||
typedef unsigned char narray_u8_t[];
|
This struct represent the proyection, where:
|
||||||
|
mesh: data of surface.
|
||||||
|
m: the dimention of the surface.
|
||||||
|
x: the coordanate of the x axis.
|
||||||
|
y: the coordanate of the y axis.
|
||||||
|
z: the coordanate of the z axis.
|
||||||
|
w: the coordanate of the w axis.
|
||||||
|
*/
|
||||||
|
|
||||||
enum
|
struct gui
|
||||||
{
|
{
|
||||||
VERTEX, FRAGMENT
|
float quat[4];
|
||||||
|
float picked_color[4];
|
||||||
|
char file_name[0xff];
|
||||||
|
struct projection
|
||||||
|
{
|
||||||
|
mesh_t mesh;
|
||||||
|
unsigned char m, x, y, z, w;
|
||||||
|
} projection;
|
||||||
};
|
};
|
||||||
|
|
||||||
window_t init_window(unsigned int w, unsigned int h, const char * name);
|
|
||||||
|
/*
|
||||||
|
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;
|
||||||
|
h: default height;
|
||||||
|
name: Name of the window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);
|
void use_window(window_t window);
|
||||||
|
|
||||||
@@ -23,33 +69,109 @@ int is_open_window(window_t window);
|
|||||||
|
|
||||||
void close_window(window_t window);
|
void close_window(window_t window);
|
||||||
|
|
||||||
mesh_t create_mesh(narray_float_t mesh);
|
/*
|
||||||
|
Create mesh:
|
||||||
|
d: array of floats with the vertex data.
|
||||||
|
n: array of floats with the normal data.
|
||||||
|
m: Dimention of mesh
|
||||||
|
*/
|
||||||
|
|
||||||
|
mesh_t create_mesh(struct surface);
|
||||||
|
|
||||||
|
void set_projection_mesh(struct projection);
|
||||||
|
|
||||||
void destroy_mesh(mesh_t p);
|
void destroy_mesh(mesh_t p);
|
||||||
|
|
||||||
void draw_mesh(mesh_t p);
|
void draw_mesh(id_t, mesh_t p);
|
||||||
|
|
||||||
void set_clean_color_context(unsigned char, unsigned char, unsigned char);
|
void draw_mesh_lines(id_t, mesh_t p);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set background color:
|
||||||
|
r: red value in hex.
|
||||||
|
g: green value in hex.
|
||||||
|
b: blue value in hex.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void set_clean_color_context(unsigned char r, unsigned char g, unsigned char b);
|
||||||
|
|
||||||
void clean_context(void);
|
void clean_context(void);
|
||||||
|
|
||||||
|
int init_context(void);
|
||||||
|
|
||||||
void destroy_shader(id_t shader);
|
void destroy_shader(id_t shader);
|
||||||
|
|
||||||
id_t create_shader(void);
|
id_t create_shader(void);
|
||||||
|
|
||||||
void use_shader(id_t program);
|
void use_shader(id_t shader);
|
||||||
|
|
||||||
unsigned char gload_program(id_t program, const char * src, unsigned int type);
|
enum
|
||||||
|
{
|
||||||
|
VERTEX,
|
||||||
|
FRAGMENT
|
||||||
|
};
|
||||||
|
|
||||||
void gload_float(id_t program, char * var, float f);
|
/*
|
||||||
|
Load program to shader:
|
||||||
|
src: GLSL source code as string.
|
||||||
|
type: VERTEX or FRAGMENT
|
||||||
|
*/
|
||||||
|
|
||||||
void gload_mat4(id_t program, char * var, mat4_t m);
|
unsigned char load_program_to_shader(
|
||||||
|
id_t shader, const char *src, unsigned int type);
|
||||||
|
|
||||||
void load_fix_matrix(id_t shader, float ratio);
|
/*
|
||||||
|
load float to shader:
|
||||||
|
var: name of glsl variable.
|
||||||
|
f: float to load
|
||||||
|
*/
|
||||||
|
|
||||||
void load_mdl_matrix(id_t shader, unsigned char i, unsigned char c);
|
void load_float_to_shader(id_t shader, char *var, float f);
|
||||||
|
|
||||||
void load_rot_matrix(id_t shader, quat_t q);
|
/*
|
||||||
|
load unsigned int to shader:
|
||||||
|
var: name of glsl variable.
|
||||||
|
u: unsigned int to load
|
||||||
|
*/
|
||||||
|
|
||||||
|
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:
|
||||||
|
var: name of glsl variable.
|
||||||
|
m: Matrix to load
|
||||||
|
*/
|
||||||
|
|
||||||
|
void load_mat4_to_shader(id_t shader, char *var, mat4_t m);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generate and load fix matrix, this matrix
|
||||||
|
has the information of the perspective and
|
||||||
|
camera information.
|
||||||
|
|
||||||
|
ratio: default ratio of window.
|
||||||
|
*/
|
||||||
|
void fix_matrix_load(id_t shader, float ratio);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generate and load rotation matrix.
|
||||||
|
q: quaterinon describing the rotation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void rot_matrix_load(id_t shader, quat_t q);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void color_load(id_t shader, float* color);
|
||||||
|
|
||||||
id_t config_texture(unsigned short type);
|
id_t config_texture(unsigned short type);
|
||||||
|
|
||||||
@@ -57,6 +179,14 @@ void use_texture(id_t texture);
|
|||||||
|
|
||||||
void destroy_texture(id_t texture);
|
void destroy_texture(id_t texture);
|
||||||
|
|
||||||
id_t create_palette_texture(const narray_u8_t colors);
|
/*
|
||||||
|
Set color palette as 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);
|
||||||
|
|
||||||
quat_t poll_input(window_t window);
|
quat_t poll_input(window_t window);
|
||||||
|
|
||||||
|
void draw_gui( void );
|
||||||
|
void init_gui( window_t window );
|
||||||
|
|||||||
51
src/matrix.c
51
src/matrix.c
@@ -1,51 +0,0 @@
|
|||||||
#include "main.h"
|
|
||||||
#include <cglm/mat4.h>
|
|
||||||
#include <cglm/cam.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/4, ratio, d-3, d+3, n );
|
|
||||||
glm_mat4_mul( n, m, m );
|
|
||||||
|
|
||||||
gload_mat4( shader, "fix", (mat4_t) m );
|
|
||||||
}
|
|
||||||
|
|
||||||
void load_mdl_matrix( id_t shader, unsigned char i, unsigned char c )
|
|
||||||
{
|
|
||||||
gload_float( shader, "idx", c );
|
|
||||||
gload_mat4( shader, "mdl", (mat4_t)ortho[i] );
|
|
||||||
}
|
|
||||||
|
|
||||||
void load_rot_matrix( id_t shader, quat_t q )
|
|
||||||
{
|
|
||||||
mat4 m;
|
|
||||||
glm_quat_mat4( q, m );
|
|
||||||
gload_mat4( shader, "rot", (mat4_t)m );
|
|
||||||
}
|
|
||||||
123
src/mesh.c
Executable file → Normal file
123
src/mesh.c
Executable file → Normal file
@@ -1,55 +1,118 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <GL/glew.h>
|
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#else
|
||||||
|
#include <glad.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct obj
|
struct obj
|
||||||
{
|
{
|
||||||
unsigned int vertex, vao, vbo;
|
unsigned int vertex, vao, n_vbo, d_vbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
mesh_t create_mesh( narray_float_t mesh )
|
void set_projection_mesh(struct projection projection)
|
||||||
{
|
{
|
||||||
struct obj * p;
|
struct obj *p;
|
||||||
|
p = projection.mesh;
|
||||||
|
|
||||||
p=malloc(sizeof(struct obj));
|
glBindVertexArray(p->vao);
|
||||||
|
|
||||||
p->vertex=(*mesh)/3;
|
glBindBuffer(GL_ARRAY_BUFFER, p->d_vbo);
|
||||||
|
glVertexAttribPointer(0, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.x * sizeof(float)));
|
||||||
|
glVertexAttribPointer(1, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.y * sizeof(float)));
|
||||||
|
glVertexAttribPointer(2, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.z * sizeof(float)));
|
||||||
|
glVertexAttribPointer(3, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.w * sizeof(float)));
|
||||||
|
|
||||||
glGenVertexArrays( 1, &p->vao );
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p->n_vbo);
|
||||||
glGenBuffers( 1, &p->vbo );
|
glVertexAttribPointer(4, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.x * sizeof(float)));
|
||||||
|
glVertexAttribPointer(5, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.y * sizeof(float)));
|
||||||
|
glVertexAttribPointer(6, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.z * sizeof(float)));
|
||||||
|
glVertexAttribPointer(7, 1, GL_FLOAT, 0, projection.m * sizeof(float),
|
||||||
|
(float *)(projection.w * sizeof(float)));
|
||||||
|
}
|
||||||
|
|
||||||
glBindVertexArray( p->vao );
|
/*
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, p->vbo );
|
In this function we load all the vertex and ELEMENT_ARRAY datas on two
|
||||||
glBufferData( GL_ARRAY_BUFFER, (p->vertex*3)*sizeof(int), mesh+1,
|
diferents buffers, so we can access the coordanates that we want
|
||||||
GL_STATIC_DRAW );
|
to display using the layout location in GLSL.
|
||||||
|
This trick can be done with glVertexAttribPointer.
|
||||||
|
*/
|
||||||
|
|
||||||
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(int), NULL );
|
mesh_t create_mesh(struct surface surface)
|
||||||
glEnableVertexAttribArray(0);
|
{
|
||||||
|
unsigned char i;
|
||||||
|
struct obj *p;
|
||||||
|
|
||||||
|
p = malloc(sizeof(struct obj));
|
||||||
|
|
||||||
|
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 * surface.dim * sizeof(float),
|
||||||
|
surface.data, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
if (surface.norm)
|
||||||
|
{
|
||||||
|
glGenBuffers(1, &p->n_vbo);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p->n_vbo);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
|
||||||
|
p->vertex * surface.dim * sizeof(float), surface.norm,
|
||||||
|
GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 8; ++i)
|
||||||
|
glEnableVertexAttribArray(i);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_mesh( mesh_t p )
|
void destroy_mesh(mesh_t p)
|
||||||
{
|
{
|
||||||
struct obj * obj ;
|
struct obj *obj;
|
||||||
obj = p;
|
obj = p;
|
||||||
glDeleteVertexArrays( 1, &obj->vao );
|
glDeleteVertexArrays(1, &obj->vao);
|
||||||
glDeleteBuffers( 1, &obj->vbo );
|
glDeleteBuffers(1, &obj->d_vbo);
|
||||||
free( p );
|
glDeleteBuffers(1, &obj->n_vbo);
|
||||||
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_mesh( mesh_t p )
|
void draw_mesh(id_t shader, mesh_t p)
|
||||||
{
|
{
|
||||||
struct obj * obj=p;
|
struct obj *obj = p;
|
||||||
|
|
||||||
glBindVertexArray( obj->vao );
|
glUseProgram(shader);
|
||||||
#ifdef DEBUG
|
glBindVertexArray(obj->vao);
|
||||||
{
|
#ifndef EMSCRIPTEN
|
||||||
int i;
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
for( i=0; i<obj->vertex;i+=3 )
|
#endif
|
||||||
glDrawArrays(GL_LINE_LOOP, i, 3 );
|
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);
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
#else
|
#else
|
||||||
glDrawArrays(GL_TRIANGLES, 0, obj->vertex );
|
glDrawArrays(GL_LINES, 0, obj->vertex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
65
src/shader.c
65
src/shader.c
@@ -1,51 +1,43 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <GL/glew.h>
|
|
||||||
|
#ifndef EMSCRIPTEN
|
||||||
|
#include <glad.h>
|
||||||
|
#else
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void destroy_shader( unsigned int shader )
|
void destroy_shader(unsigned int shader) { glDeleteProgram(shader); }
|
||||||
{
|
|
||||||
return glDeleteProgram( shader );
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int create_shader( void )
|
unsigned int create_shader(void) { return glCreateProgram(); }
|
||||||
{
|
|
||||||
return glCreateProgram();
|
|
||||||
}
|
|
||||||
|
|
||||||
void use_shader( unsigned int program )
|
void use_shader(unsigned int program) { glUseProgram(program); }
|
||||||
{
|
|
||||||
return glUseProgram( program );
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char gload_program( unsigned int program, const char * src,
|
unsigned char load_program_to_shader(
|
||||||
unsigned int i )
|
unsigned int program, const char *src, unsigned int i)
|
||||||
{
|
{
|
||||||
int shader, status;
|
int shader, status;
|
||||||
unsigned int type[] =
|
unsigned int type[] = {
|
||||||
{
|
[VERTEX] = GL_VERTEX_SHADER, [FRAGMENT] = GL_FRAGMENT_SHADER};
|
||||||
[VERTEX]=GL_VERTEX_SHADER,
|
|
||||||
[FRAGMENT]=GL_FRAGMENT_SHADER
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if (!src)
|
||||||
if( !src )
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
shader = glCreateShader(type[i]);
|
shader = glCreateShader(type[i]);
|
||||||
glShaderSource( shader, 1, (const GLchar **)&src, ((void*)0 ));
|
glShaderSource(shader, 1, (const GLchar **)&src, ((void *)0));
|
||||||
glCompileShader(shader);
|
glCompileShader(shader);
|
||||||
glGetShaderiv( shader, GL_COMPILE_STATUS, &status );
|
|
||||||
|
|
||||||
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
||||||
|
|
||||||
if( !status )
|
if (!status)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
char log[256];
|
char log[256];
|
||||||
glGetShaderInfoLog( shader, 256, NULL, log );
|
glGetShaderInfoLog(shader, 256, NULL, log);
|
||||||
printf( "%s", log );
|
printf("%s", log);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -56,14 +48,21 @@ unsigned char gload_program( unsigned int program, const char * src,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gload_float( unsigned int program, char * var, float f )
|
void load_float_to_shader(unsigned int program, char *var, float f)
|
||||||
{
|
{
|
||||||
glUseProgram( program );
|
glUseProgram(program);
|
||||||
glUniform1f( glGetUniformLocation( program, var ), f );
|
glUniform1f(glGetUniformLocation(program, var), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gload_mat4( unsigned int program, char * var, float * mat )
|
void load_mat4_to_shader(unsigned int program, char *var, float *mat)
|
||||||
{
|
{
|
||||||
glUseProgram( program );
|
glUseProgram(program);
|
||||||
glUniformMatrix4fv( glGetUniformLocation( program, var ), 1, 0, mat );
|
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]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
#include "main.h"
|
|
||||||
#include <GL/glew.h>
|
|
||||||
|
|
||||||
#define TYPE GL_TEXTURE_2D_ARRAY
|
|
||||||
|
|
||||||
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 )
|
|
||||||
{
|
|
||||||
id_t texture = config_texture( TYPE );
|
|
||||||
glTexImage3D( TYPE, 0, GL_RGBA,
|
|
||||||
1, 1, (*colors)/4, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors+1);
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
85
src/window.c
85
src/window.c
@@ -1,55 +1,96 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
void __window_callback(GLFWwindow *, int, int);
|
void __window_callback_input(GLFWwindow *, int, int);
|
||||||
void __mouse_callback(GLFWwindow *, int, int, int);
|
void __mouse_callback_input(GLFWwindow *, int, int, int);
|
||||||
void __scroll_callback(GLFWwindow *, double, double);
|
void __scroll_callback_input(GLFWwindow *, double, double);
|
||||||
|
void __key_callback_input(GLFWwindow *, int, int, int, int);
|
||||||
|
void __drop_callback_input(GLFWwindow *, int, const char **);
|
||||||
|
void __error_callback_input(int, const char *);
|
||||||
|
|
||||||
window_t init_window(unsigned int w, unsigned int h, const char * name)
|
window_t init_window(unsigned int w, unsigned int h, const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Limitamos los FPS, contando el tiempo en el que
|
||||||
|
se ejecuta el main loop, y esperando el tiempo restante
|
||||||
|
para lograr los fps deseados.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void __limit_fps_window(int max_fps)
|
||||||
{
|
{
|
||||||
void * window;
|
static double previous_time = 0.0;
|
||||||
void __mouse_callback(GLFWwindow *window, int button, int action, int mods);
|
double current_time;
|
||||||
void __scroll_callback(GLFWwindow *window, double xoffset, double yoffset);
|
double frame_time;
|
||||||
|
double elapsed_time;
|
||||||
|
|
||||||
if( !glfwInit() )
|
current_time = glfwGetTime();
|
||||||
|
frame_time = 1.0 / max_fps;
|
||||||
|
elapsed_time = current_time - previous_time;
|
||||||
|
|
||||||
|
if (elapsed_time < frame_time)
|
||||||
|
{
|
||||||
|
struct timespec sleep_time;
|
||||||
|
sleep_time.tv_sec = 0;
|
||||||
|
sleep_time.tv_nsec = (long)((frame_time - elapsed_time) * 1e9);
|
||||||
|
nanosleep(&sleep_time, NULL);
|
||||||
|
|
||||||
|
current_time = glfwGetTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
previous_time = current_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
window_t init_window(unsigned int width, unsigned int height, const char *title)
|
||||||
|
{
|
||||||
|
window_t window;
|
||||||
|
glfwSetErrorCallback(__error_callback_input);
|
||||||
|
|
||||||
|
if (!glfwInit())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
|
||||||
|
|
||||||
window = glfwCreateWindow(w, h, name, NULL, NULL);
|
window = (window_t)glfwCreateWindow(width, height, title, NULL, NULL);
|
||||||
|
if (!(window))
|
||||||
if( !window )
|
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window, __window_callback);
|
glfwMakeContextCurrent((GLFWwindow *)(window));
|
||||||
glfwSetMouseButtonCallback((GLFWwindow*)window, __mouse_callback);
|
|
||||||
glfwSetScrollCallback((GLFWwindow*)window, __scroll_callback);
|
|
||||||
|
|
||||||
__window_callback( window, w, h );
|
glfwSetWindowSizeCallback((GLFWwindow *)window, __window_callback_input);
|
||||||
|
glfwSetMouseButtonCallback((GLFWwindow *)window, __mouse_callback_input);
|
||||||
|
glfwSetScrollCallback((GLFWwindow *)window, __scroll_callback_input);
|
||||||
|
glfwSetKeyCallback((GLFWwindow *)window, __key_callback_input);
|
||||||
|
glfwSetDropCallback((GLFWwindow *)window, __drop_callback_input);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void use_window(window_t window)
|
void use_window(window_t window) { glfwMakeContextCurrent((void *)window); }
|
||||||
{
|
|
||||||
glfwMakeContextCurrent((void*)window);
|
extern int window_width, window_height;
|
||||||
}
|
|
||||||
|
|
||||||
int is_open_window(window_t window)
|
int is_open_window(window_t window)
|
||||||
{
|
{
|
||||||
glfwSwapBuffers((void*)window);
|
/* Restore window proportions if Nuklear breaks it */
|
||||||
|
__window_callback_input((GLFWwindow *)window, window_width, window_height);
|
||||||
|
|
||||||
|
glfwSwapBuffers((void *)window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
return !glfwWindowShouldClose((void*)window);
|
__limit_fps_window(60);
|
||||||
|
return !glfwWindowShouldClose((void *)window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_window(window_t window)
|
void close_window(window_t window)
|
||||||
{
|
{
|
||||||
glfwDestroyWindow((void*)window);
|
glfwDestroyWindow((GLFWwindow *)window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user