Unfortunately I have to post this topic at Advanced board, there was no solution at the beginner board for a week
I’ve written this code, but it dosn’t work:
In render function I call glCallList(rhino);
Here is the list creating routine + OBJ load routine:
float va, na, ta;
unsigned int i3, i4;
sizes temp;
temp = GetPointerSizes(“1.obj”);
va = new float[temp.vert3+3];
na = new float[temp.vert3+3];
ta = new float[temp.vert2+2];
i3 = new unsigned int[temp.i33];
i4 = new unsigned int[temp.i44];
Loader(“1.obj”, va, na, ta, i3, i4);
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer(3, GL_FLOAT, 0, va);
rhino = glGenLists (1);
glNewList(rhino, GL_COMPILE);
glColor4f(1,0,0,1);
(temp.i3==0)?NULL:glDrawElements(GL_TRIANGLES, temp.i3, GL_UNSIGNED_INT, i3);
(temp.i4==0)?NULL:glDrawElements(GL_QUADS, temp.i4, GL_UNSIGNED_INT, i4);
glEndList();
glDisableClientState (GL_VERTEX_ARRAY);
header file => ObjLoader.h <=
#include <windows.h>
#include <GL/gl.h>
struct sizes{
int vert;
int i3;
int i4;};
sizes GetPointerSizes(const char *file);
void Loader(const char *file, float *va, float *na, float *ta, unsigned int *i3, unsigned int *i4);
and source file => ObjLoader.cpp <=
#include <fstream.h>
#include <string.h>
#include “ObjLoader.h”
struct sizes GetPointerSizes(const char *file)
{ sizes temp;
temp.i3=0;
temp.i4=0;
temp.vert=0;
fstream obj;
obj.open(file,ios::in);
if (!obj.is_open())
MessageBox(NULL,“Error opening file!”,“Load error!”,MB_ICONSTOP);
while (!obj.eof())
{ char c[100]=“”;
obj.getline(c,99,’
‘);
if ((c[0]==‘v’) && (c[1]==’ ‘))
temp.vert++;
if ((c[0]==‘f’) && (c[1]==’ ‘))
{
int i=0, sp=0;
while (c[i]!=0)
{
if (c[i]==32)
sp++;
i++;
}
(sp>3)?temp.i4++:temp.i3++;
}
}
obj.close();
return temp;
}
void Loader(const char *file, float *va, float *na, float *ta, unsigned int *i3, unsigned int *i4)
{
fstream obj;
obj.open(“1.obj”,ios::in);
if (!obj.is_open())
MessageBox(NULL,“Error opening file!”,“Load error!”,MB_ICONSTOP);
while (!obj.eof())
{
int i=0;
char c[89]=“”;
obj.getline(c,88,’
‘);
if ((c[0]==‘v’) && (c[1]==’ ‘))
for (i=0;i<abs(strlen(c));i++)
{
if (c[i]==’ ‘)
{
int k=i+1;
char temp[26]=“”;
int j=0;
while ((c[k]!=’ ‘)&&(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*va++=float(atof(temp));
}
}
if ((c[0]==‘v’) && (c[1]==‘t’))
for (i=0;i<abs(strlen(c));i++)
{
if (c[i]==’ ‘)
{
int k=i+1;
char temp[12]=“”;
int j=0;
while ((c[k]!=’ ‘)&&(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*ta++=float(atof(temp));
}
}
if ((c[0]==‘v’) && (c[1]==‘n’))
for (i=0;i<abs(strlen(c));i++)
{
if (c[i]==’ ‘)
{
int k=i+1;
char temp[26]=“”;
int j=0;
while ((c[k]!=’ ‘)&&(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*na++=float(atof(temp));
}
}
if ((c[0]==‘f’) && (c[1]==’ ‘))
{
int i=0, sp=0;
while (c[i]!=0)
{
if (c[i]==’ ‘)
sp++;
i++;
}
if (sp>3)
{
for (i=0;i<abs(strlen(c));i++)
{
if (c[i]==’ ‘)
{
int k=i+1;
char temp[5]=“”;
int j=0;
while ((c[k]!=’/‘)&&(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*i4++=int(atoi(temp))-1;
}
}
}
else
{
for (i=0;i<abs(strlen(c));i++)
{
if (c[i]==’ ‘)
{
int k=i+1;
char temp[5]=“”;
int j=0;
while ((c[k]!=’/')&&(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*i3++=int(atoi(temp))-1;
}
}
}
}
}
obj.close();
}
It seems that arrays are ok, idices also, but list is empty, it draws nothing
Madman
[This message has been edited by M/\dm/
(edited 11-30-2002).]