Jump to content
  • Advertisement
Sign in to follow this  
EonStrife

OpenGL Loading JPG as Texture

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

Anyone has code for loading JPG as texture in OpenGL ? Oh, and I also need transparency (because, I want to make round-edge on the bridge card I draw). Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
A jpeg does not have an alpha (or as you call it, transparency) channel.

Share this post


Link to post
Share on other sites
Try using the PNG format. You can use DevIL (OpenIL) to load the texture. DevIL can load JPEGs too but as the AP said JPEG has not support for an alpha channel.

Share this post


Link to post
Share on other sites
Could not read file.

Go back. /home/ftp/pub/sourceforge//o/op/openil/Devil-1.6.8-RC1-win32.zip
Apr 22, 2006 17:18


??????

Share this post


Link to post
Share on other sites
You could also try Corona (http://corona.sourceforge.net/). It's very simple to use. There's a tutorial.txt included with the download, but if you're still having problems I can post my code.

Share this post


Link to post
Share on other sites
Quote:
Original post by Wingman
You could also try Corona (http://corona.sourceforge.net/). It's very simple to use. There's a tutorial.txt included with the download, but if you're still having problems I can post my code.


Thanks :)
BTW, I tried this code, but the transparency doesn't work...


bool COpenGLControl::LoadCardImage(TextureImage *texture)
{

corona::Image* image = corona::OpenImage("Data/cards.gif", corona::PF_R8G8B8A8);
if(!image) return false;
corona::FlipImage(image, corona::CA_X);
texture->width=image->getWidth();
texture->height=image->getHeight();
texture->bpp=32;
int imageSize = texture->width*texture->height*4;
texture->imageData=(GLubyte *)malloc(imageSize);
void* pixels=image->getPixels();

typedef unsigned char byte;
byte* p=(byte*)pixels;
unsigned long j=0, i=0;
for(i=0; i<texture->width*texture->height; ++i)
{
j=i*4;
texture->imageData[j]=*p++;
texture->imageData[j+1]=*p++;
texture->imageData[j+2]=*p++;
texture->imageData[j+3]=*p++;

}
// free(pixels);
delete(image);

glGenTextures(1, &texture[0].texID); // Generate OpenGL texture IDs

glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Linear Filtered


glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture[0].width, texture[0].height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture[0].imageData);



Share this post


Link to post
Share on other sites
I've never used Corona, but I guess that it probably will not automatically set the appropriate alpha value based on the RGB component pixels. If not, then you will need set this when you are transferring the image data from the corona image array to your own texture imageData array.

F451

Share this post


Link to post
Share on other sites
I use SDL_Image to load PNGs for textures, works great.

If you try to use it, here's the code I use to load them: http://rafb.net/paste/results/g0jKm682.html

Ignore the TextureHandle stuff, that's just my texture manager's extra code.

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!