eckiller

04-13-2000, 01:19 PM

Hi,

Can someone give me an idea of why my model isnt texturing correcly. It is rendering in wire frames correctly. Heres my model render function which is called in my main render function. I'm calling glBind and enabling 2d textures also in another function. I am getting some textures, but they are off and looks funny.

BOOL CMD2::RenderMD2Model( MD2MODEL *model )

{

// looping variables

int i,j;

// create an array large enough to hold all the verts and there 3

// data points that they hold

GLfloat *verts = new GLfloat[model->NumVerts*3];

// occupy the verts array;

int vc1=0, vc2=1, vc3=2;

for(i=0; i < model->NumVerts; i++)

{

verts[vc1] = model->Frames[0].Verts[i].x;

verts[vc2] = model->Frames[0].Verts[i].y;

verts[vc3] = model->Frames[0].Verts[i].z;

vc1+=3;vc2+=3;vc3+=3;

}

// loop through the primitives and each primitives index list

// render each primitive at a time. Test to see if it is

// a triangle strip of fan.

int ic1 = 0;

int s_t = 0;

int t_t = 1;

for(i=0; i < model->NumPrimitives; i++) //model->NumPrimitives; i++)

{

GLuint *indices = new GLuint[model->Primitives[i].NumFaceIndices];

// pointer to st tex coords

GLfloat *st = new GLfloat[model->Primitives[i].NumFaceIndices*2];

for(j=0; j < model->Primitives[i].NumFaceIndices; j++)

{

st[s_t] = (GLuint)model->Primitives[i].FaceIndices[j].s;

st[t_t] = (GLuint)model->Primitives[i].FaceIndices[j].t;

indices[ic1] = (GLuint)model->Primitives[i].FaceIndices[j].index;

ic1++;

s_t += 2;

t_t += 2;

}

ic1 = 0;

s_t = 0;

t_t = 1;

glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glTexCoordPointer(2, GL_FLOAT, 0, st);

glVertexPointer(3, GL_FLOAT, 0, verts);

if(model->Primitives[i].PrimitiveType == MD2_TRIANGLESTRIP)

{

glDrawElements(GL_TRIANGLE_STRIP, model->Primitives[i].NumFaceIndices,

GL_UNSIGNED_INT, indices);

}

if(model->Primitives[i].PrimitiveType == MD2_TRIANGLEFAN)

{

glDrawElements(GL_TRIANGLE_FAN, model->Primitives[i].NumFaceIndices,

GL_UNSIGNED_INT, indices);

}

delete [] indices; indices = NULL;

delete [] st; st = NULL;

}

// delete the verts array

delete [] verts; verts = NULL;

return true;

}

Can someone give me an idea of why my model isnt texturing correcly. It is rendering in wire frames correctly. Heres my model render function which is called in my main render function. I'm calling glBind and enabling 2d textures also in another function. I am getting some textures, but they are off and looks funny.

BOOL CMD2::RenderMD2Model( MD2MODEL *model )

{

// looping variables

int i,j;

// create an array large enough to hold all the verts and there 3

// data points that they hold

GLfloat *verts = new GLfloat[model->NumVerts*3];

// occupy the verts array;

int vc1=0, vc2=1, vc3=2;

for(i=0; i < model->NumVerts; i++)

{

verts[vc1] = model->Frames[0].Verts[i].x;

verts[vc2] = model->Frames[0].Verts[i].y;

verts[vc3] = model->Frames[0].Verts[i].z;

vc1+=3;vc2+=3;vc3+=3;

}

// loop through the primitives and each primitives index list

// render each primitive at a time. Test to see if it is

// a triangle strip of fan.

int ic1 = 0;

int s_t = 0;

int t_t = 1;

for(i=0; i < model->NumPrimitives; i++) //model->NumPrimitives; i++)

{

GLuint *indices = new GLuint[model->Primitives[i].NumFaceIndices];

// pointer to st tex coords

GLfloat *st = new GLfloat[model->Primitives[i].NumFaceIndices*2];

for(j=0; j < model->Primitives[i].NumFaceIndices; j++)

{

st[s_t] = (GLuint)model->Primitives[i].FaceIndices[j].s;

st[t_t] = (GLuint)model->Primitives[i].FaceIndices[j].t;

indices[ic1] = (GLuint)model->Primitives[i].FaceIndices[j].index;

ic1++;

s_t += 2;

t_t += 2;

}

ic1 = 0;

s_t = 0;

t_t = 1;

glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glTexCoordPointer(2, GL_FLOAT, 0, st);

glVertexPointer(3, GL_FLOAT, 0, verts);

if(model->Primitives[i].PrimitiveType == MD2_TRIANGLESTRIP)

{

glDrawElements(GL_TRIANGLE_STRIP, model->Primitives[i].NumFaceIndices,

GL_UNSIGNED_INT, indices);

}

if(model->Primitives[i].PrimitiveType == MD2_TRIANGLEFAN)

{

glDrawElements(GL_TRIANGLE_FAN, model->Primitives[i].NumFaceIndices,

GL_UNSIGNED_INT, indices);

}

delete [] indices; indices = NULL;

delete [] st; st = NULL;

}

// delete the verts array

delete [] verts; verts = NULL;

return true;

}