Пример #1
0
bool Image::load(File* file)
{
  initTable();

  _width = 0;
  _height = 0;
  _bits = NULL;
  _flags = 0xFFFFFF;

  if (file)
  {
    bool loaded = false;
    file->seek(0, SEEK_SET); if (!loaded) loaded = loadGIF(file);
    file->seek(0, SEEK_SET); if (!loaded) loaded = loadPNG(file);
    file->seek(0, SEEK_SET); if (!loaded) loaded = loadTGA(file);
    file->seek(0, SEEK_SET); if (!loaded) loaded = loadBIN(file);
    file->seek(0, SEEK_SET); if (!loaded) loaded = loadBLP(file);
    file->seek(0, SEEK_SET); if (!loaded) loaded = loadBLP2(file);
    if (!loaded)
    {
      delete[] _bits;
      _bits = NULL;
      _width = 0;
      _height = 0;
      _flags = 0;
    }
    else
      updateAlpha();
    return loaded;
  }
  return false;
}
Пример #2
0
FFont * newFFont(char * loc)
{
	//Creates a new font
	
	FFont * temp = (FFont *) c_malloc(sizeof(FFont));

	int w, h, size, x, y;
	short bpp = 0;
	char * data;
	Tex * letter;
	temp->nLetters = 0;

	data = loadTGA(loc, &w, &h, &bpp);
	size = w / 16;
	/* Loading the data from our font image						(deylen - 14/05/2009)*/

	for (y=0; y < 16; y++)
		for (x=0; x < 16; x++){
			letter = newLetter(data, x, 15 - y, size, bpp, w);
			temp->letters = (Tex **) listAdd((void **) temp->letters, size_tex_p, letter, &temp->nLetters);
		}
	/* Running through the image and creating each letter					(deylen - 14/05/2009)*/

	temp->size = size / 16.0;
	free(data);

	return temp;
}
Пример #3
0
bool Texture::load(FS::IFile& file)
{
	PROFILE_FUNCTION();

	const char* path = getPath().c_str();
	size_t len = getPath().length();
	bool loaded = false;
	if (len > 3 && compareString(path + len - 4, ".dds") == 0)
	{
		loaded = loadDDS(file);
	}
	else if (len > 3 && compareString(path + len - 4, ".raw") == 0)
	{
		loaded = loadRaw(file);
	}
	else
	{
		loaded = loadTGA(file);
	}
	if (!loaded)
	{
		g_log_warning.log("Renderer") << "Error loading texture " << path;
		return false;
	}

	m_size = file.size();
	return true;
}
Пример #4
0
void init()
{
	glewInit();
	if (glewIsSupported("GL_VERSION_2_0"))
		printf("Ready for OpenGL 2.0\n");
	else {
		printf("OpenGL 2.0 not supported\n");
		exit(1);
	}

	if (!loadTGA ("color_map_512.tga", color_map))
		printf ("color_map_512.tga not found!\n");
	if (!loadTGA ("normal_map_512.tga", normal_map))
		printf ("normal_map_512.tga not found!\n");

	setShaders();
}
Пример #5
0
/*
=============
glInit
=============

Sets up some OpenGL states and loads image.   

*/
void glInit (void)
{
    glEnable (GL_DEPTH_TEST);
    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);

    if (!loadTGA ("texture1.tga", 13))
        printf ("texture1.tga not found!\n");
}
Пример #6
0
void MaterialData::initEMI(Common::SeekableReadStream *data) {
    Common::Array<Common::String> texFileNames;
    char readFileName[64];

    if (_fname.hasSuffix(".sur")) {  // This expects that we want all the materials in the sur-file
        TextSplitter *ts = new TextSplitter(data);
        ts->setLineNumber(2); // Skip copyright-line
        ts->expectString("version\t1.0");
        if (ts->checkString("name:"))
            ts->scanString("name:%s", 1, readFileName);

        while(!ts->checkString("END_OF_SECTION")) {
            ts->scanString("tex:%s", 1, readFileName);
            Common::String mFileName(readFileName);
            texFileNames.push_back(mFileName);
        }
        Common::SeekableReadStream *texData;
        _textures = new Texture[texFileNames.size()];
        for (uint i = 0; i < texFileNames.size(); i++) {
            warning("SUR-file texture: %s", texFileNames[i].c_str());
            texData = g_resourceloader->openNewStreamFile(texFileNames[i].c_str(), true);
            if (!texData) {
                warning("Couldn't find tex-file: %s", texFileNames[i].c_str());
                _textures[i]._width = 0;
                _textures[i]._height = 0;
                _textures[i]._texture = new int(1); // HACK to avoid initializing.
                continue;
            }
            loadTGA(texData, _textures + i);
            delete texData;
        }
        _numImages = texFileNames.size();
        delete ts;
        return;
    } else if(_fname.hasSuffix(".tga")) {
        _numImages = 1;
        _textures = new Texture();
        loadTGA(data, _textures);
        //	texFileNames.push_back(filename);
        return;

    } else {
        warning("Unknown material-format: %s", _fname.c_str());
    }
}
Пример #7
0
bool Texture::load(const char* filename, bool mipmaps)
{
	std::string str = filename;
	std::string ext = str.substr( str.size() - 4,4 );

	if (ext == ".tga" || ext == ".TGA")
	{
		TGAInfo* tgainfo = loadTGA(filename);
		if (tgainfo == NULL)
			return false;

		this->filename = filename;

		//How to store a texture in VRAM
		glGenTextures(1, &texture_id); //we need to create an unique ID for the texture
		glBindTexture(GL_TEXTURE_2D, texture_id);	//we activate this id to tell opengl we are going to use this texture

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	//set the min filter
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,mipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST ); //set the mag filter
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4);

		if(!mipmaps) //no mipmaps
		{
			glTexImage2D(GL_TEXTURE_2D, 0, ( tgainfo->bpp == 24 ? 3 : 4), tgainfo->width, tgainfo->height, 0, ( tgainfo->bpp == 24 ? GL_BGR : GL_BGRA), GL_UNSIGNED_BYTE, tgainfo->data); //upload without mipmaps
		}
		else
		{
			if (glGenerateMipmapEXT) //extension of GL3.0 (I guess faster)
			{
				glTexImage2D(GL_TEXTURE_2D, 0, ( tgainfo->bpp == 24 ? 3 : 4), tgainfo->width, tgainfo->height, 0, ( tgainfo->bpp == 24 ? GL_BGR : GL_BGRA), GL_UNSIGNED_BYTE, tgainfo->data); //upload without mipmaps
				this->generateMipmaps(); //glGenerateMipmapEXT(GL_TEXTURE_2D);
			}
			else //use old way
			{
				#ifdef GL_VERSION_1_4
					glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
					glTexImage2D(GL_TEXTURE_2D, 0, ( tgainfo->bpp == 24 ? 3 : 4), tgainfo->width, tgainfo->height, 0, ( tgainfo->bpp == 24 ? GL_BGR : GL_BGRA), GL_UNSIGNED_BYTE, tgainfo->data); //upload without mipmaps
					glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE );
				#else
					//the wrong and slow way
					gluBuild2DMipmaps(GL_TEXTURE_2D, ( tgainfo->bpp == 24 ? 3 : 4), tgainfo->width, tgainfo->height, ( tgainfo->bpp == 24 ? GL_BGR : GL_BGRA) , GL_UNSIGNED_BYTE, tgainfo->data); //upload the texture and create their mipmaps
				#endif
			}
		}

		width = tgainfo->width;
		height = tgainfo->height;

		delete tgainfo->data;
		delete tgainfo;
		return true;
	}
	return false;
}
Пример #8
0
GLuint loadGLTex(char * loc, int *x, int *y, short * bpp)
{
	/* Load the texture data from file 					(deylen - 14/5/2009)*/
	char * data;

	if (!strstr(loc, ".tga"))
		fatal("Sorry only TGA image format is supported at the moment");

	data = loadTGA(loc, x, y, bpp);
	return makeGLTex(data, *x, *y, *bpp);
}
Пример #9
0
Bitmap::Bitmap(EFileFormat format, Stream *stream) : m_data(NULL) {
	if (format == EPNG)
		loadPNG(stream);
	else if (format == EJPEG)
		loadJPEG(stream);
	else if (format == EEXR)
		loadEXR(stream);
	else if (format == ETGA)
		loadTGA(stream);
	else if (format == EBMP)
		loadBMP(stream);
	else
		Log(EError, "Bitmap: Invalid file format!");
}
Пример #10
0
bool Texture::load(const std::string& file)
{
  ASSERT(!imageData);

  if(file.length() >= 4)
  {
    std::string suffix = file.substr(file.length() - 4);
    if(strcasecmp(suffix.c_str(), ".bmp") == 0)
      return loadBMP(file);
    if(strcasecmp(suffix.c_str(), ".tga") == 0)
      return loadTGA(file);
  }
  return false;
}
Пример #11
0
void InitFonts()
{
	ftex = loadTGA(arialtga, false);

	f16 = new Font(ftex, 256, 256, 16, arialinfo);
	f24 = new Font(ftex, 256, 256, 24, arialinfo);
	f32 = new Font(ftex, 256, 256, 32, arialinfo);

	morpheus.InitMPQ(morpheusttf, 40);
	arialn13.InitMPQ(arialnttf, 13);
	
	arial12.Init(arialttf, 12);
	arial14.Init(arialttf, 14);
	arial16.Init(arialttf, 16);
}
Пример #12
0
void glInit (void)

{

  glEnable (GL_DEPTH_TEST);

  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);



  loadTGA ("texture.tga", 13);



}
Пример #13
0
/*
 * Load and activate a 2D texture from a TGA file
 */
void createTexture(Texture *texture, char *filename) {
    loadTGA(texture, filename);
	glEnable(GL_TEXTURE_2D); // Required for glBuildMipmap() to work (!)
	glGenTextures(1, &(texture->texID));     // Create The texture ID
    glBindTexture ( GL_TEXTURE_2D , texture->texID );
    // Set parameters to determine how the texture is resized
    glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR_MIPMAP_LINEAR );
    glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR );
    // Set parameters to determine how the texture wraps at edges
    glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_REPEAT );
    glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_REPEAT );
    // Read the texture data from file and upload it to the GPU
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0,
		texture->type, GL_UNSIGNED_BYTE, texture->imageData);
	glGenerateMipmap(GL_TEXTURE_2D);
}
Пример #14
0
RawImage::RawImage(const char *path) throw(ImageException) :
  _type(GL_RGB),
  _texId(0),
  _bytesPerPixel(0),
  _width(0),
  _height(0),
  _pixels(NULL)
{
  const char *filename = basename(const_cast<char *>(path));
  if (filename == NULL)
    throw ImageException("Invalid image filename: %s does not name a file.", filename);

  const char *ext = strrchr(filename, '.');
  if (ext == NULL)
    throw ImageException("Unknown image format.");

  FILE *file = fopen(path, "rb");
  if (file == NULL)
    throw ImageException("File not found: %s.", filename);

  try {
    if (strcasecmp(ext, ".bmp") == 0) {
      loadBMP(file);
    } else if (strcasecmp(ext, ".tga") == 0) {
      loadTGA(file);
    } else if (strcasecmp(ext, ".ppm") == 0) {
      loadPPM(file);
    } else if (strcasecmp(ext, ".jpg") == 0 || strcasecmp(ext, ".jpeg") == 0) {
      loadJPG(file);
    } else if (strcasecmp(ext, ".png") == 0) {
      loadPNG(file);
    } else if (strcasecmp(ext, ".tif") == 0 || strcasecmp(ext, ".tiff") == 0) {
      loadTIFF(path);
    } else {
      throw ImageException("Unknown image format: %s", ext);
    }
    fclose(file);
  } catch (ImageException& ex) {
    fclose(file);
    if (_pixels != NULL)
      delete _pixels;
    throw ex;
  }
}
Пример #15
0
/// \param filename Specifies the name of the file.
/// \param returnErrMsg Must point to a valid character buffer to be filled
///     with an error message in the event of failure.
/// \return true iff successful, else false.
/// \warning This function is currently unsafe, as there is no guarantee that
///     the given error message buffer will be large enough to accomodate the
///     error message.  Recommend changing to use string instead.
bool	Bitmap::load(const char *filename, char *returnErrMsg,size_t errMsgSize) {

	// Free up anything already allocated

	freeMemory();

	// Fetch extension.  I wish I could use the _splitpath function,
	// but it's not cross-platform.  I'll parse the thing myself.

	const char *ext = strchr(filename, '.');
	if (ext == NULL) {
		//SECURITY-UPDATE:2/4/07
		//strcpy(returnErrMsg, "Filename has no extension");
		strcpy_s(returnErrMsg,errMsgSize, "Filename has no extension");
		return false;
	}
	for (;;) {
		const char *dot = strchr(ext+1, '.');
		if (dot == NULL) {
			break;
		}
		ext = dot;
	}

	// Check for known extensions

	if (_stricmp(ext, ".tga") == 0) {
		//SECURITY-UPDATE:2/4/07
		//return loadTGA(filename, returnErrMsg);
		return loadTGA(filename, returnErrMsg,errMsgSize);
	}
	if (_stricmp(ext, ".bmp") == 0) {
		//SECURITY-UPDATE:2/4/07
		//return loadBMP(filename, returnErrMsg);
		return loadBMP(filename, returnErrMsg,errMsgSize);
	}

	// Unknown extension
	//SECURITY-UPDATE:2/4/07
	//sprintf(returnErrMsg, "Unknown/unsupported file extension '%s'", ext);
	sprintf_s(returnErrMsg,errMsgSize, "Unknown/unsupported file extension '%s'", ext);
	return false;
}
int TextureManager::init(char *errorString)
{
	// Free everything if there was something before.
	releaseAll();

	int retVal = initializeDefaultSensor(errorString);
	if (retVal != 0) return retVal;

	// create small and large rendertarget texture
	createRenderTargetTexture(errorString, X_OFFSCREEN, Y_OFFSCREEN, TM_OFFSCREEN_NAME);
	createRenderTargetTexture(errorString, X_HIGHLIGHT, Y_HIGHLIGHT, TM_HIGHLIGHT_NAME);
	createNoiseTexture(errorString, TM_NOISE_NAME);
	createNoiseTexture3D(errorString, TM_NOISE3D_NAME);

	// Create texture for depth sensor (kinect)
	CreateSensorTexture(errorString, TM_DEPTH_SENSOR_NAME);

	// Go throught the textures directory and load all textures.
	HANDLE hFind = INVALID_HANDLE_VALUE;
	WIN32_FIND_DATA ffd;

	// Go to first file in textures directory
	char *dirname = TM_DIRECTORY TM_SHADER_WILDCARD;
	hFind = FindFirstFile(TM_DIRECTORY TM_SHADER_WILDCARD, &ffd);
	if (hFind == INVALID_HANDLE_VALUE)
	{
		sprintf_s(errorString, MAX_ERROR_LENGTH,
				  "IO Error\nThere are no textures in " TM_DIRECTORY);
		return -1;
	}

	// Load all the textures in the directory
	do
	{		
		// Note that the number of textures is increased automatically
		int retVal = loadTGA(ffd.cFileName, errorString);
		if (retVal) return retVal;
	} while (FindNextFile(hFind, &ffd));

	return 0;
}
Пример #17
0
void Texture::loaded(FS::IFile& file, bool success, FS::FileSystem& fs)
{
	PROFILE_FUNCTION();
	if (success)
	{
		const char* path = m_path.c_str();
		size_t len = m_path.length();
		bool loaded = false;
		if (len > 3 && strcmp(path + len - 4, ".dds") == 0)
		{
			loaded = loadDDS(file);
		}
		else if (len > 3 && strcmp(path + len - 4, ".raw") == 0)
		{
			loaded = loadRaw(file);
		}
		else
		{
			loaded = loadTGA(file);
		}
		if (!loaded)
		{
			g_log_warning.log("renderer") << "Error loading texture "
										  << m_path.c_str();
			onFailure();
		}
		else
		{
			m_size = file.size();
			decrementDepCount();
		}
	}
	else
	{
		g_log_warning.log("renderer") << "Error loading texture "
									  << m_path.c_str();
		onFailure();
	}
}
Пример #18
0
bool Texture::load(const std::string& file)
{
  ASSERT(!imageData);
  glGenTextures(1, &textureId);

  if(file.length() >= 4)
  {
    std::string suffix = file.substr(file.length() - 4);
    if(strcasecmp(suffix.c_str(), ".tga") == 0)
      return loadTGA(file);
  }

  QImage image;
  if(image.load(file.c_str()))
  {
    if(image.format() != QImage::Format_ARGB32 &&
       image.format() != QImage::Format_RGB32 &&
       image.format() != QImage::Format_RGB888)
      return false;
    width = image.width();
    height = image.height();
    byteOrder = image.format() == QImage::Format_RGB888 ? GL_BGR : GL_BGRA;
    hasAlpha = image.hasAlphaChannel();
    imageData = new GLubyte[image.byteCount()];
    if(!imageData)
      return false;

    GLubyte* p = imageData;
    for(int y = height; y-- > 0;)
    {
      memcpy(p, image.scanLine(y), image.bytesPerLine());
      p += image.bytesPerLine();
    }

    return true;
  }
  else
    return false;
}
Пример #19
0
void BitmapData::load() {
	if (_loaded) {
		return;
	}
	Common::SeekableReadStream *data = g_resourceloader->openNewStreamFile(_fname.c_str());

	uint32 tag = data->readUint32BE();
	switch(tag) {
		case(MKTAG('B','M',' ',' ')):				//Grim bitmap
			loadGrimBm(data);
			break;
		case(MKTAG('T','I','L','0')):				// MI4 bitmap
			loadTile(data);
			break;
		default:
			if (!loadTGA(data))	// Try to load as TGA.
				Debug::error(Debug::Bitmaps, "Invalid magic loading bitmap");
			break;
	}
	delete data;
	_loaded = true;
}
Пример #20
0
bool Image::loadSupportedFormat(const char* path_)
{
  const char *verifiedPath = MediaPathManager::lookUpMediaPath(path_);
  
  if (!verifiedPath)
    return false;
    
  path = verifiedPath;
  
  if (isPNG(verifiedPath))
    return loadPNG(verifiedPath, this);
    
  if (isJPEG(verifiedPath))
    return loadJPG(verifiedPath);
    
  if (isTGA(verifiedPath))
    return loadTGA(verifiedPath);
    
  if (isDDS(verifiedPath))
    return loadDDS(verifiedPath);
    
  return false;
}
Пример #21
0
bool Surface::loadImage(Common::SeekableReadStream &stream, ImageType type) {
	if (type == kImageTypeNone)
		return false;

	switch (type) {
	case kImageTypeTGA:
		return loadTGA(stream);
	case kImageTypeIFF:
		return loadIFF(stream);
	case kImageTypeBRC:
		return loadBRC(stream);
	case kImageTypeBMP:
		return loadBMP(stream);
	case kImageTypeJPEG:
		return loadJPEG(stream);

	default:
		warning("Surface::loadImage(): Unknown image type: %d", (int) type);
		return false;
	}

	return false;
}
Пример #22
0
int loadGame(gameLevel *gl,int draw)
{int ret=0;
  
    int i;
    
    scene *sc;
    
        switch (gl->stateGame) 
        {
        
                
            case 0:
            
                loadTGA(gl->fileBackground,&gl->background); 
                   
                gl->stateGame++;
                setWipe(&gl->transiction,FADEOUT);
                
                break;
                
          
            case 1: loadingGame(gl); 
                    if(gl->transiction.type==IDLE)
                    {
                        if(initActorsOpen(gl))
                            gl->stateGame++;
                    }
                break;
                
            case 2:
                loadingGame(gl);
            	for(i=0;i<gl->listSounds->size;i++)
                {
                    SsetMusic(gl->listSounds->nameSounds[i],0);
                }
                
                SstartIDMusic(0,REPEATMUSIC);
                
                sc=gl->sceneLevel;
                
                
                for(i=0;i<sc->sizex*sc->sizey;i++)   // cria cenario randomicamente
                    *(sc->map+i)=myrand() & 31;
                
                
                gl->stateGame++;
                setWipe(&gl->transiction,FADEIN);
  
                break;
                
                
            case 3:
                if(gl->transiction.type==IDLE)
                {
              
                    setWipe(&gl->transiction,FADEOUT);
                    gl->stateGame=0;
                    ret=1;
                }
                break;
            default:
            break;
        }
   
       
    
    return ret;
    
}
Пример #23
0
bool CGLCG::LoadShader(const TCHAR *shaderFile)
{
	CCGShader cgShader;
	TCHAR shaderPath[MAX_PATH];
	TCHAR tempPath[MAX_PATH];
	CGprofile vertexProfile, fragmentProfile;
	GLenum error;

	if(!fboFunctionsLoaded) {
		MessageBox(NULL, TEXT("Your OpenGL graphics driver does not support framebuffer objects.\nYou will not be able to use CG shaders in OpenGL mode."), TEXT("CG Error"),
			MB_OK|MB_ICONEXCLAMATION);
        return false;
    }

	vertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
	fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);

	cgGLDisableProfile(vertexProfile);
	cgGLDisableProfile(fragmentProfile);

	ClearPasses();

	if (shaderFile == NULL || *shaderFile==TEXT('\0'))
		return true;

	lstrcpy(shaderPath, shaderFile);
    ReduceToPath(shaderPath);

	SetCurrentDirectory(shaderPath);
	if(!cgShader.LoadShader(_tToChar(shaderFile)))
		return false;

	cgGLSetOptimalOptions(vertexProfile);
	cgGLSetOptimalOptions(fragmentProfile);

	/* insert dummy pass that will contain the original texture
	*/
	shaderPasses.push_back(shaderPass());

	for(CCGShader::passVector::iterator it=cgShader.shaderPasses.begin();
			it!=cgShader.shaderPasses.end();it++) {
		shaderPass pass;

		pass.scaleParams = it->scaleParams;
		/* if this is the last pass (the only one that can have CG_SCALE_NONE)
		   and no filter has been set use the GUI setting
		*/
		if(pass.scaleParams.scaleTypeX==CG_SCALE_NONE && !it->filterSet) {
			pass.linearFilter = GUI.BilinearFilter;
		} else {
			pass.linearFilter = it->linearFilter;
		}

        pass.frameCounterMod = it->frameCounterMod;

        pass.floatFbo = it->floatFbo;

		// paths in the meta file can be relative
		_tfullpath(tempPath,_tFromChar(it->cgShaderFile),MAX_PATH);
		char *fileContents = ReadShaderFileContents(tempPath);
		if(!fileContents)
			return false;

        // individual shader might include files, these should be relative to shader
        ReduceToPath(tempPath);
        SetCurrentDirectory(tempPath);

		pass.cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
						vertexProfile, "main_vertex", NULL);

		checkForCgError("Compiling vertex program");

		pass.cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
							fragmentProfile, "main_fragment", NULL);

		checkForCgError("Compiling fragment program");

        // set path back for next pass
        SetCurrentDirectory(shaderPath);

		delete [] fileContents;
		if(!pass.cgVertexProgram || !pass.cgFragmentProgram) {
			return false;
		}
		cgGLLoadProgram(pass.cgVertexProgram);
		cgGLLoadProgram(pass.cgFragmentProgram);

		/* generate framebuffer and texture for this pass and apply
		   default texture settings
		*/
		glGenFramebuffers(1,&pass.fbo);
		glGenTextures(1,&pass.tex);
		glBindTexture(GL_TEXTURE_2D,pass.tex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

		shaderPasses.push_back(pass);
	}

	for(std::vector<CCGShader::lookupTexture>::iterator it=cgShader.lookupTextures.begin();it!=cgShader.lookupTextures.end();it++) {		
		lookupTexture tex;
		strcpy(tex.id,it->id);

		/* generate texture for the lut and apply specified filter setting
		*/
		glGenTextures(1,&tex.tex);
		glBindTexture(GL_TEXTURE_2D,tex.tex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, it->linearfilter?GL_LINEAR:GL_NEAREST);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, it->linearfilter?GL_LINEAR:GL_NEAREST);

		_tfullpath(tempPath,_tFromChar(it->texturePath),MAX_PATH);

		// simple file extension png/tga decision
		int strLen = strlen(it->texturePath);
		if(strLen>4) {
			if(!strcasecmp(&it->texturePath[strLen-4],".png")) {
				int width, height;
				bool hasAlpha;
				GLubyte *texData;
				if(loadPngImage(tempPath,width,height,hasAlpha,&texData)) {
					glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
					glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width,
						height, 0, hasAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, texData);
					free(texData);
				}
			} else if(!strcasecmp(&it->texturePath[strLen-4],".tga")) {
				STGA stga;
				if(loadTGA(tempPath,stga)) {
					glPixelStorei(GL_UNPACK_ROW_LENGTH, stga.width);
					glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, stga.width,
						stga.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, stga.data);
				}
			}
		}
		lookupTextures.push_back(tex);
	}

	/* enable texture unit 1 for the lookup textures
	*/
	glClientActiveTexture(GL_TEXTURE1);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2,GL_FLOAT,0,lut_coords);
	glClientActiveTexture(GL_TEXTURE0);

	/* generate textures and set default values for the pref-filled PREV deque.
	*/
	for(int i=0;i<prevPasses.size();i++) {
		glGenTextures(1,&prevPasses[i].tex);
		glBindTexture(GL_TEXTURE_2D,prevPasses[i].tex);
		glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,NULL);
		glBindTexture(GL_TEXTURE_2D,0);
		prevPasses[i].textureSize.x = prevPasses[i].textureSize.y = prevPasses[i].textureSize.x = prevPasses[i].textureSize.y = 0;
		memset(prevPasses[i].texCoords,0,sizeof(prevPasses[i].texCoords));
	}

	shaderLoaded = true;
	
	return true;
}
	bool			CubeMap::load(std::string const &path)
	{
		glActiveTexture(GL_TEXTURE0);
		glGenTextures(1, &_id);
		glBindTexture(GL_TEXTURE_CUBE_MAP, _id);
		const char *suffixes[] = {"posx", "negx", "negy", "posy", "posz", "negz"};
		GLuint targets[] = {
			GL_TEXTURE_CUBE_MAP_POSITIVE_X,
			GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
			GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
			GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
			GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
			GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
		};

		for (unsigned int i = 0; i < 6; ++i)
		{
			File file(path + "/" + suffixes[i] + ".tga");
			if (!file.exists())
				return false; // TODO -> erase texture
			GLbyte *datas;
			GLint width, height;
			GLint components;
			GLenum format;
			if ((datas = loadTGA(file.getFullName().c_str(), &width, &height, &components, &format)) == NULL)
				return false; // TODO -> erase texture
			glTexImage2D(targets[i], 0, components, width, height, 0, format, GL_UNSIGNED_BYTE, datas);
		}

		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);


		// build cube
		float points[] = {
			-10.0f,  10.0f, -10.0f,
			-10.0f, -10.0f, -10.0f,
			10.0f, -10.0f, -10.0f,
			10.0f, -10.0f, -10.0f,
			10.0f,  10.0f, -10.0f,
			-10.0f,  10.0f, -10.0f,
			
			-10.0f, -10.0f,  10.0f,
			-10.0f, -10.0f, -10.0f,
			-10.0f,  10.0f, -10.0f,
			-10.0f,  10.0f, -10.0f,
			-10.0f,  10.0f,  10.0f,
			-10.0f, -10.0f,  10.0f,
			
			10.0f, -10.0f, -10.0f,
			10.0f, -10.0f,  10.0f,
			10.0f,  10.0f,  10.0f,
			10.0f,  10.0f,  10.0f,
			10.0f,  10.0f, -10.0f,
			10.0f, -10.0f, -10.0f,
			
			-10.0f, -10.0f,  10.0f,
			-10.0f,  10.0f,  10.0f,
			10.0f,  10.0f,  10.0f,
			10.0f,  10.0f,  10.0f,
			10.0f, -10.0f,  10.0f,
			-10.0f, -10.0f,  10.0f,
			
			-10.0f,  10.0f, -10.0f,
			10.0f,  10.0f, -10.0f,
			10.0f,  10.0f,  10.0f,
			10.0f,  10.0f,  10.0f,
			-10.0f,  10.0f,  10.0f,
			-10.0f,  10.0f, -10.0f,
			
			-10.0f, -10.0f, -10.0f,
			-10.0f, -10.0f,  10.0f,
			10.0f, -10.0f, -10.0f,
			10.0f, -10.0f, -10.0f,
			-10.0f, -10.0f,  10.0f,
			10.0f, -10.0f,  10.0f
		};

		glGenBuffers (1, &_vbo);
		glBindBuffer (GL_ARRAY_BUFFER, _vbo);
		glBufferData (GL_ARRAY_BUFFER, 3 * 36 * sizeof (float), &points, GL_STATIC_DRAW);
		
		glGenVertexArrays (1, &_vao);
		glBindVertexArray (_vao);
		glEnableVertexAttribArray (0);
		glBindBuffer (GL_ARRAY_BUFFER, _vbo);
		glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);
		return true;
	}