void GLRender::DrawImage( CPointer<Image> ℑ, int x, int y, int width, int height)
{
/**
* Get the texture num
*/
glBindTexture(GL_TEXTURE_2D, image->textNum );
/**
* draw the image out
*/
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(x, y);
glTexCoord2f(0, height );
glVertex2f(x, y+height);
glTexCoord2f(width, height);
glVertex2f(x+width, y+height);
glTexCoord2f(width, 0);
glVertex2f(x+width, y);
glEnd();
}
And here is the loader code:
/**
=========================
Load a targa file, and load
it in ogl
=========================
*/
bool TextureLoader::LoadTGA( const std::string &s )
{
TGAHEADER tga;
CPointer<Image> image = new Image();
image->data = 0;
image->data = LoadTGAFile(s, &tga);
// Didn't load the file
if ( !image->data ) {
std::cout << "\nNo data\n" << std::endl;
return false;
}
image->width = tga.imageWidth;
image->height = tga.imageHeight;
image->bitDepth = tga.imageWidth;
image->id = ++m_idcounter;
image->imageType = TGA;
image->nBPP = tga.nBPP;
int newwidth = NextPowerOfTwo( image->width );
int newheight = NextPowerOfTwo( image->height );
// Get the maximal texture size supported, and change the size of thetexture if it is to big
int maxTextureSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
if(newwidth > maxTextureSize) newwidth = maxTextureSize;
if(newheight > maxTextureSize) newheight = maxTextureSize;
// TODO - scale image to proper format
// I am using images that are powers of 2
glGenTextures(1, &image->textNum); // Create The Texture
// bind the texture
glBindTexture(GL_TEXTURE_2D, image->textNum);
// Disable Antialiazing for magnification/minification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gluBuild2DMipmaps( GL_TEXTURE_2D, image->nBPP,
image->width, image->height,
(image->nBPP == 3 ? GL_RGB : GL_RGBA),
GL_UNSIGNED_BYTE, image->data);
// add to the list
imageList[ image->id ] = image;
if ( image->data )
delete []image->data;
return true;
}
Any help would be greatly appreciated, thanks, -Tony