Results 1 to 7 of 7

Thread: run through a texture

  1. #1

    run through a texture


    I would like to know if its possible to run through a texture stored in an AUX_RGBImageRec type, to access the single pixels of it.
    I want to add some kind of color-keying to my textures through setting pixels with a special color-value to an 0-alpha-value.

    I took the Nehe Lesson 6 for loading Textures.

    Can you help me?

  2. #2

    Re: run through a texture

    marco, it is possible. if you peek inside GLAux.h, you'll see a structure like this:

    Code :
    typedef struct _AUX_RGBImageRec {
        GLint sizeX, sizeY;
        unsigned char *data;
    } AUX_RGBImageRec;
    since aux is no longer documented in .net 2k3, and since i have never personally used this structure (or aux for that matter), i make no guarantess about the following code.

    assuming you have successfully loaded your image with auxDIBImageLoad, you can plow through the bits with this:

    Code :
    unsigned char* data = image->data;
    for( int y = 0; y < image->sizeY; y++ )
        for( int x = 0; x < image->sizeX; x++ )
            // get or set here
            unsigned char red   = data[0];
            unsigned char green = data[1];
            unsigned char blue  = data[2];
            // advance to next rgb triple
            // !!! assumes packed rgb
            data += 3; 

  3. #3

    Re: run through a texture

    Thank you very much for your answer... I'll try it that way.

  4. #4

    Re: run through a texture

    Sorry for double-posting, just wanted to say that it worked great. I got it after a while
    Thank you for your help.

    However I've another question
    I want to make it possible to load non-squared textures like 140x60 pixels, instead of 128x128... I think it works when I load the .bmp and copy it to a 128x128 texture, and the fill-up the empty parts with black. I think it should be no problem to code, however here are to questions:

    - How can I check the nearest square-size to the size of the bitmap... eg, how can I tell my code that a 256x256 pixel-texture should be created when there's a 210x280 pixel bitmap?

    - How can I set the texture-coordinates to a QUAD that it gets only textured with the part of the texture that is filled?

    If you want to know why I need it: I'm coding a 2D-engine with OpenGL, and I want that I can load free-sized bitmaps
    I set up the orthographic mode, so one coordinate-unit is 1 pixel.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Feb 2004
    Long Island, New York

    Re: run through a texture


    rather than scaling your images to power of two dimensions you can use texture rectangles which allow textures of arbitrary dimensions.
    check out:

    using this approach you also eat up less texture memory for your textures (generally).
    there are some limitations (no GL_REPEAT texture mode for one)...

    if you decide to use power of two textures you can adapt the code below to find the nearest power of two given the native resolution of the image

    Code :
    int nextPow2(int i)
      //get to the nearest power of two dimension 
      //less than i.
      int pow2 = 2;
      while(pow2 < i)
         pow2 *= 2;
      //deterimine if we scale up or down now:
      //find the power of two which is closest to
      //native size
      if(abs(i-pow2) < abs(i-(pow2*2)))
         return pow2
      return pow2*2;

  6. #6

    Re: run through a texture

    hey marco, glad it worked out for you!

    yeah, i would do as aeluned suggested. then to get your coords to fit the actual image area, i'd use the coverage percentage.

    as per your example:

    width = 210;
    pow2width = 256;
    texture_s = 210 / 256;

    height = 280;
    pow2height = 512;
    texture_t = 280/512;

  7. #7

    Re: run through a texture

    Thank your for all your friendly help.
    I could do big progresses through it.

Similar Threads

  1. Replies: 1
    Last Post: 12-26-2014, 04:57 PM
  2. Replies: 1
    Last Post: 03-10-2014, 12:51 PM
  3. Replies: 2
    Last Post: 09-27-2004, 05:25 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