PCX over mesh

paul
Unregistered
 
Post: #1
Hy,
i have a lot of questions about how opengl manipolate PCX (my texture) over a mesh:

i must to develop a small opengl project: ther's a girl that mov's when you press the top row. I have already loaded a girl (mesh.ani) and now i must to load file PCX ( my texture) into the mesh. To do i use a class Coni3DPCX and method LoadPCX that permits to load PCX correctly (but i don't see nothing!!).
The problem is: why i cannot display a texture? how i can to put this texture in the mesh? Which of methods i'v must to use?


The function LoadPCX is:

Code:
int Cone3DPCX::LoadPCX(char *filename)
{
  FILE *hTexFile = fopen( filename, "rb" );
  /* check the file open command */
  if( hTexFile != NULL )
  {
    int imgWidth,width,height, imgHeight, texFileLen, imgBufferPtr, i;
    pcxHeader *pcxPtr;
    unsigned char *imgBuffer, *texBuffer, *pcxBufferPtr, *paletteBuffer;

    /* find length of file */
    fseek( hTexFile, 0, SEEK_END );
    texFileLen = ftell( hTexFile );
    fseek( hTexFile, 0, SEEK_SET );

    /* read in file */
    texBuffer = (unsigned char *)malloc( texFileLen+1 );
    fread( texBuffer, sizeof( char ), texFileLen, hTexFile );

    /* get the image dimensions */
    pcxPtr = (pcxHeader *)texBuffer;
    imgWidth = pcxPtr->size[0] - pcxPtr->offset[0] + 1;
    imgHeight = pcxPtr->size[1] - pcxPtr->offset[1] + 1;

      /* image starts at 128 from the beginning of the buffer */
    imgBuffer = (unsigned char *)malloc( imgWidth * imgHeight );
    imgBufferPtr = 0;
    pcxBufferPtr = &texBuffer[128];

    /* decode the pcx image */
    while( imgBufferPtr < (imgWidth * imgHeight) )
    {
      if( *pcxBufferPtr > 0xbf )
      {
        int repeat = *pcxBufferPtr++ & 0x3f;
        for( i=0; i<repeat; i++ )
        {
          imgBuffer[imgBufferPtr++] = *pcxBufferPtr;
        }
      } else {
        imgBuffer[imgBufferPtr++] = *pcxBufferPtr;
      }
      pcxBufferPtr++;
    }

    /* read in the image palette */
    paletteBuffer = (unsigned char *)malloc( 768 );
    for( i=0; i<768; i++ )
      paletteBuffer[i] = texBuffer[ texFileLen-768+i ];

    width=imgWidth;
    height=imgHeight;

    /* now create the OpenGLure */
    {
      int i, j;
      imageData = (unsigned char *)malloc( width * height * 3 );
      for (j = 0; j < imgHeight; j++)
      {
        for (i = 0; i < imgWidth; i++)
        {
          imageData[3*(j * width + i)+0]
            = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+0 ];
          imageData[3*(j * width + i)+1]
            = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+1 ];
          imageData[3*(j * width + i)+2]
            = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+2 ];
        }
      }
    }
    /* cleanup */
    free( paletteBuffer );
    free( imgBuffer );
     gluBuild2DMipmaps(
                   GL_TEXTURE_2D,
                   GL_RGB,
                   width,height,
                   GL_RGB,
                   GL_UNSIGNED_BYTE,
                   imageData
                   );
    glGenTextures(1, &texID);
    glBindTexture(GL_TEXTURE_2D, texID);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_RGB,
    GL_UNSIGNED_BYTE,imageData);
    bpp=24;

//But if the file didn't load, then we'll return zero. Else we'll return 1.

  } else {
    /* skip the texture setup functions */
    return 0;
  }

  return 1;
}


Is enought to display texture but i cannot see nothing!!

Thanks for all
DM
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #2
I think you need glEnable(GL_TEXTURE_2D) also

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
paul
Unregistered
 
Post: #3
Ok, i'v already try to add glEnable(--) but nothing.

Questions:
-To display the texture is correct the function that i use (Load PCX)?
-Once texture is loaded automatically sets on the mesh? If not, where e how i must to do?

thanks
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #4
Does the model have texture coordinates(uvs)?

If you don't know what either of those things are, maybe you should read up on OpenGL texturing.

http://www.spacesimulator.net/tut3_texturemapping.html

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
paul
Unregistered
 
Post: #5
Yes, i have texture coordinates in the mesh file. The mesh file is .ani and so:
v1 v2 v3 -- -- -- -- -- -- in each row there are 3 vertex and 6 texture coordanates.
-I read the mesh file and memorize the face, the vertex and the texture coordinates;
-I read the texture file (procedure on the previous post)
-I connect the texture coordinates with the vertex coordinates:

for(------)
glTexCoord2d(u,v)
glVertex3f(--vertex1--)
glTexCoord2d(u,v)
glVertex3f(--vertex2--)
glTexCoord2d(u,v)
glVertex3f(--vertex3--)

but nothing is displayed.
What i must to do? If you want i send you the function that i use to read a mesh file & texture file.
Thanks
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  how to create a grid / 2D mesh bfarah 1 4,140 Oct 20, 2010 02:22 AM
Last Post: iamflimflam1
  Boolean Mesh Operations and Mesh-Based CSG Oddity007 2 5,726 Feb 13, 2010 03:42 PM
Last Post: Oddity007
  OpenGL ES creating a 2D mesh soulstorm 0 3,031 May 20, 2009 02:37 AM
Last Post: soulstorm
  Spherical Mesh. dave05 8 5,940 Oct 29, 2008 02:53 PM
Last Post: mholg
  Breaking down a concave mesh into convex pieces Willem 5 4,713 Aug 10, 2008 05:49 AM
Last Post: Willem