View Full Version : Loading .bmp textures: GLUT, GLaux? HELP!!!
04-20-2005, 10:11 PM
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.
04-21-2005, 01:24 AM
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).
04-21-2005, 03:00 AM
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)
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
GetObject(hBMP, sizeof(BMP), &BMP);
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);
After you have entered that go to the
part and enter, before
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))
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
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
and the second coord point would be
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"...
GetObject(hBMP, sizeof(BMP), &BMP);should be:
GetObject(hBMP, sizeof(BITMAP), &BMP);
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.