🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

What's wrong? Texture binding prob of some sort

Started by
6 comments, last by VECTOR 24 years ago
int LoadGLTextures() // Load Bitmaps And Convert To Textures { MessageBox( NULL, "A Try", "InfoLoadGLTextures", NULL ); // -------------- Load the filenames -------------------- ifstream inStream; inStream.open( "tstfile.txt", ios::in/ios::nocreate ); if( !inStream ) MessageBox( NULL, "no file", "INFO", NULL ); char scanline[512]; AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL int tnum = 0; glGenTextures(3, &texture[0]); // Create Three Textures for (int loop = 0; loopsizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); } int Status=TRUE; return Status; // Return The Status } It might be some work to figure this out, but it''s not that hard. It loads from tstfile.txt a few material filenames. Then it loads those textures into TextureImage[index]. Why won''t it do that? When I run I get blank polygons with no textures. By the way how do you people post your code in those white console type boxes on this messageboard?
The object of war is not to die for your country, but to make the other bastard die for his . . -General MacArthur
Advertisement
make sure that the bitmaps you are using are 64X64 or 128X128 or 256X256 pixels if not you will get the black polygons
I don''t know about you, but this had me stumped for awhile: make sure you bind your textures BEFORE glBegin();

its probably just me though

If all these errors are so fatal, why am I still alive?
If all these errors are so fatal, why am I still alive?
Check your return values and make sure you have a valid rendering context before trying to load

..
1. Have you enabled GL_TEXTURE_2D before calling this function ?
2. Why do you make a call to glGenTextures in your loop ? You already created them before.

Y.
hi,

>>AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
>>glGenTextures(3, &texture[0]); // Create Three Textures

why do you create 3 textures objects with the same texture?

secondly make sure that in your drawing function, you bind the texture
ex :
glBindTexture(GL_TEXTURE_2D,texture[0]);
glBegin(GL_TRIANGLES);
//draw some stuff
glEnd();

hope that help

lunasol



I''m dealing with the same problem.

Maybe someone could copy & paste a good example on using a few different textures ??

please

Blizz
hi
i don''t if it''s a good example but it works.

GLuint texture_im[3];
...
...
void LoadGLTextures(){

int status=1;
int i;
GLfloat mat_emission[]={1.0f,0.7f,0.0f,1.0f};
GLfloat mat_diffuse[]={1.0f,0.7f,0.0f,1.0f};

AUX_RGBImageRec *TextureImage[2];
memset(TextureImage,0,sizeof(void *)*1);
if (TextureImage[0]=LoadBMP("data/crom1.bmp")){
glGenTextures(1,&texture_im[0]);
glBindTexture( GL_TEXTURE_2D, texture_im[0] );
glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,
GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
}
if (TextureImage[1]=LoadBMP("data/castle1.bmp")){
glGenTextures(1,&texture_im[1]);
glBindTexture( GL_TEXTURE_2D, texture_im[1] );
glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[1]->sizeX,TextureImage[1]->sizeY,0,
GL_RGB,GL_UNSIGNED_BYTE,TextureImage[1]->data);

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
}
if (TextureImage[2]=LoadBMP("data/sky1.bmp")){
glGenTextures(1,&texture_im[2]);
glBindTexture( GL_TEXTURE_2D, texture_im[2] );
glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[2]->sizeX,TextureImage[2]->sizeY,0,
GL_RGB,GL_UNSIGNED_BYTE,TextureImage[2]->data);

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
}
for (i=0;i if (TextureImage){
if(TextureImage->data){<br> free(TextureImage->data);<br> }<br> free(TextureImage);<br> }<br> }<br>}<br>drawObject(){<br>…<br>…<br>glBindTexture(GL_TEXTURE_2D,texture_im[0]);<br>glBegin(GL_TRIANGLES);<br>//draw object n°1 with texture 0<br>glEnd();<br>glBindTexture(GL_TEXTURE_2D,texture_im[2];<br>glBegin(GL_TRIANGLES);<br>//draw object n°1 with texture 2<br>glEnd();<br>}<br><br>hope that help<br><br>lunasol<br><br><br><br> </i>

This topic is closed to new replies.

Advertisement