Merge: doc -> main
This commit is contained in:
58
Makefile
58
Makefile
@@ -1,42 +1,64 @@
|
||||
LIBGLFW=./libglfw.so
|
||||
BIN = manigraph
|
||||
|
||||
BIN = ./manigraph
|
||||
OBJ = \
|
||||
src/context.o \
|
||||
src/texture.o \
|
||||
src/window.o \
|
||||
src/matrix.o \
|
||||
src/shader.o \
|
||||
src/input.o \
|
||||
src/color.o \
|
||||
src/mesh.o \
|
||||
src/main.o
|
||||
|
||||
LIB = \
|
||||
$(LIBGLFW)
|
||||
|
||||
CFLAGS = \
|
||||
-I./ext/cglm/include \
|
||||
-I./ext/glfw/include \
|
||||
-Wall -Wno-unused-function -std=c89
|
||||
-Wall -Wno-unused-function -std=c99 \
|
||||
-D_XOPEN_SOURCE
|
||||
|
||||
all: $(BIN) $(LIB)
|
||||
help:
|
||||
@echo "Para compilar el proyecto a tu sistema operativo"
|
||||
@echo "porfavor usa uno de los siguientes comandos:"
|
||||
@echo " $(MAKE) windows"
|
||||
@echo " $(MAKE) linux-x11"
|
||||
@echo " $(MAKE) linux-wayland"
|
||||
@echo " $(MAKE) cocoa"
|
||||
@echo "Para limpiar los archivos compilados se puede usar"
|
||||
@echo " $(MAKE) clean"
|
||||
@echo "Para ejecturar el programa sin instalarlos se puede usar:"
|
||||
@echo " $(MAKE) run-linux"
|
||||
|
||||
$(BIN): $(OBJ) $(LIB)
|
||||
$(CC) -lGL -lglfw -L. -o $(BIN) $(OBJ)
|
||||
# WINDOWS
|
||||
windows: $(OBJ) glfw.dll
|
||||
$(CC) -L. -lGL -lglfw -o $(BIN).exe $(OBJ)
|
||||
|
||||
$(LIBGLFW):
|
||||
$(CC) -fPIC -shared -D_GLFW_X11 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@
|
||||
glfw.dll:
|
||||
$(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@
|
||||
|
||||
run:
|
||||
LD_LIBRARY_PATH=. $(BIN)
|
||||
# LINUX
|
||||
linux-x11: $(OBJ)
|
||||
$(MAKE) BKN=_GLFW_X11 libglfw.so
|
||||
$(CC) -L. -lGL -lglfw -o $(BIN) $(OBJ)
|
||||
|
||||
linux-wayland: $(OBJ)
|
||||
$(MAKE) BKN=_GLFW_WAYLAND libglfw.so
|
||||
$(CC) -L. -lGL -lglfw -o $(BIN) $(OBJ)
|
||||
|
||||
run-linux:
|
||||
LD_LIBRARY_PATH=. ./$(BIN)
|
||||
|
||||
# COCOA
|
||||
cocoa: $(OBJ)
|
||||
$(MAKE) BKN=_GLFW_COCOA libglfw.so
|
||||
$(CC) -framework OpenGL -L. lglfw -o $(BIN) $(OBJ)
|
||||
|
||||
libglfw.so:
|
||||
$(CC) -fPIC -shared -D$(BKN) -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@
|
||||
|
||||
clean:
|
||||
rm $(OBJ) $(BIN)
|
||||
|
||||
clean-all:
|
||||
rm $(OBJ) $(DOC) $(LIB) $(BIN)
|
||||
|
||||
.SUFFIXES: .c .o
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $< -c -o $@
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
106
README.md
Normal file
106
README.md
Normal file
@@ -0,0 +1,106 @@
|
||||
# Manigraph: Graficadora de variedades
|
||||
Diaz Camacho Pedro Emilio
|
||||
|
||||
# Resumen
|
||||
manigraph es un graficador interactiva de variedades que lee archivos binarios, con la información de
|
||||
una variedad multidimensional y grafica esta variedad en una proyección tridimensional.
|
||||
|
||||
# Dependencias
|
||||
Para poder compilar el proyecto hace falta los siguientes pro.
|
||||
## 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)
|
||||
- `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
|
||||
|
||||
# Codigo fuente
|
||||
Para adquirir el código fuente de manigraph se puede usar git o descargar manualmente los
|
||||
archivos zip.
|
||||
|
||||
## git via https
|
||||
Usando git se necesitan ejecutar los siguientes comándos en la terminal.
|
||||
|
||||
```
|
||||
git clone https://gitea.adles.top/software/manigraph.git
|
||||
cd manigraph
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
## zip files
|
||||
Alternativamente se puede descargar el código fuente en formato zip usando las siguientes
|
||||
direcciones y acomodando manualmente las carpetas de `glfw` y `cglm` en `ext/`.
|
||||
|
||||
- [manigraph](https://gitea.adles.top/software/manigraph/archive/main.zip)
|
||||
- [glfw](https://github.com/glfw/glfw/archive/refs/heads/master.zip)
|
||||
- [cglm](https://github.com/recp/cglm/archive/refs/heads/master.zip)
|
||||
|
||||
|
||||
# Compilación
|
||||
Para compilar manualmente el proyecto se puede usar `make` o ejecutar los comandos manualmente
|
||||
en el código fuente de `manigraph`.
|
||||
|
||||
## Make
|
||||
Los siguientes comandos sirven para compilar `manigraph` deacuerdo al sistema operativo.
|
||||
|
||||
```
|
||||
make windows
|
||||
make linux-x11
|
||||
make linux-wayland
|
||||
make cocoa
|
||||
```
|
||||
|
||||
## Manualmente
|
||||
se pueden compilar el proyecto manualmente sin necesidad del programa `make`.
|
||||
|
||||
### GLFW
|
||||
Si tienes problemas compilando `GLFW` puedes checar su página web oficial
|
||||
explicando el tema: [Compiling GLFW](https://www.glfw.org/docs/3.3/compile.html).
|
||||
|
||||
#### Windows
|
||||
```
|
||||
cc -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o glfw.dll
|
||||
```
|
||||
|
||||
#### Linux
|
||||
```
|
||||
cc -fPIC -shared -D_GLFW_X11 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o libglfw.so
|
||||
cc -fPIC -shared -D_GLFW_WAYLAND -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o libglfw.so
|
||||
```
|
||||
|
||||
#### Mac
|
||||
```
|
||||
cc -fPIC -shared -D_GLFW_COCOA -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o libglfw.so
|
||||
```
|
||||
|
||||
### Manigraph
|
||||
#### Windows
|
||||
```
|
||||
cc -L. -lglfw -lGL -I ext/cglm/include/ -I ext/glfw/include/ src/*.c -o manigraph.exe
|
||||
```
|
||||
#### Linux
|
||||
```
|
||||
cc -L. -lglfw -lGL -I ext/cglm/include/ -I ext/glfw/include/ src/*.c -o manigraph
|
||||
```
|
||||
#### Mac
|
||||
```
|
||||
cc -L. -lglfw -framework GL -I ext/cglm/include/ -I ext/glfw/include/ src/*.c -o manigraph
|
||||
```
|
||||
|
||||
# Ejecutar
|
||||
En linux se puede ejecutar el programa sin instalar la llibreria de glfw usando:
|
||||
## make
|
||||
```
|
||||
make run-linux
|
||||
```
|
||||
## manual
|
||||
```
|
||||
LD_LIBRARY_PATH=. ./manigraph
|
||||
```
|
||||
@@ -3,48 +3,78 @@ Díaz Camacho Pedro Emilio
|
||||
|
||||
# Headers
|
||||
## main.h
|
||||
Este archivo incluye los prototipos internos que va a usar el programa
|
||||
Este archivo incluye los prototipos internos, que va a usar el programa
|
||||
funge como api interna para los desarrolladores y debe estar bien documentada.
|
||||
|
||||
# Datos
|
||||
## data/cube.h
|
||||
## data/axis.h
|
||||
## data/shaders.h
|
||||
|
||||
# codigo fuente
|
||||
|
||||
## main.c
|
||||
Este archivo inclye la función principal, debe inicializar, ejecutar, y terminar el programa correctamente,
|
||||
así como avisar de los errores cuando aparezcan.
|
||||
## color.c
|
||||
Incluye las funciones para escoger y pintar el color de fondo.
|
||||
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 el código necesario para interactuar con el program
|
||||
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
|
||||
Debe cargar en la gpu las matrices que use el programa.
|
||||
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
|
||||
Debe crear, destruir y dibujar los mesh, que son la representación de objetos tridimensionales.
|
||||
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, que son programas para la gpu, así como tener funciones
|
||||
para cargar estructuras a la gpu.
|
||||
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, destruir las texturas, también crea una textura para una paleta de colores.
|
||||
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, y cierra una ventana, también avisa cuando la ventana está abierta.
|
||||
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
|
||||
|
||||
43
doc/es/dev/tipos.md
Normal file
43
doc/es/dev/tipos.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# 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,33 +1,6 @@
|
||||
# Manual de Diseño
|
||||
Diaz Camacho Pedro Emilio
|
||||
|
||||
# Resumen
|
||||
manigraph es un graficador de variedades que lee archivos binarios con un forma
|
||||
to espacial, este viene con un manual explicando como correr el programa, como
|
||||
interactuar con el programa y las especificaciones del archivo binario.
|
||||
|
||||
# Tecnologias
|
||||
## Lenguajes:
|
||||
- C89
|
||||
## Librerias:
|
||||
- OpenGL
|
||||
- GLFW
|
||||
- cglm
|
||||
|
||||
# Archivos
|
||||
- Ejecutable.
|
||||
- Ejemplo.
|
||||
- Una libreria tipo STB, con las funciones para hacer variedades con una
|
||||
funcion parametrizadora.
|
||||
- LA PARAMETRIZACION DEBE SER CONTINUA.
|
||||
- El codigo fuente de un programa que cree la variedad de una botella
|
||||
de klein usando esta libreria.
|
||||
- Manual
|
||||
- Explicando como correr el programa desde la terminal.
|
||||
- Explicando como interactuar con el programa con el teclado y mouse.
|
||||
- Explicando el formato binario de las variedaedes.
|
||||
- Explicando la libreria STB.
|
||||
|
||||
# Objetivos
|
||||
## Prioridad alta
|
||||
- [ ] El programa debe actualizarse cuando interactuan con el.
|
||||
@@ -40,7 +13,7 @@ interactuar con el programa y las especificaciones del archivo binario.
|
||||
- [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 standar del programa.
|
||||
- [ ] Desde la entrada estandar del programa.
|
||||
|
||||
## Prioridad media
|
||||
|
||||
@@ -78,44 +51,9 @@ interactuar con el programa y las especificaciones del archivo binario.
|
||||
1. Usando el mouse.
|
||||
1. Usando el teclado.
|
||||
0. Detalles.
|
||||
0. Se anima el cambio de eje.
|
||||
0. Se hace el generador de GIF.
|
||||
0. Se puede cambiar el shader
|
||||
0. Documentacion
|
||||
|
||||
# Cronograma
|
||||
|
||||
| Persona | Ver | Objetivo| Fecha|
|
||||
|.........|....|..........|......|
|
||||
|Alan ||Familiarizarse con el codigo| 15-Sep-2024|
|
||||
||3.1| Sombreado |17-Nov-2024|
|
||||
|...|...|...|...|
|
||||
|Francisco||Familiarizarse con el codigo|15-Sep-2024|
|
||||
||0.4| Seleccionar ejes con el mouse|29-Sep-2024|
|
||||
||0.4|Rotar ejes con el scroll del mouse| 13-Oct-2024|
|
||||
|...|...|...|...|
|
||||
|Roberto||Familiarizarse con el codigo|15-Sep-2024|
|
||||
||1.2 Programa ejemplo mobius|13-Oct-2024|
|
||||
||1.3 Programa ejemplo klein|20-Oct-2024|
|
||||
1. Se anima el cambio de eje.
|
||||
1. Se hace el generador de GIF.
|
||||
1. Se puede cambiar el shader
|
||||
1. Documentacion
|
||||
|
||||
|
||||
## Problemas
|
||||
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.
|
||||
|
||||
|
||||
22
doc/es/tech/problemas.md
Normal file
22
doc/es/tech/problemas.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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.
|
||||
|
||||
19
doc/es/user.md
Normal file
19
doc/es/user.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# 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.
|
||||
@@ -2,13 +2,13 @@
|
||||
#include <GL/gl.h>
|
||||
#include "main.h"
|
||||
|
||||
void set_color( 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 );
|
||||
}
|
||||
|
||||
void draw_color( void )
|
||||
void clean_context( void )
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
@@ -8,8 +8,8 @@
|
||||
#undef H
|
||||
|
||||
const float X = 2.0;
|
||||
const float Y = 0.1;
|
||||
const float Z = 0.1;
|
||||
const float Y = 0.05;
|
||||
const float Z = 0.05;
|
||||
|
||||
#define A -X,-Y,-Z,
|
||||
#define B -X,-Y, Z,
|
||||
@@ -20,7 +20,7 @@ const float Z = 0.1;
|
||||
#define G X, Y,-Z,
|
||||
#define H X, Y, Z,
|
||||
|
||||
float d_axis[] =
|
||||
narray_float_t d_axis =
|
||||
{
|
||||
3*3*2*6,
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define G 1, 1,-1,
|
||||
#define H 1, 1, 1,
|
||||
|
||||
float d_cube[] =
|
||||
narray_float_t d_cube =
|
||||
{
|
||||
3*3*2*6,
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#define inline
|
||||
#include <cglm/quat.h>
|
||||
|
||||
#define ANGLE ((float)0x01/0xff*2*GLM_PI)
|
||||
#define ANGLE ((float)0x02/0xff*2*GLM_PI)
|
||||
|
||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||
vec3 axis[3] =
|
||||
@@ -13,7 +13,7 @@ vec3 axis[3] =
|
||||
{0,0,1},
|
||||
};
|
||||
|
||||
float * poll_input( window_t window )
|
||||
quat_t poll_input( window_t window )
|
||||
{
|
||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
|
||||
12
src/main.c
12
src/main.c
@@ -21,16 +21,15 @@ const char * wname = "manigraph: manifold grapher";
|
||||
|
||||
int main( void )
|
||||
{
|
||||
unsigned int shader, texture;
|
||||
void * m_cube, *m_axis;
|
||||
|
||||
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_color( 0x2E, 0x07, 0x3F );
|
||||
set_clean_color_context( 0x2E, 0x07, 0x3F );
|
||||
|
||||
if( !( shader = create_shader() ) )
|
||||
goto error_shader;
|
||||
@@ -52,11 +51,12 @@ int main( void )
|
||||
|
||||
while( is_open_window( window ) )
|
||||
{
|
||||
float * q;
|
||||
quat_t q;
|
||||
|
||||
q=poll_input( window );
|
||||
load_rot_matrix( shader, q );
|
||||
|
||||
draw_color();
|
||||
clean_context();
|
||||
|
||||
load_mdl_matrix( shader, 0, 0 );
|
||||
draw_mesh( m_axis );
|
||||
|
||||
45
src/main.h
45
src/main.h
@@ -1,4 +1,11 @@
|
||||
typedef const void * window_t;
|
||||
typedef unsigned int id_t;
|
||||
typedef void * mesh_t;
|
||||
typedef float * quat_t;
|
||||
typedef float * mat4_t;
|
||||
|
||||
typedef float narray_float_t[];
|
||||
typedef unsigned char narray_u8_t[];
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -13,40 +20,40 @@ int is_open_window( window_t window );
|
||||
|
||||
void close_window( window_t window );
|
||||
|
||||
void * create_mesh( float * mesh );
|
||||
mesh_t create_mesh( narray_float_t mesh );
|
||||
|
||||
void destroy_mesh( void * p );
|
||||
void destroy_mesh( mesh_t p );
|
||||
|
||||
void draw_mesh( void * p );
|
||||
void draw_mesh( mesh_t p );
|
||||
|
||||
void set_color( unsigned char, unsigned char, unsigned char );
|
||||
void set_clean_color_context( unsigned char, unsigned char, unsigned char );
|
||||
|
||||
void draw_color( void );
|
||||
void clean_context( void );
|
||||
|
||||
void destroy_shader( unsigned int shader );
|
||||
void destroy_shader( id_t shader );
|
||||
|
||||
unsigned int create_shader( void );
|
||||
id_t create_shader( void );
|
||||
|
||||
void use_shader( unsigned int program );
|
||||
void use_shader( id_t program );
|
||||
|
||||
unsigned char gload_program( unsigned int program, const char * src, unsigned int type );
|
||||
unsigned char gload_program( id_t program, const char * src, unsigned int type );
|
||||
|
||||
void gload_float( unsigned int program, char * var, float f );
|
||||
void gload_float( id_t program, char * var, float f );
|
||||
|
||||
void gload_mat4( unsigned int program, char * var, float * m );
|
||||
void gload_mat4( id_t program, char * var, mat4_t m );
|
||||
|
||||
void load_fix_matrix( unsigned int shader, float ratio );
|
||||
void load_fix_matrix( id_t shader, float ratio );
|
||||
|
||||
void load_mdl_matrix( unsigned int shader, unsigned char i, unsigned char c );
|
||||
void load_mdl_matrix( id_t shader, unsigned char i, unsigned char c );
|
||||
|
||||
void load_rot_matrix( unsigned int shader, float * q );
|
||||
void load_rot_matrix( id_t shader, quat_t q );
|
||||
|
||||
unsigned int config_texture( unsigned short type );
|
||||
id_t config_texture( unsigned short type );
|
||||
|
||||
void use_texture( unsigned int texture );
|
||||
void use_texture( id_t texture );
|
||||
|
||||
void destroy_texture( unsigned int texture );
|
||||
void destroy_texture( id_t texture );
|
||||
|
||||
unsigned int create_palette_texture( const unsigned char * colors );
|
||||
id_t create_palette_texture( const narray_u8_t colors );
|
||||
|
||||
float * poll_input( window_t window );
|
||||
quat_t poll_input( window_t window );
|
||||
|
||||
12
src/matrix.c
12
src/matrix.c
@@ -26,7 +26,7 @@ mat4 ortho[] =
|
||||
},
|
||||
};
|
||||
|
||||
void load_fix_matrix( unsigned int shader, float ratio )
|
||||
void load_fix_matrix( id_t shader, float ratio )
|
||||
{
|
||||
mat4 m, n;
|
||||
const int d = 7;
|
||||
@@ -35,18 +35,18 @@ void load_fix_matrix( unsigned int shader, float ratio )
|
||||
glm_perspective( CGLM_PI/4, ratio, d-3, d+3, n );
|
||||
glm_mat4_mul( n, m, m );
|
||||
|
||||
gload_mat4( shader, "fix", (float*)m );
|
||||
gload_mat4( shader, "fix", (mat4_t) m );
|
||||
}
|
||||
|
||||
void load_mdl_matrix( unsigned int shader, unsigned char i, unsigned char c )
|
||||
void load_mdl_matrix( id_t shader, unsigned char i, unsigned char c )
|
||||
{
|
||||
gload_float( shader, "idx", c );
|
||||
gload_mat4( shader, "mdl", (float*)ortho[i] );
|
||||
gload_mat4( shader, "mdl", (mat4_t)ortho[i] );
|
||||
}
|
||||
|
||||
void load_rot_matrix( unsigned int shader, float * q )
|
||||
void load_rot_matrix( id_t shader, quat_t q )
|
||||
{
|
||||
mat4 m;
|
||||
glm_quat_mat4( q, m );
|
||||
gload_mat4( shader, "rot", (float*)m );
|
||||
gload_mat4( shader, "rot", (mat4_t)m );
|
||||
}
|
||||
|
||||
17
src/mesh.c
17
src/mesh.c
@@ -1,13 +1,14 @@
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <stdlib.h>
|
||||
#include "main.h"
|
||||
|
||||
struct obj
|
||||
{
|
||||
unsigned int vertex, vao, vbo;
|
||||
};
|
||||
|
||||
void * create_mesh( float * mesh )
|
||||
mesh_t create_mesh( narray_float_t mesh )
|
||||
{
|
||||
struct obj * p;
|
||||
|
||||
@@ -29,7 +30,7 @@ void * create_mesh( float * mesh )
|
||||
return p;
|
||||
}
|
||||
|
||||
void destroy_mesh( void * p )
|
||||
void destroy_mesh( mesh_t p )
|
||||
{
|
||||
struct obj * obj ;
|
||||
obj = p;
|
||||
@@ -38,10 +39,18 @@ void destroy_mesh( void * p )
|
||||
free( p );
|
||||
}
|
||||
|
||||
void draw_mesh( void * p )
|
||||
void draw_mesh( mesh_t p )
|
||||
{
|
||||
struct obj * obj=p;
|
||||
|
||||
glBindVertexArray( obj->vao );
|
||||
glDrawArrays(GL_TRIANGLES, 0, obj->vertex );
|
||||
#ifdef DEBUG
|
||||
{
|
||||
int i;
|
||||
for( i=0; i<obj->vertex;i+=3 )
|
||||
glDrawArrays(GL_LINE_LOOP, i, 3 );
|
||||
}
|
||||
#else
|
||||
glDrawArrays(GL_TRIANGLES, 0, obj->vertex );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
#include <GL/gl.h>
|
||||
#include "main.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
void destroy_shader( unsigned int shader )
|
||||
@@ -44,7 +48,7 @@ unsigned char gload_program( unsigned int program, const char * src,
|
||||
#ifdef DEBUG
|
||||
char log[256];
|
||||
glGetShaderInfoLog( shader, 256, NULL, log );
|
||||
printf( log );
|
||||
printf( "%s", log );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#define TYPE GL_TEXTURE_2D_ARRAY
|
||||
|
||||
unsigned int config_texture( unsigned short type )
|
||||
id_t config_texture( unsigned short type )
|
||||
{
|
||||
unsigned int texture;
|
||||
id_t texture;
|
||||
|
||||
glGenTextures( 1, &texture );
|
||||
glBindTexture( TYPE, texture );
|
||||
@@ -18,7 +18,7 @@ unsigned int config_texture( unsigned short type )
|
||||
return texture;
|
||||
}
|
||||
|
||||
void use_texture( unsigned int texture )
|
||||
void use_texture( id_t texture )
|
||||
{
|
||||
return glBindTexture( TYPE, texture );
|
||||
}
|
||||
@@ -28,9 +28,9 @@ void destroy_texture( unsigned int texture )
|
||||
return glDeleteTextures( 1, &texture );
|
||||
}
|
||||
|
||||
unsigned int create_palette_texture( const unsigned char * colors )
|
||||
id_t create_palette_texture( const unsigned char * colors )
|
||||
{
|
||||
unsigned int texture = config_texture( TYPE );
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user