Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

VECTOR

What's wrong? Texture binding prob of some sort

This topic is 6720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
make sure that the bitmaps you are using are 64X64 or 128X128 or 256X256 pixels if not you will get the black polygons

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Check your return values and make sure you have a valid rendering context before trying to load

..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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



Share this post


Link to post
Share on other sites
I''m dealing with the same problem.

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

please

Blizz

Share this post


Link to post
Share on other sites
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[i]->data){
free(TextureImage[i]->data);
}
free(TextureImage[i]);
}
}
}
drawObject(){
...
...
glBindTexture(GL_TEXTURE_2D,texture_im[0]);
glBegin(GL_TRIANGLES);
//draw object n°1 with texture 0
glEnd();
glBindTexture(GL_TEXTURE_2D,texture_im[2];
glBegin(GL_TRIANGLES);
//draw object n°1 with texture 2
glEnd();
}

hope that help

lunasol



Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!