Results 1 to 4 of 4

Thread: How to split up a large texture ?

  1. #1
    Junior Member Newbie
    Join Date
    May 2001

    How to split up a large texture ?

    Here's the problem, I need to support very large textures for use as backgrounds in my application. The textures are usually aerial photos and sizes of 2000+ pixels are not uncommon. Also a 2^x ratio is not guaranteed.

    I know that the best solution to this problem would be to read the single large texture, split it up in to X manageable tiles (all of which conform to 2^x), bind each tile to a texture object and then draw the scene using the multiple tiles.

    My problem is how to split-up / scale the single large texture (says its size is 2000 x 2100) in to 16 smaller textures of say 512 x 512. I'm stuck on the actual process/code required to split up the one big image into several smaller tiles, I just can't get my head around it !

    Any help, links, code, are appreciated.


  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000

    Re: How to split up a large texture ?

    Code :
    for(y=0; y<512; y++)
      for(x=0; x<512; x++)
        subImage[x][y] = origImage[x+subStartX][y+subStartY]
    subStartX and -Y is the startoffset for the subimage.

    This will extract a 512x512 image from the original image. Just increase subStartX and -Y with 512 for each subimage you create.

  3. #3
    Junior Member Newbie
    Join Date
    May 2001

    Re: How to split up a large texture ?

    Ok is see what you mean here, but when I read in the image data from the texture file I use the code below to read and bind the image data to a texture object.

    void read_rgb_24bit(FILE *s, int width, int height)
    unsigned char *rgb;
    unsigned char temp;
    int bread;
    int i;
    int size = width*height;

    rgb = malloc_test(sizeof(int) * size * 3, "Texture Data", TextureMemTag);

    if (rgb == NULL) return 0;

    bread = fread (rgb, sizeof (unsigned char), size * 3, s);
    if (bread != size * 3)
    return 0;

    for (i = 0; i < size * 3; i += 3)
    temp = rgb[i];
    rgb[i] = rgb[i + 2];
    rgb[i + 2] = temp;

    TextureFormat = GL_RGB;

    bind_texture(1, width, height, TextureFormat, rgb);

    void bind_texture(int id, int pix_width, int pix_height, GLenum format,
    unsigned char *data)
    /* dull openGl stuff */
    glBindTexture(GL_TEXTURE_2D, id);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    /* scaling a streching */

    /* bind the texture */
    glTexImage2D(GL_TEXTURE_2D, 0, format, pix_width, pix_height,
    0, format, GL_UNSIGNED_BYTE, data);

    So my image data is in an unsigned char *rgb not a 2D char array. Maybe I don't understand how the image data is actually stored/used by openGL but how to I get from an unsigned char *rgb to the 'origImage[X][y]' in your code ? Then how to I get back to the unsigned char *data for binding from each 'subImage[x][y]' ?

    I think that this is the bit I'm struggling to understand. Then if you add in the need to scale/pad the 'origImage' data if the texture is not a power of 2, I'm really confused ?

    Any further help is appreciated,

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Fargo, ND

    Re: How to split up a large texture ?

    Converting the indices from a 2d array to a flat array is really pretty easy. It just takes a little bit of math. The basic formula would be this...

    index = ((y*width)+x)*3;
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. Spectrograph and large texture
    By spirox in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-19-2011, 11:30 AM
  2. what's the fastest way to upload large texture
    By finalpatch in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-17-2008, 12:21 PM
  3. texgen and large texture coord
    By imported_vince in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 06-06-2003, 10:48 AM
  4. large texture problem
    By Zorro0033 in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 10-12-2002, 08:39 PM
  5. Texture Mapping to split windows
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-02-2002, 01:13 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