Archived

This topic is now archived and is closed to further replies.

Vaporized

Textures in C++

Recommended Posts

How do i load bmp files to use them with OpenGl ?? I use to program Delphi and i used a scanline function. Although i cant find a similiar function in C++. The help i have is ancient so it doesnt help much i have looked at Hbitmap structure, i can use it to load a bitmap but how do i get to the actual data after its loaded ?? I would realy apreciate it if any of you could give me some info. Thanks c(_) <- inspiration

Share this post


Link to post
Share on other sites
Bitmaps are all that adaptable (no alpha channel), I''d suggest using an easier format such as TGA''s (they do have an alpha channel). See Nehe''s TGA loading tutorial for more of an explanation.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/

Share this post


Link to post
Share on other sites
Here''s my bitmap loding code for OpenGL using a modified version of NeHe''s code:

  
UINT LoadOpenGLTexture( LPSTR lpFile,
BOOL bAlpha = FALSE,
GLenum minfilter = GL_LINEAR,
GLenum magfilter = GL_LINEAR,
GLenum wrap = GL_REPEAT )
{
if (lpFile == NULL)
return 0;

FILE* f;
AUX_RGBImageRec* img;
UINT texture;

// try to open the file to make sure it exists

if ((f = fopen(lpFile, "r")) == NULL)
{
MessageBox( 0, "LoadOpenGLTexture() FAILED.", "Error", MB_OK );
return 0;
}

fclose(f); // The file exists - proceed


// Clear the image memory

memset(&img, 0, sizeof(img));

// Put the data into the image holder

img = auxDIBImageLoad(lpFile);

if (img)
{
glGenTextures( 1, &texture ); // Generate tex

glBindTexture( GL_TEXTURE_2D, texture ); // 2D texture


// Texture options

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap );
glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// Generate the texture

glTexImage2D( GL_TEXTURE_2D, 0, 3, img->sizeX, img->sizeY, 0, GL_RGB,
GL_UNSIGNED_BYTE, img->data );

// Everything went ok, free ram

if ( img )
{
if ( img->data )
free( img->data );

free ( img );
}
}
else
{
MessageBox( 0, "LoadOpenGLTexture() FAILED.", "Error", MB_OK );
return 0;
}

return texture;
}



Here''s how to use it:

  
UINT texture = LoadOpenGLTexture( "texture.bmp" );

glBindTexture( GL_TEXTURE_2D, texture );


hope that helps

Share this post


Link to post
Share on other sites