Results 1 to 6 of 6

Thread: loading bmp files using opengl

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2004
    Posts
    19

    loading bmp files using opengl

    how do you load a bmp file into opengl.

  2. #2
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: loading bmp files using opengl

    Write a BMP loading function or use a BMP loading library.

    Seriously, OpenGL has no support for loading specific image formats at all; that's not a design goal of it. You need to either provide your own code or use a library to get at the raw pixel data and send that through glTexImage2D.

    Which library to use depends on what OS you're on, whether or not portability is a concern for your program, what language you're using and other factors.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2004
    Posts
    19

    Re: loading bmp files using opengl

    well I am using win 7 and and c++.

  4. #4
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: loading bmp files using opengl

    Well there are a number of options. On that platform I like using GDI+ because it means that you can distribute your application to other Windows (XP, Vista or 7) users without requiring them to install additional DLLs to get it running. Something like this will do it (untested, for illustrative purposes only):
    Code :
    Bitmap theImage (name);
    BitmapData bmpData;
    Rect lockRect (0, 0, theImage.GetWidth (), theImage.GetHeight ());
    theImage.LockBits (&lockRect, ImageLockModeRead, PixelFormat32bppARGB, &bmpData);
    glTexImage2D (...);
    theImage.UnlockBits (&bmpData);

    You'll also need to correctly start up and shut down GDI+ in your program; info here: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    592

    Re: loading bmp files using opengl


  6. #6
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: loading bmp files using opengl

    I have a simple demo that loads .bmp files and displays them as textures or as an image (glDrawPixels). The .bmp loading routines are contained in the demo. You don't have to mess with any libraries. See -

    http://www.mfwweb.com/OpenGL/Loading_Textures/
    Am I doing your homework for you?

Similar Threads

  1. Loading .obj files into Opengl
    By jaeybee in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-19-2013, 10:11 AM
  2. Loading object files into OpenGL
    By aeonstrife in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-22-2011, 03:57 AM
  3. Issue loading files with OpenGL enabled.
    By LScinto in forum OpenGL: Windows
    Replies: 6
    Last Post: 11-25-2008, 06:16 PM
  4. loading dds files onto opengl application
    By artintel2 in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 08-17-2004, 03:11 PM
  5. Loading files and OpenGL
    By d98ped in forum OpenGL: macOS
    Replies: 4
    Last Post: 09-03-2001, 03:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean