Skip to main content
gamedev.net
🔒 Locked

[SOLVED]Problem with textures

Started by mesor Jun 19, 2007 at 7:40 PM 7 replies 1k views
Original Post
mesor
mesor
im traying to use 2 textures but if i call TexR[1] or TexT[0] it's the same!!!! here is the code!!!!!
char FTLoad2[256]="/mnt/backup/mdv/OpenGL/textura/door.bmp";
char FTLoad[256]="/mnt/backup/mdv/OpenGL/textura/fire.bmp";
GLuint textures[3];
GLuint TexA[2];GLuint TexR[2];




load 1 text

void TexLoad1(){
void FreeImage_Initialise();
glEnable(GL_TEXTURE_2D);
FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(FTLoad, 0);
FIBITMAP  *bmp = FreeImage_Load (fifmt,FTLoad, 0);
h=FreeImage_GetHeight(bmp);
w=FreeImage_GetWidth(bmp);
glBindTexture(GL_TEXTURE_2D,TexR[1]);
BYTE *bits = new BYTE[FreeImage_GetWidth(bmp) * FreeImage_GetHeight(bmp) * 3];
BYTE *pixels = (BYTE*)FreeImage_GetBits(bmp);
for(int pix=0; pix<FreeImage_GetWidth(bmp) * FreeImage_GetHeight(bmp); pix++)
		{	bits[pix*3+0]=pixels[pix*3+2];
			bits[pix*3+1]=pixels[pix*3+1];
			bits[pix*3+2]=pixels[pix*3+0];

		}
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, GL_RGB8, w,h, 0, GL_RGB, GL_UNSIGNED_BYTE,bits);
void FreeImage_DeInitialise();
}





load 2 text

void TexLoad2(){
void FreeImage_Initialise();
glEnable(GL_TEXTURE_2D);
FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(FTLoad2, 0);
FIBITMAP  *bmp = FreeImage_Load (fifmt,FTLoad2, 0);
h=FreeImage_GetHeight(bmp);
w=FreeImage_GetWidth(bmp);
glBindTexture(GL_TEXTURE_2D,TexR[0]);
BYTE *bits = new BYTE[FreeImage_GetWidth(bmp) * FreeImage_GetHeight(bmp) * 3];
BYTE *pixels = (BYTE*)FreeImage_GetBits(bmp);
for(int pix=0; pix<FreeImage_GetWidth(bmp) * FreeImage_GetHeight(bmp); pix++)
		{	bits[pix*3+0]=pixels[pix*3+2];
			bits[pix*3+1]=pixels[pix*3+1];
			bits[pix*3+2]=pixels[pix*3+0];

		}
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, GL_RGB8, w,h, 0, GL_RGB, GL_UNSIGNED_BYTE,bits);
void FreeImage_DeInitialise();
}




ps: im using Freeimage [Edited by - mesor on June 20, 2007 11:46:05 PM]
psycho_svk
psycho_svk
i think you forgot glGenTextures

before actually binding TexR[0], you first need to initialize it somehow [see glGenTextures]

---

also, the only difference in your two functions seems to be the file path and the texture id.. so to make it simpler, you could make this kind of function:

void TexLoad(char *file, GLuint *texID);

then you call TexLoad(FTLoad, &TexR[0]) for example..
and in function, you will use 'file' instead of 'FTLoad' and 'FTLoad2' and texID instead of TexR[0], etc..
mesor
mesor
i did it
glGenTextures(2, TexR)

then i call the load,
but nothing!
psycho_svk
psycho_svk
btw, you have saved width and height, so you dont have to use so long function names any more:
h = FreeImage_GetHeight(bmp);w = FreeImage_GetWidth(bmp);// soBYTE *bits = new BYTE[w * h * 3];// andfor(int pix=0; pix< w*h; pix++);


what 'nothing'? what happens?
mesor
mesor
all that you say im going to do it!!!! but first i need this thing works!
the problem is that i get allways the same texture -the last i load-!!!
I generate d etexture with glGenTexture(). But get the same problem
thx!
KumGame07
KumGame07
Quote:

the problem is that i get allways the same texture -the last i load-!!!


That is because you are loading texture to the same texture unit. (Unit 0) Are you binding the proper texture object before drawing?

Do something like,

glBindTexture(GL_TEXTURE_2D,TexR[0]);
//Draw an object
glBindTexture(GL_TEXTURE_2D,TexR[1]);
// Draw another object

Hope this helps you.
Best Regards,KumGame07
mesor
mesor
I try everithing!!! and its no`t working! i think the porblem is in other place!!!!!
i leave the full code here!!!! -dont worry its very short!- its supose to make 2 text and show them!!!!
i hope some one give me some help!!!!
THX!!!!!

http://itam.no-ip.org/backup/ftp/panel.cpp
psycho_svk
psycho_svk
so we found it..
glBindTexture() somehow fell inside of glBegin() and glEnd()

glBindTexture() must be outside ;)
mesor
mesor
Quote:
Original post by psycho_svk
so we found it..
glBindTexture() somehow fell inside of glBegin() and glEnd()

glBindTexture() must be outside ;)


YEAH!!!!!!!!!!!!!!!!! my mistake!!!!!!
thank you dude!!!!!!!
it work!!!!!!!
;)
i think this is it!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.