FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

openGL: Texture Mapping

 


darth_revan
I want to import and use 2d textures. I checked out some tutorials about glut (such as http://www.morrowland.com/ ) and learnt how to use textures. In its tutorials, the author uses this function to import JPG files:
LoadJPG function:
Code:

tImage *LoadJPG(const char *strFileName){
   struct jpeg_decompress_struct cinfo;
   tImage *pImageData = NULL;
   FILE *pFile;   
   if((pFile = fopen(strFileName, "rb")) == NULL)
      return NULL;   
   jpeg_error_mgr jerr;   
   cinfo.err = jpeg_std_error(&jerr);
   jpeg_create_decompress(&cinfo);
   jpeg_stdio_src(&cinfo, pFile);
   pImageData = (tImage*)malloc(sizeof(tImage));
   jpeg_read_header(&cinfo, TRUE);
   jpeg_start_decompress(&cinfo);
   pImageData->channels = cinfo.num_components;
   pImageData->sizeX    = cinfo.image_width;
   pImageData->sizeY    = cinfo.image_height;
   int rowSpan = cinfo.image_width * cinfo.num_components;
   pImageData->data = ((unsigned char*)malloc(sizeof(unsigned char)*rowSpan*pImageData->sizeY));
   unsigned char** rowPtr = new unsigned char*[pImageData->sizeY];
   for (int i = 0; i < pImageData->sizeY; i++)
      rowPtr[i] = &(pImageData->data[i * rowSpan]);
   int rowsRead = cinfo.output_height-1;
   while (cinfo.output_scanline < cinfo.output_height)
   { rowsRead -= jpeg_read_scanlines(&cinfo, &rowPtr[rowsRead], cinfo.output_height - rowsRead); }
delete [] rowPtr;
   jpeg_finish_decompress(&cinfo);
   jpeg_destroy_decompress(&cinfo);
   fclose(pFile);
   return pImageData;
}


and the exact function to load texture:

Code:

bool Load_Texture(UINT &texture, LPSTR strFileName)
{   if(!strFileName)  return false;
   tImage *pImage = NULL;
   pImage = LoadJPG(strFileName);
   if(pImage == NULL)   return false;
   glGenTextures(1, &texture);
   glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
   glBindTexture(GL_TEXTURE_2D, texture);
   int textureType = GL_RGB;
   if(pImage->channels == 4)
      textureType = GL_RGBA;
   gluBuild2DMipmaps(GL_TEXTURE_2D, pImage->channels, pImage->sizeX,
      pImage->sizeY, textureType, GL_UNSIGNED_BYTE, pImage->data);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   if (pImage){
      if (pImage->data)   free(pImage->data);      
      free(pImage);
   }
   return true;
}


With the texture file included, it works fine (resolution of that file is 300x300)
But when i try to use a texture file, it works like that:
http://img225.imageshack.us/img225/9279/textureps2.jpg

(the cube behind is the texture file included, the texture on the front is my texture (downloaded from NeHe, about blending)). You see that my texture (128x128) has vertical lines on it. I made its resolution 300x300 and it was still the same. How can i solve this problem?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.