PDA

View Full Version : Please help, texture not appearing



Ray14324
11-11-2010, 02:38 PM
I'm using the glm to load meshes as .obj, the problem I am facing is that the textures won't appear. i have a working example and I tried to mimic it in my code but no matter what I do no results show up and I can't figure out why(I don't know where else to go to). I write to you in hopes that someone is willing to guide this poor noob through this tormenting problem.
the loading code for the TGA image ( it is in a power of 2 ; 256)

Texture worldTexture[1];
int LoadWorldTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE;
// Status Indicator

// Load The Bitmap, Check For Errors.
if (LoadTGA(&worldTexture[0], "texture/sky_texture2.tga"))
{
Status=TRUE; // Set The Status To TRUE
}
else
{
Status=FALSE;
}

if(Status==TRUE)
{
for (int loop=0; loop<1; loop++) // Loop Through Both Textures
{
// Typical Texture Generation Using Data From The TGA ( CHANGE )
glGenTextures(1, &amp;worldTexture[loop].texID); // Create The Texture ( CHANGE )
glBindTexture(GL_TEXTURE_2D, worldTexture[loop].texID);
glTexImage2D(GL_TEXTURE_2D, 0, worldTexture[loop].bpp / 8, worldTexture[loop].width, worldTexture[loop].height, 0, worldTexture[loop].type, GL_UNSIGNED_BYTE, worldTexture[loop].imageData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

if (worldTexture[loop].imageData) // If Texture Image Exists ( CHANGE )
{
free(worldTexture[loop].imageData); // Free The Texture Image Memory ( CHANGE )
}
}
}
return Status; // Return The Status
}

the drawing of the object

void draw_pamant()
{
if (!pamant)
{
pamant = glmReadOBJ("pamant.obj");
if (!pamant) exit(0);
// scaleC=glmUnitize(pamant);
glmFacetNormals(pamant);
glmVertexNormals(pamant, 90.0);
}
glmDraw(pamant, GLM_SMOOTH | GLM_TEXTURE);

}

the initialization of openGL

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel (GL_SMOOTH);
gluPerspective(90.0f, (GLfloat)screen_width/(GLfloat)screen_height, 1.0f, 10000.0f);

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_TEXTURE_2D);
LoadWorldTextures();
}

and finaly the rendering

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
gluLookAt(0,0,50,0,0,-10,0,1,0);

glPushMatrix();
glTranslatef(transX[0],transY[0],transZ[0]);
glMultMatrixf(rot_scena);
glScalef(scalare_scena[0],scalare_scena[0],scalare_scena[0]);

glTranslatef(0,zoom,0);

glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,worldTexture[0].texID);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1f);
draw_pamant();
glPopMatrix();
glPopMatrix();
}
I use glut for the utility library. Please help me out I just don't know where to search for next. I must mention that my knowledge is very limited so excuse me if the problem is somehow considered by some elementary.
Thank-you.