Problems with textures
Hi everyone,
I am having problems with using textures on Visual C++. I suspect that somehow my texture is not being loaded properly. Could anyone help me, please?
Here is the code. I use the function CargarBMP to load the BMP and the function InicializaTexturas should get the texture, but when I bind the texture to an object on the Display function nothing is shown
Thanks in advance for your help
//TEXTURAS
GLuint texturas[1]; //nombres de las texturas
AUX_RGBImageRec *imagen[1];
//funcion que carga un BMP y lo devuelve
AUX_RGBImageRec *CargarBMP(char *NombreFichero)
{
FILE *Imagen=NULL;
if (!NombreFichero) // nos aseguramos de que tengamos el nombre del fichero
{
return NULL; //si no devolvemos NULL
}
Imagen=fopen(NombreFichero,"r");
if (Imagen) // comprobamos si existe el fichero
{
fclose(Imagen); // cerramos el handle
return auxDIBImageLoad(NombreFichero); // cargamos el BMP y lo devolvemos
}
return NULL; //si no devolvemos NULL
}
//funcion que carga los BMP en sus tablas de texturea correspondientes
void InicializaTexturas()
{
memset(imagen,0,sizeof(void *)*1); //inicializamos la memoria de la tabla
if(imagen[0]= CargarBMP("asfalto.bmp"))
{
//creamos las texturas
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texturas[0]);
glBindTexture(GL_TEXTURE_2D, texturas[0]);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB,imagen[0]->sizeX, imagen[0]->sizeY,
// 0, GL_RGB, GL_UNSIGNED_BYTE, imagen[0]->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, imagen[0]->sizeX, imagen[0]->sizeY,
GL_BGR_EXT, GL_UNSIGNED_BYTE, imagen[0]->data);
}
}
First off, may I recommend translating your comments to English. I''m sure the code would be easier to decipher for us non-Spanish people then.
_________"Maybe this world is another planet''s hell." -- Aldous Huxley
February 24, 2003 03:21 PM
This guy seems to be too lazy to translate or he is too lazy to tell he found the problem. Actually there aren''t much info in the comments but anyway here''s the translation:
//TEXTURES
GLuint texturas[1]; //names of the textures
AUX_RGBImageRec *imagen[1];
//function that loads a BMP and returns it
AUX_RGBImageRec *CargarBMP(char *NombreFichero)
{
FILE *Imagen=NULL;
if (!NombreFichero) //we make sure we got the name of the file
{
return NULL; //if not return NULL
}
Imagen=fopen(NombreFichero,"r"
;
if (Imagen) // test if the file exist
{
fclose(Imagen); // we close the handle
return auxDIBImageLoad(NombreFichero); //we load the BMP and return it
}
return NULL; //if not return NULL
}
//function that loads the textures into it''s asigned texture tables
void InicializaTexturas()
{
memset(imagen,0,sizeof(void *)*1); //we load the memory into the table
if(imagen[0]= CargarBMP("asfalto.bmp"
)
{
//we close the textures
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texturas[0]);
glBindTexture(GL_TEXTURE_2D, texturas[0]);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB,imagen[0]->sizeX, imagen[0]->sizeY,
// 0, GL_RGB, GL_UNSIGNED_BYTE, imagen[0]->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, imagen[0]->sizeX, imagen[0]->sizeY,
GL_BGR_EXT, GL_UNSIGNED_BYTE, imagen[0]->data);
}
}
I can''t help you because I''m trying to learn to load a texture myself! ;D
//TEXTURES
GLuint texturas[1]; //names of the textures
AUX_RGBImageRec *imagen[1];
//function that loads a BMP and returns it
AUX_RGBImageRec *CargarBMP(char *NombreFichero)
{
FILE *Imagen=NULL;
if (!NombreFichero) //we make sure we got the name of the file
{
return NULL; //if not return NULL
}
Imagen=fopen(NombreFichero,"r"

if (Imagen) // test if the file exist
{
fclose(Imagen); // we close the handle
return auxDIBImageLoad(NombreFichero); //we load the BMP and return it
}
return NULL; //if not return NULL
}
//function that loads the textures into it''s asigned texture tables
void InicializaTexturas()
{
memset(imagen,0,sizeof(void *)*1); //we load the memory into the table
if(imagen[0]= CargarBMP("asfalto.bmp"

{
//we close the textures
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texturas[0]);
glBindTexture(GL_TEXTURE_2D, texturas[0]);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB,imagen[0]->sizeX, imagen[0]->sizeY,
// 0, GL_RGB, GL_UNSIGNED_BYTE, imagen[0]->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, imagen[0]->sizeX, imagen[0]->sizeY,
GL_BGR_EXT, GL_UNSIGNED_BYTE, imagen[0]->data);
}
}
I can''t help you because I''m trying to learn to load a texture myself! ;D
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement