Click here to Skip to main content
Click here to Skip to main content

Load textures using OpenGL and Light weight Corona Image I/O

By , 13 Jun 2010
Rate this:
Please Sign up or sign in to vote.
Corona(http://corona.sourceforge.net/[^]) is an open-source light weight image input/output library that can read, write, and
manipulate image files in just a few lines of code. It can be used to load textures of formats PNG, JPEG, PCX, BMP, TGA, and GIF and output as PNG and TGA files. It well integrates with C and OpenGL.
 
Here is a code snippet which can be used to load textures:
 
unsigned int *tTexture;
// corona::OpenImage, where PF_DONTCARE to indicate any Pixel Format(PF) to load as texture, FF_AUTODETECT is Auto detect FileFormat.
    Image *image = OpenImage(filename,PF_DONTCARE,FF_AUTODETECT);
    if(image == NULL)
    {
         //Throw error
    }
 
    int imWidth = image->getWidth(); //Extract Width of the texture
    int imHeight = image->getHeight();
    glGenTextures(1,&tTexture[ID]); //Generate single texture (parameter one) and addressed by tTexture[ID]
    glBindTexture(GL_TEXTURE_2D,tTexture[ID]); //Make tTexture[ID] current
    gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,imWidth,imHeight,GL_RGB,GL_UNSIGNED_BYTE,image->getPixels());
    ...
    ...
    delete image;

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

GPUToaster™
Other
India India
http://gputoaster.wordpress.com/about
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 14 Jun 2010
Article Copyright 2010 by GPUToaster™
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid