How to load JPG for textures

How should i load jpg images for using them as a textures ?

  1. Go and read about discrete cosine transforms and quantization and huffman encoding
  2. Code a jpg decompression algorithm

or

use a jpeg library

I tried that but it doesn’t work :

TJPEGImage *JPEGObrazek = new TJPEGImage();
JPEGObrazek->Performance = jpBestQuality;
JPEGObrazek->PixelFormat = jf24Bit;
JPEGObrazek->Grayscale = false;
JPEGObrazek->LoadFromFile(“Data//Suter.jpg”);

Graphics::TBitmap *Bitmapa = new Graphics::TBitmap();
Bitmap->HandleType = bmDIB;
Bitmap->PixelFormat = pf32bit;
Bitmapa->Width = JPEGObrazek->Width;
Bitmapa->Height = JPEGObrazek->Height;
Bitmapa->Canvas->Draw(0,0,JPEGObrazek);
free (JPEGObrazek);

glGenTextures(1,&Textures[0]);
glBindTexture(GL_TEXTURE_2D,Textures[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3,Bitmapa->Width, Bitmapa->Height, 0, GL_RGB, GL_UNSIGNED_BYTE, Bitmapa );

Is the jpeg being loaded ok, i.e. can you draw the ‘bitmapa’ to the screen to check it? try gldrawpixels to check you have loaded it as well…
glteximage the last parameter… is that correct? isn’t that ‘bitmapa’ the structure which holds all the jpeg info, as in width and everything as well? you need a pointer to the actual rgb data. but I work in C so what do I know!..

Hello.
Take a look at the third tutorial of this page: http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg2.htm

I hope that helps.

Thanks