51 lines
995 B
C
51 lines
995 B
C
#include <GL/glew.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "wavefrontobj.h"
|
|
|
|
#define OBJ_LINE_BUFFER_SIZE 256
|
|
|
|
ParsedObjFile readObjFile(char* path) {
|
|
ParsedObjFile parsedFile;
|
|
|
|
FILE* fp = fopen(path, "r");
|
|
|
|
if (fp == NULL) {
|
|
fprintf(stderr, "File could not be opened: %s", path);
|
|
parsedFile.vertices = NULL;
|
|
parsedFile.length = 0;
|
|
}
|
|
|
|
uint numVertices = 0;
|
|
uint numVertexNormals = 0;
|
|
uint numFaces = 0;
|
|
uint numTextureCoords = 0;
|
|
|
|
char buf[OBJ_LINE_BUFFER_SIZE];
|
|
|
|
while (fgets(buf, OBJ_LINE_BUFFER_SIZE, fp)) {
|
|
if (buf[0] == 'v') {
|
|
if (buf[1] == ' ') {
|
|
numVertices++;
|
|
} else if (buf[1] == 't') {
|
|
numTextureCoords++;
|
|
} else if (buf[1] == 'n') {
|
|
numVertexNormals++;
|
|
}
|
|
}
|
|
if (buf[0] == 'f') {
|
|
numFaces++;
|
|
}
|
|
}
|
|
|
|
printf("Vertices: %d\nFaces: %d\nNormals:%d\nTextures:%d\n", numVertices, numFaces, numVertexNormals, numTextureCoords);
|
|
|
|
|
|
fclose(fp);
|
|
}
|
|
|
|
void clearParsedFile(ParsedObjFile file) {
|
|
free(file.vertices);
|
|
} |