Jump to content
  • Advertisement


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


Textures in C++

This topic is 6451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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 );

// 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 );
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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!