PDA

View Full Version : What's wrong here?:(



M/\dm/\n
11-30-2002, 01:01 AM
Unfortunately I have to post this topic at Advanced board, there was no solution at the beginner board for a week http://www.opengl.org/discussion_boards/ubb/frown.gif

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.vert*3+3];
na = new float[temp.vert*3+3];
ta = new float[temp.vert*2+2];
i3 = new unsigned int[temp.i3*3];
i4 = new unsigned int[temp.i4*4];
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,'\n');
if ((c[0]=='v') &amp;&amp; (c[1]==' '))
temp.vert++;
if ((c[0]=='f') &amp;&amp; (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,'\n');
if ((c[0]=='v') &amp;&amp; (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]!=' ')&amp;&amp;(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*va++=float(atof(temp));
}
}
if ((c[0]=='v') &amp;&amp; (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]!=' ')&amp;&amp;(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*ta++=float(atof(temp));
}
}
if ((c[0]=='v') &amp;&amp; (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]!=' ')&amp;&amp;(c[k]!=0))
{
temp[j]=c[k];
j++;
k++;
}
*na++=float(atof(temp));
}
}
if ((c[0]=='f') &amp;&amp; (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]!='/')&amp;&amp;(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]!='/')&amp;&amp;(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 http://www.opengl.org/discussion_boards/ubb/frown.gif

Madman

[This message has been edited by M/\dm/\n (edited 11-30-2002).]

okapota
11-30-2002, 02:45 AM
dont you to enable/disable the vertex array inside the list, and not outside? it seems to me you are drawing the mesh with vertexarray disabled.

Bob
11-30-2002, 03:36 AM
That shouldn't be a problem. When you build a display list from a vertex array, the vertex array data will be dereferenced at compile time and moved to the display list instead. As long as the vertex array is enabled at the point where it's compiled it should be OK.

By the way, this kind of operation is typically something you put in the startup phase of your program, but make sure you're not calling it too early, i.e. make sure you have a rendering context.

M/\dm/\n
11-30-2002, 04:19 AM
Thanks for advice, but unfortunately that didn't helped. Other Lists in my program, that are being created before this and also include vertex arrays works with no problems. So there's somthing wrong with OBJ importer http://www.opengl.org/discussion_boards/ubb/frown.gif I checked out va,na... in MSVC debuger and they have real data, that from the file.

Ysaneya
11-30-2002, 05:20 AM
Everything looks fine, and if you say you've got the correct results in memory in the vertex and index arrays, it's probably not the OBJ importer.

Maybe it's a stupid mistake somewhere else ? You say nothing is drawn, but are your transformation matrix correct ? Maybe you're just not looking at the object ?

Y.

jwatte
11-30-2002, 06:48 AM
What's the size of the object? What's your viewing frustum in object space? (near/far may clip it out, too)

Gdo
11-30-2002, 12:30 PM
Have you tried to create and render only THIS display list ?
Are you sure you have enought video memory to create all your display lists ?

Ysaneya
12-01-2002, 02:56 AM
I don't see what video memory has anything to do with that matter. For all we know, display lists can be stored in AGP or in system memory. In addition, you have no way to check for video memory usage.

Y.

M/\dm/\n
12-01-2002, 05:26 AM
I want to import static cube -1,-1,-1 1,1,1 in my game so far, so i can walk to that point http://www.opengl.org/discussion_boards/ubb/frown.gif It seems that I'll have to look for other examples and check them out.

zeckensack
12-01-2002, 05:41 AM
Did you just say unit cube?
Ummm ... do you have backface culling enabled?

Try
glDisable(GL_CULL_FACE);