Results 1 to 7 of 7

Thread: Loading Textures

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    6

    Loading Textures

    Hi I am just starting to learn OGL and I am
    looking into loading textures. Which got me
    thinking of something which I can't seem to
    figure out. I can load a texture from a
    complete BMP file. (Found some code through NEHE
    and it was quite simpel to understand) But I
    have noticed that some people keep many texture
    in one BMP file, so thinking I understand all I
    have read so far, I decided to give it a shot...
    ya right easy NOT.

    Where can I find documentation on loading a
    portion of a BMP file into a texture. What I
    would like as a test is to Hold 9 textures in
    one BMP file. Lets say the BMP file is 300*300
    Pixels. Therefore I would have 9 100X100 images
    that can be loaded as textures. Currently I see
    creating a C++ object with the entry point
    LoadBMPPortion(int TopLeft, int TopRight, int
    Width, int height) is this a good approach and
    how will this interact with glTexImage2D.

    Thanks for your time.
    Marc

    Here is the code I currently use:
    CBitmap image; // We'll use this to load the texture

    // First we load the bitmap
    // if(image.loadBMP("100a_Chicago_skyline(4X).bmp") == false)
    // if(image.loadBMP("100a_Chicago_skyline.bmp") == false)
    if(image.loadBMP("Bitmap.bmp") == false)
    return;

    glGenTextures(1, &g_Texture[0]);

    glBindTexture(GL_TEXTURE_2D, g_TextureID);

    glTexImage2D(GL_TEXTURE_2D, 0, image.getChannels(), image.getWidth()/4, image.getHeight()/4,
    0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image.getLinePtr(0));

    gluBuild2DMipmaps(GL_TEXTURE_2D, image.getChannels(), image.getWidth(),
    image.getHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE,
    image.getLinePtr(0));

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR);

  2. #2
    Member Newbie
    Join Date
    Jul 2004
    Posts
    49

    Re: Loading Textures

    If you want glTexImage2D to pick a portion of an image, you'll need to call glPixelStorei(GL_UNPACK_ROW_LENGTH, your_image_width). And of course, you'll have to specify the right address as the last parameter to glTexImage2D, but that's just generic 2d array stuff.

    Or you could just leave them all in one texture and adjust the texture coordinates appropriately.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    6

    Re: Loading Textures

    Hi

    Thanks for the prompt response, I am just using
    this as a learning tool, so yes I only plan to
    do 2d (Baby Steps)

    I am not sure I understand your reply. Where do
    I call this function glPixelStorei(..) my guess
    is before, but how will this interact with the
    glTexImage2D(...). Can you please elaborate on
    your response, and/or if possible provide some
    psuedo code maybe by seeing it I'll understand
    better what you mean.

    Thanks for your time
    Marc

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    6

    Re: Loading Textures

    Oh One last thing // Second though

    I am able to get portions of the BMP in staright C++ code using CreateBitmap(...) and pointing to a porting of the Original BML file. I the have a portion of the BMP file,When I output it straigh using no OGL code the image I get is correct, when I try to point to the Pixel info i seem to only get the first line of pixels. Can I therefore load a texture from a HBITMAP.

    Marc

  5. #5
    Member Newbie
    Join Date
    Jul 2004
    Posts
    49

    Re: Loading Textures

    Originally posted by Bukwheat:
    When I output it straigh using no OGL code the image I get is correct, when I try to point to the Pixel info i seem to only get the first line of pixels. Can I therefore load a texture from a HBITMAP.
    I'm not sure what you're trying to say here. What exactly do you do that causes you to see just the first line in a texture? Also, is the rest of the texture black, or random data, or is it valid pixels but in the wrong places? (If you don't use glPixelStore, and the width you pass glTexImage is 1/3 the source width, every third line in the texture should be a consecutive line from the correct portion of the source, with the other lines being from portions to the side of the one you want.)

    I'm not familiar with any of the classes you're using, or HBITMAP. I'm just assuming that however you get the image, you have access to a standard row-major 2d array of pixel data.

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2004
    Posts
    6

    Re: Loading Textures

    Thanks for your help, I'll read up some more to better understand all facets of the image. THe raw data part and th opengl part, the problem may be coming from the image manipulation than OGL itself.

    If ever you come up with a suggestion on how this is done it will be welcomed.

    Thanks
    Marc

  7. #7
    Member Newbie
    Join Date
    Jun 2001
    Posts
    43

    Re: Loading Textures

    And remember to use power-of-two sized textures. So your 300x300 texture should actually be 384x384 (=128x3):

    glPixelStorei(GL_UNPACK_ROW_LENGTH, 12;
    glTexImage2D(GL_TEXTURE_2D, 0, image.getChannels(), image.getWidth()/3, image.getHeight()/3,
    0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image.getLinePtr(0));

Similar Threads

  1. Image Loading Library for loading image textures
    By jitendra2896 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-03-2017, 12:13 AM
  2. loading tga textures
    By Riuzaki90 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-20-2012, 10:16 AM
  3. loading textures
    By xorek in forum OpenGL: User Software
    Replies: 0
    Last Post: 06-14-2004, 03:40 AM
  4. Loading DDS textures
    By d-slut in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-20-2003, 02:41 PM
  5. textures loading in c++
    By lara in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-02-2002, 12:48 PM

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