Grafica algo pero no la banda

This commit is contained in:
alan
2024-10-17 19:37:00 -06:00
parent 252aab3dd2
commit 7333f3933c
6 changed files with 68 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
BIN = manigraph
OBJ = \
src/banda_mob.o \
src/context.o \
src/texture.o \
src/window.o \
@@ -8,7 +9,6 @@ OBJ = \
src/shader.o \
src/input.o \
src/mesh.o \
src/alan.o \
src/main.o
CFLAGS = \
@@ -35,14 +35,16 @@ windows: $(OBJ) glfw.dll
glfw.dll:
$(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@ -lgdi32
src/main.o: src/data/shaders.h src/data/cube.h src/data/axis.h
# LINUX
linux-x11: $(OBJ)
$(MAKE) BKN=_GLFW_X11 libglfw.so
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw -lm
linux-wayland: $(OBJ)
$(MAKE) BKN=_GLFW_WAYLAND libglfw.so
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw -lm
run-linux:
LD_LIBRARY_PATH=. ./$(BIN)

48
src/banda_mob.c Normal file
View File

@@ -0,0 +1,48 @@
#include <stdio.h>
#include "main.h"
#include <math.h>
#define PI 3.14159265358979323846
#define GRID_SIZE 256
#define WIDTH 0.5 // Ancho de la cinta de Möbius
void getMobiusPoint(float *p, int i, int j) {
float u = (2*PI) * ( (float)i/(GRID_SIZE+1) );
float v = (2*WIDTH) * ((float)j/(GRID_SIZE+1) ) - WIDTH;
p[0] = cos(u) + v * cos(u / 2) * cos(u);
p[1] = sin(u) + v * cos(u / 2) * sin(u);
p[2] = v * sin(u / 2);
}
float * acabron(){
int k=0;
long size = GRID_SIZE*GRID_SIZE*2*3;
float * d_cube;
d_cube = malloc((size+1)*sizeof(float));
d_cube[0] = size;
for (int i = 0; i < GRID_SIZE; i++)
{
for (int j = 0; j < GRID_SIZE; j++)
{
// Triángulo 1
getMobiusPoint(&d_cube[k + 1], i, j);
getMobiusPoint(&d_cube[k + 2], i + 1, j);
getMobiusPoint(&d_cube[k + 3], i + 1, j + 1);
// Triángulo 2
getMobiusPoint(&d_cube[k + 4], i, j);
getMobiusPoint(&d_cube[k + 5], i, j + 1);
getMobiusPoint(&d_cube[k + 6], i + 1, j + 1);
// Imprimir los triángulos generados
k+=6;
}
}
return d_cube;
}

View File

@@ -20,7 +20,7 @@ const float Z = 0.05;
#define G X, Y,-Z,
#define H X, Y, Z,
narray_float_t d_axis =
float d_axis[] =
{
3*3*2*6,

View File

@@ -1,5 +1,4 @@
#include "main.h"
#include "data/cube.h"
#include "data/axis.h"
#include "data/shaders.h"
#include <GL/glew.h>
@@ -17,9 +16,11 @@ unsigned char palette[] =
};
const char * wname = "manigraph: manifold grapher";
float * acabron(void);
int main( void )
{
float * d_cube;
id_t shader, texture;
mesh_t m_cube, m_axis;
window_t window;
@@ -32,6 +33,8 @@ int main( void )
glewInit();
d_cube = acabron();
if( !( shader = create_shader() ) )
goto error_shader;
@@ -40,9 +43,11 @@ int main( void )
use_shader( shader );
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
if( !( m_cube = create_mesh( d_cube ) ) )
goto error_mesh_cube;
goto error_mesh_cube;
free(d_cube);
if( !( m_axis = create_mesh( d_axis ) ) )
goto error_mesh_axis;
@@ -66,8 +71,10 @@ int main( void )
load_mdl_matrix( shader, 2, 2 );
draw_mesh( m_axis );
#endif
load_mdl_matrix( shader, 0, 3 );
draw_mesh( m_cube );
}
destroy_texture( texture );

View File

@@ -23,7 +23,7 @@ int is_open_window(window_t window);
void close_window(window_t window);
mesh_t create_mesh(narray_float_t mesh);
mesh_t create_mesh( float * mesh);
void destroy_mesh(mesh_t p);

View File

@@ -7,7 +7,7 @@ struct obj
unsigned int vertex, vao, vbo;
};
mesh_t create_mesh( narray_float_t mesh )
mesh_t create_mesh( float * mesh )
{
struct obj * p;
@@ -20,10 +20,10 @@ mesh_t create_mesh( narray_float_t mesh )
glBindVertexArray( p->vao );
glBindBuffer( GL_ARRAY_BUFFER, p->vbo );
glBufferData( GL_ARRAY_BUFFER, (p->vertex*3)*sizeof(int), mesh+1,
glBufferData( GL_ARRAY_BUFFER, (p->vertex*3)*sizeof(float), mesh+1,
GL_STATIC_DRAW );
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(int), NULL );
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(float), NULL );
glEnableVertexAttribArray(0);
return p;