Jump to content
  • Advertisement
Sign in to follow this  
billconan

OpenGL texture problem, cannot create non-square texture

This topic is 4312 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 guys, is it true that opengl only support texture in square? i'm working on my 3d modeller which allows people to choose an image as reference, and i can't guarantee that the image is in square. my program is ok if the image i specified is in square but becomes very weird if it is not. so how to deal with it. do i need to manually map the image to a square texture? thank you.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by billconan
hello guys, is it true that opengl only support texture in square?
i'm working on my 3d modeller which allows people to choose an image as reference, and i can't guarantee that the image is in square. my program is ok if the image i specified is in square but becomes very weird if it is not. so how to deal with it. do i need to manually map the image to a square texture? thank you.
No, OpenGL supports textures with non-square dimensions. OpenGL versions prior to 2.0 did not support non-power-of-two dimensioned textures unless using an extension such as GL_ARB_texture_rectangle or if the GL_ARB_texture_non_power_of_two extension was supported. GL_ARB_texture_non_power_of_two was rolled into the core in OpenGL 2.0.

What do you mean it "becomes very weird?" More information on exactly what you're doing (and maybe some relevant source code, using source tags) and what's going wrong would be useful.

Share this post


Link to post
Share on other sites
ok, i'll explain the "weird" :,

this is how the app looks if the texture for those buttons is 256*256:


and this is how it looks when i expand the texture to 300*256(in photoshop)


and this is my code for generating texture from image(using wxwidgets' image class):


GLuint loadTexture(char *fileName)
{
GLuint txtnumber;
wxImage texture(_T(fileName),wxBITMAP_TYPE_PNG,-1);
int theHeight=texture.GetHeight(); //read into height and width
int theWidth=texture.GetWidth();
unsigned char *RGBData=texture.GetData();
unsigned char *alphaData=texture.GetAlpha();
size_t pixelCount=theHeight*theWidth;
size_t dataSize=pixelCount*4;
unsigned char *data=new unsigned char[dataSize];
for(size_t i=0;i<pixelCount;++i)
{
data[i*4]=RGBData[i*3];
data[i*4+1]=RGBData[i*3+1];
data[i*4+2]=RGBData[i*3+2];
data[i*4+3]=alphaData;
}
glGenTextures(1, &txtnumber);
glBindTexture(GL_TEXTURE_2D, txtnumber);
glTexImage2D(GL_TEXTURE_2D, 0, 4, theHeight, theWidth, 0,GL_RGBA,GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
delete data;
return txtnumber;
};


[Edited by - billconan on September 29, 2006 4:30:27 AM]

Share this post


Link to post
Share on other sites
[grin] It happens, those are the worst bugs to find sometimes. Glad you got it fixed. Your app looks great by the way.

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!