Jump to content
  • Advertisement
Sign in to follow this  
mesor

OpenGL Appling texture help! NOOB !!

This topic is 4117 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

Hello every boady!!!! im traying to use a texture with opengl under linux. I load it using FreeImage and then convert to apply it. the problem is that the result is not the spected. Here it is!!!! display i don't know what peace off code do you need. I paste what i think is relevant! thanks in advance and sorry!!! ---------------
unsigned char *data = FreeImage_GetBits(bmp);
glTexImage2D(GL_TEXTURE_2D, 0, 3, w,h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glutInitDisplayMode (GLUT_RGB);
---------------

Share this post


Link to post
Share on other sites
Advertisement
What is the size of your texture? It has to be a multiple of 8/16/or 32. (I recommend 32x32)

Also, it would be helpful to tell us the tex coords as well.

Share this post


Link to post
Share on other sites
OK i try 32*32 but still get the same!
here are the coords.

first i try this!


glVertex3f(w / 2,h ,0);glTexCoord2f(w / 2,h);
glVertex3f(w / 2 + w,h,0);glTexCoord2f(w / 2 + w,h);
glVertex3f(w / 2 + w,2*h,0);glTexCoord2f(w / 2 + w,2*h);
glVertex3f(w/ 2 ,2*h,0); glTexCoord2f(w/ 2 ,2*h);



then this!

glVertex3f(0,0,0);glTexCoord2f(0,0);
glVertex3f(w,0,0);glTexCoord2f(w,0);
glVertex3f(w ,h,0);glTexCoord2f(w,h);
glVertex3f(0,h,0); glTexCoord2f(0,h);


but get the same shit!
where

FIBITMAP *bmp = FreeImage_Load (fifmt,FTLoad, 0);
unsigned h=FreeImage_GetHeight(bmp);
unsigned w=FreeImage_GetWidth(bmp);
glOrtho(0.0, 2*GetW(), 0.0,3*GetH(), 0, 1.0);


thank dude!

Share this post


Link to post
Share on other sites
Try this:

glVertex3f(0,0,0);glTexCoord2f(0.0f,0.0f);
glVertex3f(w,0,0);glTexCoord2f(1.0f,0.0f);
glVertex3f(w ,h,0);glTexCoord2f(1.0f,1.0f);
glVertex3f(0,h,0); glTexCoord2f(0.0f,1.0f);

Share this post


Link to post
Share on other sites
Firstly, every modern graphics card and driver supports textures that aren't powers of 2. They might run slower on some older cards, but they'd be supported.

Okay, for your problem. I suggest using one of the other values (such as GL_RGB8) for the internalformat (third) parameter to glTexImage2D. They are more descriptive and make it more obvious as to what you get. Next, double check what format FreeImage_GetBits() gives you the images in. It could have an Alpha channel. If so, you'd have to use a different value for the format (7th) parameter to glTexImage2D that would fit the actual format (eg: GL_RGBA).

Notice that I'm thinking that the problem is with your call to glTexImage2D. That's because the problem looks to me as if it's got the wrong number of bytes or channels and is, hence, using parts of one pixel for another.

And finally, put in some code to make sure that FreeImage_GetBits() hasn't failed. That's all I can think of, good luck.

Share this post


Link to post
Share on other sites
ok1!!!
it's getting beter!!!!
thanks!!!
now i get this

get

but im supossed to get this

want


guess the problem is with rgb, but i can`t figure it out!!!
its twisted and blue!!!

if i want to use a larger texture like 200*300 i cant right?
it should be 200,304?
thx!!!!!

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
Firstly, every modern graphics card and driver supports textures that aren't powers of 2. They might run slower on some older cards, but they'd be supported.

i guess this answer one of my quiestion thx!!!!
Quote:
Original post by Ezbez
Okay, for your problem. I suggest using one of the other values (such as GL_RGB8) for the internalformat (third) parameter to glTexImage2D. They are more descriptive and make it more obvious as to what you get. Next, double check what format FreeImage_GetBits() gives you the images in. It could have an Alpha channel. If so, you'd have to use a different value for the format (7th) parameter to glTexImage2D that would fit the actual format (eg: GL_RGBA).

i trye but get the same. i fixit with de coords that crypter sugested!!!

Quote:
Original post by Ezbez
And finally, put in some code to make sure that FreeImage_GetBits() hasn't failed. That's all I can think of, good luck.

i all ready do that and is supossed to work!!!!
thank YOU!!!
now i have the blu problem!!!!
:D

Share this post


Link to post
Share on other sites
color Finally fixed!!!!!
here is the code!!!!!

BYTE *bits = new BYTE[FreeImage_GetWidth(bmp) * FreeImage_GetHeight(bmp) * 3];
BYTE *pixels = (BYTE*)FreeImage_GetBits(bmp);

y add those lines!!!!
and now it works!!!!!
but still have the twisted problem thx!!!!!!!
good fights!!! god nights!!!!
thank you all!!!

Share this post


Link to post
Share on other sites
OK its all runing!!!!
thank you people!!!! you really help!!!!!!!!!!!!!
i fix the twist by playin with the coords!
final these ones works



glVertex3f(0,0,0);glTexCoord2f(1.0f,0.0f);
glVertex3f(w,0,0);glTexCoord2f(1.0f,1.0f);
glVertex3f(w ,h,0);glTexCoord2f(0.0f,1.0f);
glVertex3f(0,h,0); glTexCoord2f(0.0f,0.0f);

thank you all!!!!!!!!!!!!!!!!!!!!!1

Share this post


Link to post
Share on other sites
I know that you fixed your problem. Ive also had the same problem with the colors and i figured it out.
BMP textures are stored in BGR and not RGB. All i had to do was use GL_BGR_EXT when i call glTexImage2D() instead of GL_RGB.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!