• Advertisement
Sign in to follow this  

What do I do with this?

This topic is 1980 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all,

I'm loading a model with AssImp and using DevIL for the textures. I'm using models from Turbosquid for testing and I'm having some troubles. First I'll start with asking what exactly I'm supposed to do with the following?

color_6.jpg

The model is made up of a single Mesh, so what do I do with this texture?

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You're supposed to "parse" it using texture coordinates (aligning your model's texture coordinates on this texture image instead of each different texture of your model having its own individual texture image - which would probably contain a lot of wasted space). Doing it like this saves space and is often more convenient for the artist (and looks sort of cool, too).

In theory the model you downloaded from Turbosquid already has its texture coordinates set to match the accompanying texture, so you just need to read those uv's when loading the mesh and use that texture to render. Edited by Bacterius

Share this post


Link to post
Share on other sites
Right, they should have correct texture coordinates but when I apply the texture I get the following:

borkedtextures.jpg

This would be the second part of my question. The texture seems to be shrunk considerably and then the black edges get clamped all the way around instead of being stretched appropriately.

Share this post


Link to post
Share on other sites
How do you apply the texture, can you show some code? And also link to the relevant model (if it's free). I can't really see on the screenshot but it seems you are applying the texture in screen space? Weird. I think code is needed here. Edited by Bacterius

Share this post


Link to post
Share on other sites
Loading the texture:

GLuint loadImage(const char* theFileName)
{
ILuint imageID; // Create an image ID as a ULuint

GLuint textureID = 0; // Create a texture ID as a GLuint

ILboolean success; // Create a flag to keep track of success/failure

ILenum error; // Create a flag to keep track of the IL error state

ilGenImages(1, &imageID); // Generate the image ID

ilBindImage(imageID); // Bind the image

success = ilLoadImage((ILstring)theFileName); // Load the image file

// If we managed to load the image, then we can start to do things with it...
if (success)
{
// If the image is flipped (i.e. upside-down and mirrored, flip it the right way up!)
ILinfo ImageInfo;
iluGetImageInfo(&ImageInfo);
if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT)
{
iluFlipImage();
}

// Convert the image into a suitable format to work with
// NOTE: If your image contains alpha channel you can replace IL_RGB with IL_RGBA
success = ilConvertImage(ilGetInteger(IL_IMAGE_FORMAT), IL_UNSIGNED_BYTE);

// Quit out if we failed the conversion
if (!success)
{
error = ilGetError();
std::cout << "Image conversion failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
//exit(-1);
}

// Generate a new texture
glGenTextures(1, &textureID);

// Bind the texture to a name
glBindTexture(GL_TEXTURE_2D, textureID);

// Set texture clamping method
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

// Set texture interpolation method to use linear interpolation (no MIPMAPS)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

// Specify the texture specification
glTexImage2D(GL_TEXTURE_2D, // Type of texture
0, // Pyramid level (for mip-mapping) - 0 is the top level
ilGetInteger(IL_IMAGE_BPP), // Image colour depth
ilGetInteger(IL_IMAGE_WIDTH), // Image width
ilGetInteger(IL_IMAGE_HEIGHT), // Image height
0, // Border width in pixels (can either be 1 or 0)
ilGetInteger(IL_IMAGE_FORMAT), // Image format (i.e. RGB, RGBA, BGR etc.)
IL_UNSIGNED_BYTE, // Image data type
ilGetData()); // The actual image data itself
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
else // If we failed to open the image file in the first place...
{
error = ilGetError();
std::cout << "Image load failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
std::cout << theFileName << std::endl;
exit(-1);
}
ilDeleteImages(1, &imageID); // Because we have already copied image data into texture data we can release memory used by image.
//std::cout << "Texture creation successful." << std::endl;
return textureID; // Return the GLuint to the texture so you can use it!
}


Draw the scene:

void RenderScene()
{
std::sort (RenderList.begin(), RenderList.end(), SortRenderList);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
Material *TempMat = NULL;
MyVertex *TempVerts = NULL;
glDisable(GL_TEXTURE_2D);
for (RenderListIT = RenderList.begin(); RenderListIT != RenderList.end(); RenderListIT++)
{
glLoadIdentity();
glTranslatef((*RenderListIT)->Position->x, (*RenderListIT)->Position->y, (*RenderListIT)->Position->z);

glScalef ((*RenderListIT)->Scale->x, (*RenderListIT)->Scale->y, (*RenderListIT)->Scale->z);
glRotatef ((*RenderListIT)->Rotation->x, 1.0f, 0.0f, 0.0f);
glRotatef ((*RenderListIT)->Rotation->y, 0.0f, 1.0f, 0.0f);
glRotatef ((*RenderListIT)->Rotation->z, 0.0f, 0.0f, 1.0f);
if (TempMat == NULL || TempMat != (*RenderListIT)->RenderMesh->Materials)
{
TempMat = (*RenderListIT)->RenderMesh->Materials;
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (*RenderListIT)->RenderMesh->Materials->Diffuse );
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (*RenderListIT)->RenderMesh->Materials->Specular );
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (*RenderListIT)->RenderMesh->Materials->Ambient );
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (*RenderListIT)->RenderMesh->Materials->Emission );
}
if (TempVerts == NULL || TempVerts != (*RenderListIT)->RenderMesh->VertexData)
{
TempVerts = (*RenderListIT)->RenderMesh->VertexData;

if ((*RenderListIT)->RenderMesh->HasVertexs == true)
{
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer( 3, GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
}
if ((*RenderListIT)->RenderMesh->HasNormals == true)
{
glEnable(GL_LIGHTING);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer( GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisable(GL_LIGHTING);
glDisableClientState(GL_NORMAL_ARRAY);
}
if ((*RenderListIT)->RenderMesh->HasTexcoords == true)
{
if ((*RenderListIT)->RenderMesh->HasTexture == true)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, (*RenderListIT)->RenderMesh->Active->TextureHandle);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if ((*RenderListIT)->RenderMesh->HasColors)
{
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer( 3, GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisableClientState(GL_COLOR_ARRAY);
}
}
glDrawArrays(GL_TRIANGLES, 0, (*RenderListIT)->RenderMesh->NumVerticies);
}
//RenderList.clear();
glutSwapBuffers();
}


the model http://www.turbosquid.com/FullPreview/Index.cfm/ID/526437

Share this post


Link to post
Share on other sites
It looks like you are using RenderMesh->VertexData for your texcoords, this is most likely incorrect (Since it appears as if you're only storing vertex coordinates in that structure), With assimp you get the texture coordinates in the mTextureCoords member. (I can't see your model loading code so i can't be much more specific than that)

Share this post


Link to post
Share on other sites

struct MyVertex
{
float x, y, z; // Vertex
float nx, ny, nz; // Normal
float u, v; // Texcoords
float a, r, g, b; // Color
float padding[4];
};


That's my VertexData

Share this post


Link to post
Share on other sites


struct MyVertex
{
float x, y, z; // Vertex
float nx, ny, nz; // Normal
float u, v; // Texcoords
float a, r, g, b; // Color
float padding[4];
};



My openGL is a bit rusty, but I believe you want the value passed into the gl*Pointer() functions to actually point to the part of the struct that is relevant.
ie:

glNormalPointer( GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.nx );
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.u );
glColorPointer( 3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.a );
//etc....

Share this post


Link to post
Share on other sites


glNormalPointer( GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.nx );
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.u );
glColorPointer( 3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.a );
//etc....



That did it. It's working now. Awesome, thank you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement