Display Lists and Obj. File Loader Problems

Member
Posts: 40
Joined: 2008.10
Post: #1
Hello. I have been making an obj file loader and everything time I try to display the models, nothing shows up on the screen. I have double checked to see if it's loading obj files correctly by making it print out every vertex, and it has, and it also has been making all the display lists correctly(using the same method). Clearly they are only working correctly in my eyes, because when I call the display lists in the middle of my OpenGL code, I get a blank screen. Here is the code

Object.h
Code:
#ifndef OBJECT_H
#define OBJECT_H

#include <stdlib.h>
#include <GLUT/glut.h>
#include <stdio.h>
#include <string.h>

#define MAX_VERTICES 10000
#define MAX_FACES 1000

struct Object
{
    float vertices[MAX_VERTICES][3];
    float normals[MAX_VERTICES][3];
    float texCoords[MAX_VERTICES][3];
    int faces[MAX_FACES][3][3];
    int counter[5];
    int otype;
    GLuint model;
};    
struct Object objects[10];
float vertices[MAX_VERTICES][3];
float normals[MAX_VERTICES][3];
float texCoords[MAX_VERTICES][3];
int faces[MAX_FACES][3][3];
int counter[5];
int otype;
extern void loadObjFile(char* filename, int objType ,int num);
extern void loadList(int num);
extern void draw(int num);

#endif

and
Object.c
Code:
#include "Object.h"





void loadObjFile(char* filename, int objType, int num)
{
    
    FILE *fptr;
    fptr = fopen(filename, "r");
    char token[1000];
    
    while(!feof(fptr))
    {
        fscanf(fptr, "%s", token);
        if(!strcmp(token,"v"))
        {
            fscanf(fptr,"%f %f %f", &objects[num].vertices[objects[num].counter[1]][0], &objects[num].vertices[objects[num].counter[1]][1], &objects[num].vertices[objects[num].counter[1]][2]);
            objects[num].counter[1]++;
        }
        if(!strcmp(token, "vn"))
        {
            fscanf(fptr,"%f %f %f", &objects[num].normals[objects[num].counter[2]][0], &objects[num].normals[objects[num].counter[2]][1], &objects[num].normals[objects[num].counter[2]][2]);
            objects[num].counter[2]++;
        }
        if(!strcmp(token, "vt"))
        {
            fscanf(fptr,"%f %f %f", &objects[num].texCoords[objects[num].counter[3]][0], &objects[num].texCoords[objects[num].counter[3]][1], &objects[num].texCoords[objects[num].counter[3]][2]);
            objects[num].counter[3]++;
        }
        if(!strcmp(token, "f"))
        {
            if(objType==2)
            {
                fscanf(fptr,"%d/%d/%d", &objects[num].faces[objects[num].counter[4]][0], &objects[num].faces[objects[num].counter[4]][1], &objects[num].faces[objects[num].counter[4]][2]);
            }else{
                fscanf(fptr,"%d//%d", &objects[num].faces[objects[num].counter[4]][0], &objects[num].faces[objects[num].counter[4]][2]);
            }
            objects[num].counter[4]++;
        }
        objects[num].counter[0]++;
    }
    fclose(fptr);
    
}

void loadList(int num)
{
    objects[num].model=glGenLists(1);
    glNewList(objects[num].model,GL_COMPILE);
    int x=0;
    while(x<objects[num].counter[4])
    {
        int y=0;
        int u=0;
        int p=0;
        glBegin(GL_TRIANGLES);
        while(y<3)
        {
            u=objects[num].faces[x][y][2];
            p=objects[num].faces[x][y][0];
            glNormal3f(objects[num].normals[u][0],objects[num].normals[u][1],objects[num].normals[u][2]);
            glVertex3f(objects[num].vertices[p][0],objects[num].vertices[p][1],objects[num].vertices[p][2]);
            y++;
        }
        printf("\n");
        glEnd();
        x++;
    }
    glEndList();
        
}
void draw(int num)
{
    glCallList(objects[num].model);
}

I would really appreciate any help. Thank you
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDL_TTF Problems (Can't display text) pb2ya 4 5,017 Sep 18, 2008 06:50 PM
Last Post: Raptor007
  Display Lists or Vertex Arrays with texturing seven 6 3,587 Oct 17, 2005 09:24 AM
Last Post: seven
  Slowing Frame Rates and Display Lists Nick 4 2,876 Mar 27, 2005 06:08 AM
Last Post: wadesworld
  More display lists not working... SOUR-Monkey 1 2,275 Dec 8, 2004 09:11 PM
Last Post: SOUR-Monkey
  Display Lists not working Jake 6 3,694 Dec 8, 2004 04:10 PM
Last Post: TomorrowPlusX