45 lines
1.0 KiB
C
45 lines
1.0 KiB
C
#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 an int 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;
|
|
}
|