Loading .bmp textures: GLUT, GLaux? HELP!!!

hello,

ok, so i have read ‘OpenGL Programming Guide’ (the Red Book) and ‘OpenGL Superbible’, and both seemed to just sort of race through texture mapping without discussing how to load and use bitmap textures.

i am just looking for the basic steps for loading bitmaps and using them as textures in simple english.

any samples or source code would be great.

thank you, brian.

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06

glaux is way outdated, I wouldn’t use it anymore…

You could have a look at DevIL (www.imagelib.org). There are many tutorials on the DevIL homepage, and it is integrated pretty well with OpenGL (directly loading a file into a texture).

i spent to weeks solid trying to get texture mapping to work but i kept on getting all sorts of linker errors, like unresolved external LoadDIBimageA or sumthing like that and everyone i asked said it was the glaux lib either i didnt link it or it was damaged but i definatly linked it so i deleted all the glaux rubbish and found some code which didnt need the glaux lib, and after 10 minits it worked perfect. so take overminds word for it, the glaux lib is junk.
here is the steps for loading a bitmap;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc

Underneath, the code above, in your programm(its near the start)put in the code below;

bool LoadBitmap(LPTSTR szFileName, GLuint &texid)
HBITMAP hBMP;
BITMAP BMP;
glGenTextures(1, &texid);
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );

if (!hBMP)															
	return FALSE;													

GetObject(hBMP, sizeof(BMP), &BMP);

glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

glBindTexture(GL_TEXTURE_2D, texid);

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, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

DeleteObject(hBMP);									
return TRUE;								

}

After you have entered that go to the
int InitGL(GLvoid)
part and enter, before
return true;
this part of code

if (!LoadBitmap(“Data/(this is the name of your bimap ie its saved name which is put into a folder named Data. The Data folder is placed with the project and unit code wherever u saved that. ps The brackets around this are not here).bmp”, texture[0]))
{
return FALSE;
}

after this is in, go to the drawglscene part of the code and draw a normal square except before u do glBegin(QUADS) enter this

glBindTexture(GL_TEXTURE_2D, texture[0]);

after that u need to enter the coord points, which are entered before the each of these
glVertex3f(-1.0f, -1.0f, 1.0f);
the coord pionts are these
glTexCoord2f(0.0f, 0.0f);
and the second coord point would be
glTexCoord2f(1.0f, 0.0f);
then
glTexCoord2f(1.0f, 1.0f);
then
glTexCoord2f(0.0f, 1.0f);
notice they always go round in a anticlockwise direction so make sure u draw ur shape in a anticlockwise direction.

hope that helps if u dont understand anything just reply

If you can, get your hands on a copy of OpenGL game programming. Or find its web page (google). You’re especially interested in chapters 7,8,9 which cover loading a bmp and tga file, saving them and then do some funky stuff with it. If you download the source code you could use the bmp loading function. Now if it only was in C++… but nobody’s perfect.

There are lots of libraries out there with source code for loading windows bitmaps… the NeHe site is one of many that explains the “how-to”…

off:

GetObject(hBMP, sizeof(BMP), &BMP);
should be:

GetObject(hBMP, sizeof(BITMAP), &BMP);
  

right ?