Advertisement

Glaux replacement

Started by April 10, 2003 08:45 AM
9 comments, last by i_pee_freely 21 years, 10 months ago
I see people in posts saying that glaux is bad. I want to load bitmaps to use as textures. How do i do it without auxDIBImageLoad()????? Some code of creating an image without would be beautiful. Is there a function in glut that does the job of loading bitmaps?? Why do tutorials that i see use it if it''s bad.
Just write a BMP loader yourself it's not that hard, check www.wotsit.org for the file format. You could also use the Win32 function LoadBitmap() (and some others) to get data from a BMP file,...

If you're to lazy grab the TGA loader from one of NeHe's tutorials.... i recommend using TGA because it has support for alpha channels...

-Crawl

[edited by - Crawl on April 10, 2003 11:39:59 AM]
--------<a href="http://www.icarusindie.com/rpc>Reverse Pop Culture
Advertisement
http://openil.sourceforge.net/
A clip from the non GLaux tuts I'm rewriting... Hope it helps!

bool LoadBitmap(LPTSTR szFileName, GLuint &texid)							// Creates Texture From A Bitmap File{	HBITMAP hBMP;											// Handle Of The Bitmap	BITMAP	BMP;											// Bitmap Structure	glGenTextures(1, &texid);									// Create The Texture	hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );	if (!hBMP)											// Does The Bitmap Exist?		return FALSE;										// If Not Return False	GetObject(hBMP, sizeof(BMP), &BMP);								// Get The Object													// hBMP:        Handle To Graphics Object													// sizeof(BMP): Size Of Buffer For Object Information													// &BMP:        Buffer For Object Information	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);								// Pixel Storage Mode (Word Alignment / 4 Bytes)	// Typical Texture Generation Using Data From The Bitmap	glBindTexture(GL_TEXTURE_2D, texid);								// Bind To The Texture ID	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);				// Linear Min Filter	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);				// Linear Mag Filter	glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);	DeleteObject(hBMP);										// Delete The Object	return TRUE;											// Loading Was Successful}BOOL Initialize (GL_Window* window, Keys* keys)								// Any GL Init Code & User Initialiazation Goes Here{	g_window	= window;	g_keys		= keys;	// Start Of User Initialization	if (!LoadBitmap("Data/NeHe.bmp", texture[0]))							// Load The Bitmap		return FALSE;										// Return False If Loading Failed    


[edited by - nehe on April 16, 2003 10:15:38 PM]
Nice NeHe, thanks
Thanks Nehe for the code!!!

It''ll be very useful to me!

Thanks,
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear
Advertisement
You are very welcome... that''s about as small as I could get the code ... lots of trial and error

Seems to work not too bad... and replaces the glaux code without adding alot of extra code.
Out of curiosity, what *is* it that''s so bad about the glauxDIBImageLoad function?
copy and paste from opengl.org


2.130 What is the AUX library?

Very important: Don''t use AUX. Use GLUT instead.

The AUX library was developed by SGI early in OpenGL''s life to ease creation of small OpenGL demonstration programs. It''s currently neither supported nor maintained. Developing OpenGL programs using AUX is strongly discouraged.
Here''s a little SDL based code to do the same thing for those of us
not living in windows land, mostly ripped from lesson06 check there
for commented code =)

GLuint texture[1];

int BMPtoTexture( char *filename, int texid )
{
int Status = false;
SDL_Surface *TextureImage[1];

if ( ( TextureImage[0] = SDL_LoadBMP( filename ) ) )
{
Status = true;

glGenTextures( 1, &texture[texid] );
glBindTexture( GL_TEXTURE_2D, texture[texid] );
glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->w,
TextureImage[0]->h, 0, GL_BGR,
GL_UNSIGNED_BYTE, TextureImage[0]->pixels );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}

if ( TextureImage[0] )
SDL_FreeSurface( TextureImage[0] );

return Status;
}

bool Initialize(void)
{
if (!BuildTexture("data/nehe.bmp", 0 ))
return false;
return true;
}


--
/Ant Whitehead
Unix Sysadmin
PGP Key: http://www.solace.mh.se/~ant/ant.pubkey
--/Ant WhiteheadUnix SysadminPGP Key: http://www.solace.mh.se/~ant/ant.pubkey

This topic is closed to new replies.

Advertisement