Пример #1
0
int OBJ::readTexture(string filename,int i) {
	texture[i] = new GLuint ;
	TGAImg img;
	glActiveTexture(GL_TEXTURE0);
	
	if (img.Load((char*)filename.c_str())==IMG_OK) {
		glGenTextures(1,texture[i]); //Zainicjuj uchwyt tex
		glBindTexture(GL_TEXTURE_2D,*texture[i]); //Przetwarzaj uchwyt tex
		if (img.GetBPP()==24) //Obrazek 24bit
			glTexImage2D(GL_TEXTURE_2D,0,3,img.GetWidth(),img.GetHeight(),0,
				GL_RGB,GL_UNSIGNED_BYTE,img.GetImg());
		else if (img.GetBPP()==32) //Obrazek 32bit
			glTexImage2D(GL_TEXTURE_2D,0,4,img.GetWidth(),img.GetHeight(),0,
				GL_RGBA,GL_UNSIGNED_BYTE,img.GetImg());      
		else {
			printf("Nieobs³ugiwany format obrazka w pliku: %s \n",filename.c_str());
		}
	} else {
		printf("B³¹d przy wczytywaniu pliku: %s\n",filename.c_str());
	}
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);	
	
	return 0;
}
Пример #2
0
GLuint readTexture(char* filename) {
	GLuint tex;
	TGAImg img;
	glActiveTexture(GL_TEXTURE0);
	if (img.Load(filename)==IMG_OK) {
		glGenTextures(1,&tex); //Zainicjuj uchwyt tex
		glBindTexture(GL_TEXTURE_2D,tex); //Przetwarzaj uchwyt tex
		if (img.GetBPP()==24) //Obrazek 24bit
			glTexImage2D(GL_TEXTURE_2D,0,3,img.GetWidth(),img.GetHeight(),0,
			GL_RGB,GL_UNSIGNED_BYTE,img.GetImg());
		else if (img.GetBPP()==32) //Obrazek 32bit
			glTexImage2D(GL_TEXTURE_2D,0,4,img.GetWidth(),img.GetHeight(),0,
			GL_RGBA,GL_UNSIGNED_BYTE,img.GetImg());
		else {
			printf("Nieobsługiwany format obrazka w pliku: %s \n",filename);
		}
	} else {
		printf("Błąd przy wczytywaniu pliku: %s\n",filename);
	}
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
	return tex;
}
Пример #3
0
GLuint TextureLoader::LoadTexture(char *TexName) {
        TGAImg Img;        // Image loader
        GLuint Texture;
        
        // Load our Texture
        if(Img.Load(TexName)!=IMG_OK)
            return -1;
        
        glGenTextures(1,&Texture);            // Allocate space for texture
        glBindTexture(GL_TEXTURE_2D,Texture); // Set our Tex handle as current
        
        // Create the texture
        if(Img.GetBPP()==24)
            glTexImage2D(GL_TEXTURE_2D,0,3,Img.GetWidth(),Img.GetHeight(),0,
                         GL_RGB,GL_UNSIGNED_BYTE,Img.GetImg());
        else if(Img.GetBPP()==32)
            glTexImage2D(GL_TEXTURE_2D,0,4,Img.GetWidth(),Img.GetHeight(),0,
                         GL_RGBA,GL_UNSIGNED_BYTE,Img.GetImg());
        else
            return -1;
        
        // Specify filtering and edge actions
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
        
        return Texture;
}
Пример #4
0
bool
loadImageTGA(string fileName, agg::int8u** oData, int* oWidth, int* oHeight)
{
  TGAImg tgaImage = TGAImg();

  int result = tgaImage.Load(fileName.c_str());
  if(result != IMG_OK) {
    ostringstream ossError;
    ossError << "TGA loader: Error: ";
    if(IMG_ERR_NO_FILE == result)
      ossError << "No file (IMG_ERR_NO_FILE)";
    else if(IMG_ERR_MEM_FAIL == result)
      ossError << "Memory failure (IMG_ERR_MEM_FAIL)";
    else if(IMG_ERR_BAD_FORMAT == result)
      ossError << "Bad format (IMG_ERR_BAD_FORMAT)";
    else if(IMG_ERR_UNSUPPORTED == result)
      ossError << "Unsupported image type (IMG_ERR_UNSUPPORTED)";
    logEngineError(ossError.str());
    return false;
  }

  if(tgaImage.GetBPP() != 32) {
    ostringstream ossError;
    ossError << "TGA loader: 32bit support only. " << tgaImage.GetBPP() << "bit not supported.";
    logEngineError(ossError.str());
    return false;
  }
  if(tgaImage.GetWidth() != *oWidth || tgaImage.GetHeight() != *oHeight) {
    if(NULL != *oData) delete[] *oData;
    *oWidth = 0;
    *oHeight = 0;  

    *oData = new agg::int8u[tgaImage.GetWidth() * tgaImage.GetHeight() * 4];
  }
  
  *oWidth = tgaImage.GetWidth();
  *oHeight = tgaImage.GetHeight();  

  agg::int8u* srcData = tgaImage.GetImg();
  agg::int8u* dstData = *oData;
  int pixelCount = (*oWidth) * (*oHeight);
  for(int iPixel = 0; iPixel < pixelCount; ++iPixel) {
    int8u r = *srcData++;
    int8u g = *srcData++;
    int8u b = *srcData++;
    int8u a = *srcData++;
    *dstData++ = b;
    *dstData++ = g;
    *dstData++ = r;
    *dstData++ = a;
  }

  return true;
}
Пример #5
0
void Mesh::setTexture(std::string name)///COPYPASTA ! %-D
{
	TGAImg img; 
	if(img.Load((char *) name.c_str())==IMG_OK) 
	{
		mMaterial.setTextureName(name);
		mTextured = true;
		glGenTextures(1,&mTexture);
		glBindTexture(GL_TEXTURE_2D,mTexture);
		if(img.GetBPP()==24)
			glTexImage2D(GL_TEXTURE_2D,0,3,img.GetWidth(),img.GetHeight(),0,GL_RGB,GL_UNSIGNED_BYTE,img.GetImg());
		else if(img.GetBPP()==32)
			glTexImage2D(GL_TEXTURE_2D,0,4,img.GetWidth(),img.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,img.GetImg());
		else
		{
			mTextured = false;
			printf("[Warning]Texture (\"%s\") is in unsupported format.\n",name.c_str());
		}
	}
	else
	{
		printf("[Warning]Texture (\"%s\") cannot be loaded (file loading error).\n",name.c_str());
	}
}