Jump to content

  • Log In with Google      Sign In   
  • Create Account


What do I do with this?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Ahl   Members   -  Reputation: 168

Like
0Likes
Like

Posted 19 August 2012 - 06:33 PM

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?

Posted Image

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

Thanks in advance.

Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 8188

Like
0Likes
Like

Posted 19 August 2012 - 07:49 PM

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, 19 August 2012 - 07:50 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 Ahl   Members   -  Reputation: 168

Like
0Likes
Like

Posted 19 August 2012 - 09:38 PM

Right, they should have correct texture coordinates but when I apply the texture I get the following:

Posted Image

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.

#4 Bacterius   Crossbones+   -  Reputation: 8188

Like
0Likes
Like

Posted 19 August 2012 - 09:43 PM

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, 19 August 2012 - 09:44 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 Ahl   Members   -  Reputation: 168

Like
0Likes
Like

Posted 19 August 2012 - 10:33 PM

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

#6 SimonForsman   Crossbones+   -  Reputation: 5810

Like
1Likes
Like

Posted 19 August 2012 - 11:18 PM

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)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#7 Ahl   Members   -  Reputation: 168

Like
0Likes
Like

Posted 20 August 2012 - 10:08 AM

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

#8 WarAmp   Members   -  Reputation: 723

Like
2Likes
Like

Posted 20 August 2012 - 10:41 AM

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....

Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.

#9 powly k   Members   -  Reputation: 632

Like
0Likes
Like

Posted 20 August 2012 - 10:41 AM

Does the .obj file have normalized texture coordinates, in the range [0,1]?

#10 Ahl   Members   -  Reputation: 168

Like
0Likes
Like

Posted 20 August 2012 - 12:12 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS