Exemple #1
0
int LoadGLTextures()                                    // Load Bitmaps And Convert To Textures
{
    int Status=FALSE;									// Status Indicator
    AUX_RGBImageRec *TextureImage[3];					// Create Storage Space For The Textures
    memset(TextureImage,0,sizeof(void *)*3);			// Set The Pointer To NULL
    if ((TextureImage[0]=LoadBMP("Data/EnvWall.bmp")) &&// Load The Floor Texture
        (TextureImage[1]=LoadBMP("Data/Ball.bmp")) &&	// Load the Light Texture
        (TextureImage[2]=LoadBMP("Data/EnvRoll.bmp")))	// Load the Wall Texture
	{   
		Status=TRUE;									// Set The Status To TRUE
		glGenTextures(3, &texture[0]);					// Create The Texture
		for (int loop=0; loop<3; loop++)				// Loop Through 5 Textures
		{
			glBindTexture(GL_TEXTURE_2D, texture[loop]);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		}
		for (loop=0; loop<3; loop++)					// Loop Through 5 Textures
		{
			if (TextureImage[loop])						// If Texture Exists
			{
				if (TextureImage[loop]->data)			// If Texture Image Exists
				{
					free(TextureImage[loop]->data);		// Free The Texture Image Memory
				}
				free(TextureImage[loop]);				// Free The Image Structure 
			}
		}
	}
	return Status;										// Return The Status
}
Exemple #2
0
void chargerTextures()
{	
    SImage* Image = NULL;

    if( Image = LoadBMP("textures/stonewalldiffuse.bmp" ) )
    {
        glGenTextures( 1, &Variable::texture0 );
        init2DTexture(Variable::texture0, Image->width, Image->height, Image->data );
        delete Image;
    }

    if( Image = LoadBMP( "textures/rust.bmp" ) )
    {
        glGenTextures( 1, &Variable::texture1 );
        init2DTexture(Variable::texture1, Image->width, Image->height, Image->data );
        delete Image;
    }

    if( Image = LoadBMP( "textures/3dlabs.bmp" ) )
    {
        glGenTextures( 1, &Variable::texture2 );
        init2DTexture(Variable::texture2, Image->width, Image->height, Image->data );
        delete Image;
    }
}
Exemple #3
0
int LoadGLTextures()										// Load Bitmaps And Convert To Textures
{
        int Status=FALSE;									// Status Indicator
        AUX_RGBImageRec *TextureImage[2];					// Create Storage Space For The Textures
        memset(TextureImage,0,sizeof(void *)*2);			// Set The Pointer To NULL

        if ((TextureImage[0]=LoadBMP("Data/Font.bmp")) &&	// Load The Font
			(TextureImage[1]=LoadBMP("Data/Image.bmp")))	// Load Background Image
        {
			Status=TRUE;									// Set The Status To TRUE

			glGenTextures(2, &texture[0]);					// Create The Texture

			for (loop1=0; loop1<2; loop1++)					// Loop Through 2 Textures
			{
				glBindTexture(GL_TEXTURE_2D, texture[loop1]);
				glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop1]->sizeX, TextureImage[loop1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop1]->data);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			}

			for (loop1=0; loop1<2; loop1++)					// Loop Through 2 Textures
			{
				if (TextureImage[loop1])					// If Texture Exists	
				{
					if (TextureImage[loop1]->data)			// If Texture Image Exists
					{
						free(TextureImage[loop1]->data);	// Free The Texture Image Memory
					}
					free(TextureImage[loop1]);				// Free The Image Structure
				}
			}
		}
	return Status;											// Return The Status
}
int LoadGLTextures()
{
	int Status=FALSE;

	AUX_RGBImageRec *TextureImage[1];

	memset(TextureImage,0,sizeof(void *)*1);

	if (TextureImage[0]=LoadBMP("Data/Font.bmp"))
	{
		Status=TRUE;

		glGenTextures(1, &texture[0]);

		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
	}

	if (TextureImage[0]=LoadBMP("Data/Floor.bmp"))
	{
		Status=TRUE;

		glGenTextures(1, &texture[1]);

		glBindTexture(GL_TEXTURE_2D, texture[1]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
	}

	if (TextureImage[0]=LoadBMP("Data/Smoke.bmp"))
	{
		Status=TRUE;

		glGenTextures(1, &texture[2]);

		glBindTexture(GL_TEXTURE_2D, texture[2]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
	}

	if (TextureImage[0])
	{
		if (TextureImage[0]->data)
		{
			free(TextureImage[0]->data);
		}

		free(TextureImage[0]);
	}

	return Status;
}
static void LoadGLTextures()     //Bitmaps laden und in Texturen umwandeln
{
	myRGBImage *textureImage[NUM_TEXTURES];
	int i;
	for (i = 0; i<NUM_TEXTURES; i++) {
		textureImage[i] = (myRGBImage *)malloc(sizeof(myRGBImage));
		if (textureImage[i] == NULL) {
			printf("Fehler bei der Speicherreservierung fuer die Bilddaten");
			exit(0);
		}
	}
	//memset(textureImage,0,sizeof(void *)*1); //sicherheitshalber den Inhalt loeschen
	if (
		LoadBMP("waldboden.bmp", textureImage[0]) && LoadBMP("himmel.bmp", textureImage[1]) && LoadBMP("baum.bmp", textureImage[2])
		&& LoadBMP("himmel2.bmp", textureImage[3]) && LoadBMP("himmel3.bmp", textureImage[4]) && LoadBMP("himmel4.bmp", textureImage[5]))  {

		for (i = 0; i < NUM_TEXTURES; i++) {
			glGenTextures(1, &texture[i]);  //Textur erzeugen
			// Textur Erstellung mit Daten vom Bitmap
			glBindTexture(GL_TEXTURE_2D, texture[i]);
			glTexImage2D(GL_TEXTURE_2D,            //target (Gibt an, welche Texture erreicht werden soll)
				0,                          //level (Grad der Mipmap-Reduzierung, 0 ist das Basisbild)
				3,                          //components (1 fuer R, 2 fuer R+A, 3 fuer RGB, 4 fuer RGBA)
				textureImage[i]->sizeX,     //width (Bildbreite in Pixeln)
				textureImage[i]->sizeY,     //height (Bildhoehe in Pixeln)
				0,                          //border (Rand: 0 oder 1)
				GL_RGB,                     //format (z.B. GL_COLOR_INDEX, GL_RGBA, GL_LUMINANCE, ...)
				GL_UNSIGNED_BYTE,           //type (Typ der Daten; z.B. GL_BYTE, GL_INT, GL_FLOAT, ...)
				textureImage[i]->data);     //pixels (eigentlichen Bilddaten)
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterMode);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterMode);

			//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
		}
		//Aufraeumen
		for (i = 0; i<NUM_TEXTURES; i++) {
			if (textureImage[i]) {              //falls existiert
				if (textureImage[i]->data) {     //falls Daten existieren
					free(textureImage[i]->data);  //Datenbereich freigeben
				}
				free(textureImage[i]);          //Bitmap-Struktur freigeben
			}
		}
	}
	else{
		textureLoaded = false;		
	}

}
Exemple #6
0
int LoadGLTextures()									// Load Bitmaps And Convert To Textures
{
	int Status=FALSE;									// Status Indicator

	AUX_RGBImageRec *TextureImage[2];					// Create Storage Space For The Texture

	memset(TextureImage,0,sizeof(void *)*2);           	// Set The Pointer To NULL

	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if ((TextureImage[0]=LoadBMP("Data/BG.bmp")) &&
		(TextureImage[1]=LoadBMP("Data/Reflect.bmp")))
	{
		Status=TRUE;									// Set The Status To TRUE

		glGenTextures(6, &texture[0]);					// Create Three Textures (For Two Images)

		for (int loop=0; loop<2; loop++)
		{
		// Create Nearest Filtered Texture
			glBindTexture(GL_TEXTURE_2D, texture[loop]);	// Gen Tex 0 and 1
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);

			// Create Linear Filtered Texture
			glBindTexture(GL_TEXTURE_2D, texture[loop+2]);	// Gen Tex 2 and 3 4
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);

			// Create MipMapped Texture
			glBindTexture(GL_TEXTURE_2D, texture[loop+4]);	// Gen Tex 4 and 5
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
			gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
		}
		for (loop=0; loop<2; loop++)
		{
	        if (TextureImage[loop])							// If Texture Exists
		    {
			        if (TextureImage[loop]->data)			// If Texture Image Exists
				    {
					        free(TextureImage[loop]->data);	// Free The Texture Image Memory
					}
					free(TextureImage[loop]);				// Free The Image Structure
			}
		}
	}

	return Status;										// Return The Status
}
//Inicializar texturas
void InitTexture(){
	//determinação dos ficheiros a carregar que vão servir de texturas
	glEnable(GL_TEXTURE_2D);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glGenTextures(11, texture_id);

	glBindTexture(GL_TEXTURE_2D, texture_id[0]);
	LoadBMP("aquario.bmp", 0);
	glBindTexture(GL_TEXTURE_2D, texture_id[1]);
	LoadBMP("aquariomask.bmp", 1);
	glBindTexture(GL_TEXTURE_2D, texture_id[2]);
	LoadBMP("Clown_fish.bmp", 2);
	glBindTexture(GL_TEXTURE_2D, texture_id[3]);
	LoadBMP("Clown_fishmask.bmp", 3);
}
Exemple #8
0
//Load - load a texture from a file
bool IMAGE::Load(char * filename)
{
	//Clear the data if already used
	if(data)
		delete [] data;
	data=NULL;
	bpp=0;
	width=0;
	height=0;
	format=0;

	int filenameLength=strlen(filename);

	if(	strncmp((filename+filenameLength-3), "BMP", 3)==0 ||
		strncmp((filename+filenameLength-3), "bmp", 3)==0)
		return LoadBMP(filename);
	
	if(	strncmp((filename+filenameLength-3), "PCX", 3)==0 ||
		strncmp((filename+filenameLength-3), "pcx", 3)==0)
		return LoadPCX(filename);
	
	if(	strncmp((filename+filenameLength-3), "TGA", 3)==0 ||
		strncmp((filename+filenameLength-3), "tga", 3)==0)
		return LoadTGA(filename);

	errorLog.OutputError("%s does not end in \".tga\", \".bmp\" or \"pcx\"", filename);
	return false;
}
Exemple #9
0
int LoadGLTextures()									// Load Bitmap And Convert To A Texture
{
        int Status=FALSE;								// Status Indicator
        AUX_RGBImageRec *TextureImage[1];				// Create Storage Space For The Textures
        memset(TextureImage,0,sizeof(void *)*1);		// Set The Pointer To NULL

        if (TextureImage[0]=LoadBMP("Data/Particle.bmp"))	// Load Particle Texture
        {
			Status=TRUE;								// Set The Status To TRUE
			glGenTextures(1, &texture[0]);				// Create One Texture

			glBindTexture(GL_TEXTURE_2D, texture[0]);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
        }

        if (TextureImage[0])							// If Texture Exists
		{
			if (TextureImage[0]->data)					// If Texture Image Exists
			{
				free(TextureImage[0]->data);			// Free The Texture Image Memory
			}
			free(TextureImage[0]);						// Free The Image Structure
		}
        return Status;									// Return The Status
}
int LoadGLTextures()									// Load Bitmaps And Convert To Textures
{
	int Status=FALSE;									// Status Indicator

	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture

	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL

	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
	{
		Status=TRUE;									// Set The Status To TRUE

		glGenTextures(1, &texture[0]);					// Create The Texture

		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	}

	if (TextureImage[0])									// If Texture Exists
	{
		if (TextureImage[0]->data)							// If Texture Image Exists
		{
			free(TextureImage[0]->data);					// Free The Texture Image Memory
		}

		free(TextureImage[0]);								// Free The Image Structure
	}

	return Status;										// Return The Status
}
Exemple #11
0
int LoadGLTextures()
{
	int status = false;

	AUX_RGBImageRec * TextureImage[1];
	memset(TextureImage, 0, sizeof(void*)* 1);

	if (TextureImage[0] = LoadBMP("loc"))
		status = true;
	glGenTextures(1, &texture[0]);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	if (status)
	{
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,
			0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
	}
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// 线形滤波
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// 线形滤波
	
	if (TextureImage[0])
	{
		if (TextureImage[0]->data)
			free(TextureImage[0]->data);
		free(TextureImage[0]);
	}

	return status;
}
Exemple #12
0
int LoadGLTexture()
{
	int Status = FALSE;
	std::string tab[3] = { "pliki/tex.bmp", "pliki/tex2.bmp","pliki/tex3.bmp"};
	AUX_RGBImageRec *TextureImage[3];//rezerwujemy miejsce na teksture
	memset(TextureImage, 0, sizeof(void*) * 1); //ustawiamy na 0
	for (int i = 0; i < 3; i++)
	{
		if (TextureImage[i] = LoadBMP(tab[i]))
		{
			Status = true;
			glGenTextures(3, &texture[i]);
			glBindTexture(GL_TEXTURE_2D, texture[i]);
			gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, TextureImage[i]->sizeX, TextureImage[i]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[i]->data);//przypisawanie teksturze danych obrazowych
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//filtrowanie liniowe
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//filtrowanie liniowe
		}
		if (TextureImage[i])
		{
			if (TextureImage[i]->data)
			{
				free(TextureImage[i]->data);//zwolnij pamiec tekstury obrazu
			}
			free(TextureImage[i]);//zwolnij pamiec struktury obrazu
		}
	}
	return Status;
}
int Create_panel_from_bmp(char* background_filename, char* name, Sint16 x_location, Sint16 y_location, Uint16 picture_width, Uint16 picture_height, control** control_toRet, char** error)
{
	SDL_Surface* Panel_Background;

	if ( -1 ==LoadBMP(background_filename, &Panel_Background, error))
	{
		*control_toRet = NULL;
		return -1;
	}

	SDL_Rect* Panel_Rect = malloc(sizeof(SDL_Rect));
	if (Panel_Rect == NULL) {
		SDL_FreeSurface(Panel_Background);
		Panel_Background = NULL;
		*control_toRet = NULL;
		*error = "ERROR: failed to allocate memory for SDL_Rect";
		return -1;
	}
	Panel_Rect->x = x_location;
	Panel_Rect->y = y_location;
	Panel_Rect->h = picture_height;
	Panel_Rect->w = picture_width;

	if (-1 == CreateControl(Panel_Background, NULL, Panel_Rect, name, NULL, WINDOWTYPE, control_toRet, error))
	{
		SDL_FreeSurface(Panel_Background);
		Panel_Background = NULL;
		free(Panel_Rect);
		Panel_Rect = NULL;
		return -1;
	}
	return 0;
}
void LoadDensityMap( const char* FileName )
{
	std::cout << "Loading density map " << FileName << std::endl;

	int W, H;
	unsigned char* Data = LoadBMP( FileName, &W, &H );

	std::cout << "Loaded ( " << W << " x " << H << " ) " << std::endl;

	if ( W != ImageSize || H != ImageSize )
	{
		std::cout << "ERROR: density map should be " << ImageSize << " x " << ImageSize << std::endl;		

		exit( 255 );
	}

	g_DensityMap = new float[ W * H ];

	for ( int y = 0; y != H; y++ )
	{
		for ( int x = 0; x != W; x++ )
		{
			g_DensityMap[ x + y * W ] = float( Data[ 3 * (x + y * W) ] ) / 255.0f;
		}
	}

	delete[]( Data );
}
Exemple #15
0
void tekstur() {
   int i,size,j;
   char c[64];
   unsigned char t;
   unsigned char *p;
   /* allocate space for texture in graphics card */
   glGenTextures(7,texture);
   for(i=0;i<7;i++) {
      sprintf(c,"t%d.bmp",i+1);
/*      fprintf(debug,"%s\n",c);*/
      img[i]=LoadBMP(c);
      buf[i]=(unsigned char*)malloc(512*512*3);
      memcpy(buf[i],img[i]->pixels,512*512*3);
      p=buf[i];

/*      fprintf(debug,"bits: %d\n",(int)img[i]->format->BytesPerPixel);*/
      size=3*512*512;
      /* reverser */
      for(j=0;j<size/2;j++) {
         t=p[j]; p[j]=p[size-j-1]; p[size-j-1]=t;
      }
      loadtexture(&texture[i],512,512,buf[i]);
   }
   glEnable(GL_TEXTURE_2D);
}
Exemple #16
0
//载入位图文件并创建纹理
bool BMPLoad::Load(const char *filename)
{
	if(!LoadBMP(filename))
	{
		MessageBox(NULL, TEXT("载入位图文件失败"),TEXT("错误"), MB_OK);
		exit(0);
	}
	//生成纹理对象名称
	glGenTextures(1, &ID);
	//创建纹理对象
	glBindTexture(GL_TEXTURE_2D, ID);

	//控制滤波,纹理过滤与环绕,  控制纹理参数 
	/*==============================
	*这里改动会比较多做个记号
	*/
	//==================================
	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_S, GL_REPEAT);

	//创建纹理mip贴图
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, imageWidth, imageHeight, GL_RGB, GL_UNSIGNED_BYTE, image);

	return true;
}
Exemple #17
0
bool Texture::LoadFromBMP( const char* Filename )
{
    unsigned int width, height;
    
    unsigned char* data = LoadBMP(Filename, width, height);
    if(data==NULL)
        return false;
    
    if( m_pImage )
        delete m_pImage;
    
    m_pImage = createImage(data, width, height);
    
    glGenTextures(1, &m_TextureID);
    
    glBindTexture(GL_TEXTURE_2D, m_TextureID);
    glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
    glGenerateMipmap(GL_TEXTURE_2D);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glBindTexture(GL_TEXTURE_2D, 0);
   
    return true;
}
Exemple #18
0
Surface::Surface( const IDataStream& Stream, ESurfaceFileType FileType )
    :	m_Width( 0 )
    ,	m_Height( 0 )
    ,	m_Stride( 0 )
    ,	m_Padding( 0 )
#if BUILD_WINDOWS_NO_SDL
    ,	m_hDC( NULL )
    ,	m_BMP( NULL )
    ,	m_OldBMP( NULL )
#endif
    ,	m_pPixels( NULL )
    ,	m_BitmapInfo()
    ,	m_ViewportLeft( 0 )
    ,	m_ViewportTop( 0 )
    ,	m_ViewportRight( 0 )
    ,	m_ViewportBottom( 0 )
{
    // Load depending on extension
    if( FileType == ESFT_BMP )
    {
        LoadBMP( Stream );
    }
    else if( FileType == ESFT_TGA )
    {
        LoadTGA( Stream );
    }
    else
    {
        WARNDESC( "Unknown file type constructing Surface." );
    }
}
Exemple #19
0
//Load an image from a file
bool IMAGE::Load(char * filename)
{
	//Clear the member variables if already used
	bpp=0;
	width=height=0;
	stride=0;
	format=0;

	if(data)
		delete []  data;
	data=NULL;

	paletted=false;
	paletteBpp=0;
	paletteFormat=0;
	if(palette)
		delete [] palette;
	palette=NULL;

	//Call the correct loading function based on the filename
	int filenameLength=strlen(filename);

	if(	strncmp(filename+filenameLength-3, "BMP", 3)==0 ||
		strncmp(filename+filenameLength-3, "bmp", 3)==0)
		return LoadBMP(filename);

	if(	strncmp(filename+filenameLength-3, "TGA", 3)==0 ||
		strncmp(filename+filenameLength-3, "tga", 3)==0)
		return LoadTGA(filename);

	LOG::Instance()->OutputError("%s does not end with \"bmp\" or \"tga\"", filename);
	return false;
}
Exemple #20
0
int LoadGLTextures() {                                  // Загружаем битмап и преобразуем в текстуру
    int Status = FALSE;                                 // Индикатор состояния

    AUX_RGBImageRec* TextureImage[1];                   // Создаем пространство для хранения текстуры

    memset(TextureImage, 0, sizeof(void*) * 1);         // Устанавливаем указатель в NULL

    // Загружаем изображение, проверяем ошибки, если изображение не найдено, то выходим.
    if (TextureImage[0] = LoadBMP("Data/Cube.bmp")) {
        Status = TRUE;                                  // Устанавливаем состояние в TRUE

        glGenTextures(1, &texture[0]);                  // Создаем текстуру

        // Генерация типичной текстуры с использованием данных из битовых карт (bitmap)
        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    }

    if (TextureImage[0]) {                                  // Если текстура существует
        if (TextureImage[0]->data) {                        // Если текстурное изображение существует
            free(TextureImage[0]->data);                    // Освобождаем память изображения текстуры
        }

        free(TextureImage[0]);                              // Освобождаем структуру изображения
    }

    return Status;                                      // Возвращаем состояние
}
Exemple #21
0
// Inicializa parâmetros de rendering
void Inicializa (void)
{
	// Define a cor de fundo da janela de visualização como preta
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	// Habilita a definição da cor do material a partir da cor corrente
	glEnable(GL_COLOR_MATERIAL);
	//Habilita o uso de iluminação
	glEnable(GL_LIGHTING);
	// Habilita a luz de número 0
	glEnable(GL_LIGHT0);
	// Habilita o depth-buffering
	glEnable(GL_DEPTH_TEST);

	// Inicializa a variável que especifica o ângulo da projeção
	// perspectiva
	angle=50;

	// Inicializa as variáveis usadas para alterar a posição do
	// observador virtual
	rotX = 30;
	rotY = 0;
	obsZ = 10;

	// Comandos de inicialização para textura
	imagemTextura = LoadBMP("imagem.bmp");
	glGenTextures(1, &idTextura);
	glBindTexture(GL_TEXTURE_2D, idTextura);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, imagemTextura->sizeX,
			imagemTextura->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
			imagemTextura->data);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glEnable(GL_TEXTURE_2D);
}
Exemple #22
0
/*!
 * \brief
 * Load image file (8-bit BMP or PNG)
 *
 * \param filename
 * File name with the image
 *
 * \returns
 * Handler to the loaded image or NULL if error
 *
 * \see
 * TLN_DeleteBitmap()
 */
TLN_Bitmap TLN_LoadBitmap (char *filename)
{
    TLN_Bitmap bitmap;

    if (!CheckFile (filename))
    {
        TLN_SetLastError (TLN_ERR_FILE_NOT_FOUND);
        return NULL;
    }

    /* try png, else bmp*/
    bitmap = LoadPNG (filename);
    if (bitmap == NULL)
        bitmap = LoadBMP (filename);

    /* bitmap loaded */
    if (bitmap)
    {
        /* accept only 8 bpp */
        int bpp = TLN_GetBitmapDepth (bitmap);
        if (bpp == 8)
            TLN_SetLastError (TLN_ERR_OK);
        else
        {
            TLN_DeleteBitmap (bitmap);
            bitmap = NULL;
        }
    }

    if (!bitmap)
        TLN_SetLastError (TLN_ERR_WRONG_FORMAT);

    return bitmap;
}
Exemple #23
0
int LoadGLTextures(GLuint  texture[], CHAR *filename)         // 载入位图(调用上面的代码)并转换成纹理
{
	int Status = FALSE;         // 状态指示器
	AUX_RGBImageRec *TextureImage[1];     // 创建纹理的存储空间
	memset(TextureImage, 0, sizeof(void *) * 1);   // 将指针设为 NULL
	// 载入位图,检查有无错误,如果位图没找到则退出
	if (TextureImage[0] = LoadBMP(filename))
	{
		Status = TRUE;         // 将 Status 设为 TRUE
		glGenTextures(1, &texture[0]);     // 创建纹理

		// 使用来自位图数据生成 的典型纹理
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		// 生成纹理
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

		//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // 线形滤波
		//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // 线形滤波
	}

	if (TextureImage[0])        // 纹理是否存在
	{
		if (TextureImage[0]->data)      // 纹理图像是否存在
		{
			free(TextureImage[0]->data);    // 释放纹理图像占用的内存
		}
		else printf("the texture image is not existing!");

		free(TextureImage[0]);       // 释放图像结构
	}
	else printf("the texture is not existing!");
	return Status;          // 返回 Status
}
Exemple #24
0
int LoadGLTextures()									// Load Bitmap And Convert To A Texture
{
	char particlefilename[200];
    int Status=FALSE;								// Status Indicator
    SDL_Surface *TextureImage[1];				// Create Storage Space For The Textures
  

	memset(TextureImage,0,sizeof(void *)*1);		// Set The Pointer To NULL
	strcpy(particlefilename,GLOBAL.resourcepath);
	strcat(particlefilename,"GRAPHICS\\");
	strcat(particlefilename,PARTICLEBITMAP);
    if (TextureImage[0]=LoadBMP(particlefilename))	// Load Particle Texture
    {
		Status=TRUE;								// Set The Status To TRUE
		glGenTextures(1, &texture[0]);				// Create One Texture
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->w, TextureImage[0]->h, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->pixels);
    }

    if (TextureImage[0])							// If Texture Exists
	{
		SDL_FreeSurface(TextureImage[0]);
	}
    return Status;		
}
Exemple #25
0
static struct texture* LoadTexture (char* name)
{

  char              filename[MAX_STRING];
  struct texture*   t;

  t = new struct texture;
  strcpy (t -> name, name);
  sprintf (filename, "textures/%s.bmp", name);
  t->image = LoadBMP (filename);
  if (!t->image) {
    t->id = 0;
    return t;
  }
  glGenTextures (1, &t->id);// Create The Texture
	// Typical Texture Generation Using Data From The Bitmap
	glBindTexture (GL_TEXTURE_2D, t -> id);
  // Generate The Texture
	glTexImage2D (GL_TEXTURE_2D, 0, 3, 
    t -> image->sizeX, 
    t -> image->sizeY, 
    0, GL_RGB, GL_UNSIGNED_BYTE, 
    t -> image->data);
  free (t -> image);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering
  t -> next = head_texture;
  head_texture = t;
  return t;

}
Exemple #26
0
int LoadGLTextures2()         // 载入位图(调用上面的代码)并转换成纹理
{
	int Status = FALSE;         // 状态指示器
	AUX_RGBImageRec *TextureImage[1];     // 创建纹理的存储空间
	memset(TextureImage, 0, sizeof(void *)* 1);   // 将指针设为 NULL
	// 载入位图,检查有无错误,如果位图没找到则退出
	if (TextureImage[0] = LoadBMP("wall.bmp"))
	{
		Status = TRUE;         // 将 Status 设为 TRUE
		glGenTextures(1, &textureb[0]);     // 创建纹理

		// 使用来自位图数据生成 的典型纹理
		glBindTexture(GL_TEXTURE_2D, textureb[0]);
		// 生成纹理
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // 线形滤波
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // 线形滤波
	}

	if (TextureImage[0])        // 纹理是否存在
	{
		if (TextureImage[0]->data)      // 纹理图像是否存在
		{
			free(TextureImage[0]->data);    // 释放纹理图像占用的内存
		}

		free(TextureImage[0]);       // 释放图像结构
	}
	return Status;          // 返回 Status
}
static GLuint LoadGLTextures(const std::string &strFile)									// Load Bitmap And Convert To A Texture
{
	int Status = FALSE;								
	AUX_RGBImageRec *TextureImage[1];				
	memset(TextureImage, 0, sizeof(void *) * 1);		

	GLuint texture;
	if (TextureImage[0] = LoadBMP(strFile))	
	{
		Status = TRUE;								
		glGenTextures(1, &texture);				

		glBindTexture(GL_TEXTURE_2D, texture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0,
			GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
	}

	if (TextureImage[0])							
	{
		if (TextureImage[0]->data)					
		{
			free(TextureImage[0]->data);		
		}
		free(TextureImage[0]);					
	}
	return texture;	
}
int CLineComputeView::LoadGLTextures()
{
    int status = false;
    AUX_RGBImageRec *textureImage[1];
    memset(textureImage, 0, sizeof(void *)*1);
    if(textureImage[0] = LoadBMP(_T("test.bmp")))
    {
        status = true;
        glGenTextures(3, &texture[0]);
        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);	// 图像小于贴图
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);	// 图像大于贴图
        glTexImage2D(GL_TEXTURE_2D, 0, 3, textureImage[0]->sizeX, textureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, textureImage[0]->data);

        glBindTexture(GL_TEXTURE_2D, texture[1]);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// 图像小于贴图
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// 图像大于贴图
        glTexImage2D(GL_TEXTURE_2D, 0, 3, textureImage[0]->sizeX, textureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, textureImage[0]->data);

        glBindTexture(GL_TEXTURE_2D, texture[2]);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);	// 图像小于贴图
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// 图像大于贴图
        glTexImage2D(GL_TEXTURE_2D, 0, 3, textureImage[0]->sizeX, textureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, textureImage[0]->data);
    }
    if(textureImage[0])
    {
        if(textureImage[0]->data)
        {
            free(textureImage[0]->data);
        }
        free(textureImage[0]);
    }
    return status;
}
Exemple #29
0
bool CGLImageData::LoadTexture(const char *filename)
{
	if (!LoadBMP(filename))
		if(!LoadPNG(filename))
		{
			sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load image->");
			return false;
		}
		else
		{
			if (!MakeTexture())
			{
				sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load texture in video adapter.");
				return false;
			}
		}
	else
	{
		if(!MakeRGBA())
		{
			sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load texture.");
			return false;
		}
		if (!MakeTexture())
		{
			sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load texture in video memory.");
			return false;
		}
	}
	{
		delete [] data;
		data = NULL;
	}
	return true;
}
Exemple #30
0
int LoadGLTexture()
{
	int Status = FALSE;
	std::string tab[29] =
	{ "pliki/guziole/wrocN.bmp", "pliki/guziole/opcjeN.bmp", "pliki/guziole/startN.bmp", "pliki/guziole/wroc.bmp", "pliki/guziole/opcje.bmp",
		"pliki/guziole/start.bmp", "pliki/guziole/suwak.bmp", "pliki/guziole/pasek.bmp", "pliki/guziole/suwakN.bmp", "pliki/guziole/pasekN.bmp",
		"pliki/skyboxes/bottom.bmp", "pliki/skyboxes/left.bmp", "pliki/skyboxes/middle.bmp", "pliki/skyboxes/front.bmp", "pliki/skyboxes/right.bmp",
		"pliki/skyboxes/top.bmp","pliki/textures/ground.bmp","pliki/textures/groundN.bmp","pliki/skyboxes/stars.bmp","pliki/textures/literaq.bmp",
		"pliki/textures/literaw.bmp", "pliki/textures/literae.bmp", "pliki/textures/literar.bmp", "pliki/textures/literaa.bmp", "pliki/textures/literas.bmp",
		"pliki/textures/literad.bmp", "pliki/textures/literaf.bmp", "pliki/textures/back.bmp","pliki/textures/backN.bmp"  };
	AUX_RGBImageRec *TextureImage[29];//rezerwujemy miejsce na teksture
	memset(TextureImage, 0, sizeof(void*) * 1); //ustawiamy na 0
	for (int i = 0; i < 29; i++)
	{
		if ((TextureImage[i] = LoadBMP(tab[i])))
		{
			Status = true;
			glGenTextures(1, &texture[i]);
			glBindTexture(GL_TEXTURE_2D, texture[i]);
			gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, TextureImage[i]->sizeX, TextureImage[i]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[i]->data);//przypisawanie teksturze danych obrazowych
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//filtrowanie liniowe
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
		}
		if (TextureImage[i])
		{
			if (TextureImage[i]->data)
			{
				free(TextureImage[i]->data);//zwolnij pamiec tekstury obrazu
			}
			free(TextureImage[i]);//zwolnij pamiec struktury obrazu
		}
	}
	return Status;
}