🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
More than one texture? Lesson10 ASC Importer
I''m currently integrating John Zolis'' 3DS ASC importer into
Lesson10 and I''ve got as far as trying to load multiple textures from a *.mtl file and hit a dead end....it''ll display the objects w/ one texture just fine. Any additional textures don''t display correctly.
Here''s the modified LoadGLTextures() and DrawGLScene(GLvoid)
when debugging, the values for texture[0]=1 & texture[1]=2
The values in "objects" appear to be just fine.
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[1]; // Create storage space for one TextureImage
glGenTextures(MAXTEXTURE, texture); // MAXTEXTURES is the max number of textures
for (int i=0; i < numTextures; i++)
{
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap''s Not Found Quit
TextureImage[0]=LoadBMP(textureList->bitmapname);
Status=TRUE; // Set The Status To TRUE
// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX,
TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
}
return Status; // Return The Status
}
int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
// int curObject = 5;
GLfloat x_m, y_m, z_m, u_m, v_m;
GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
GLfloat ytrans = -walkbias-0.25f;
GLfloat sceneroty = 360.0f - yrot;
glRotatef(lookupdown,1.0f,0,0);
glRotatef(sceneroty,0,1.0f,0);
glTranslatef(xtrans, ytrans, ztrans);
//Process each Object
for (int curObject = 0; curObject < numObjects; curObject++)
{
// Process Each Triangle
for (int curFace = 0; curFace < objects[curObject]->numFace; curFace++)
{
glBindTexture(GL_TEXTURE_2D, texture[objects[curObject]->pFace[curFace].texture]);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
x_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[0]].x;
y_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[0]].y;
z_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[0]].z;
u_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[0]].u;
v_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[0]].v;
if (curObject == 0) glTexCoord2f(u_m,v_m);
glVertex3f(x_m,y_m,z_m);
x_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[1]].x;
y_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[1]].y;
z_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[1]].z;
u_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[1]].u;
v_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[1]].v;
if (curObject == 0) glTexCoord2f(u_m,v_m);
glVertex3f(x_m,y_m,z_m);
x_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[2]].x;
y_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[2]].y;
z_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[2]].z;
u_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[2]].u;
v_m = objects[curObject]->pVertex[objects[curObject]->pFace[curFace].vertex[2]].v;
if (curObject == 0) glTexCoord2f(u_m,v_m);
glVertex3f(x_m,y_m,z_m);
glEnd();
}
}
return TRUE; // Everything Went OK
}
</i>
Or I could just delete the "if (curObject == 0) " before UV mapping the texture...Doh!
If anybody wants a copy of the now working ASC importer let me by email!
If anybody wants a copy of the now working ASC importer let me by email!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement