Results 1 to 7 of 7

Thread: Creating white texture.

  1. #1
    Junior Member Newbie rnodal's Avatar
    Join Date
    Jun 2008
    Posts
    24

    Creating white texture.

    Hello,
    I'm trying to create an empty texture(white actually) and this is what I'm doing.

    Code :
    data = (unsigned int*)new GLuint[((width * height)* 4 * sizeof(unsigned int))];
    ;
     
            for(int i = 0; i < (int)(width * height * sizeof(unsigned int) * 4); i++)
            {
                data[i] = 256;
            }
     
            // Generate white OpenGL texture.
            GLuint whiteTextureID;
            glGenTextures(1, &amp;whiteTextureID);
            glBindTexture(GL_TEXTURE_2D, whiteTextureID);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    What I don't understand is why when I texture a quad with this texture the quad does not render. Is there anything that I'm overlooking? I would like to get into creating my own textures by making each pixels myself so I figured that making a white texture would be a good start. Any help is really appreciated.

    Thanks,

    -r

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: Creating white texture.

    You write it in memory as integers with value 0x00000100 into a width*height*16 bytes-sized array, and tell OpenGL your data is GL_UNSIGNED_BYTE in a 4 times smaller array.
    You're sending a RGBA value of {0,1/255,0,0}


    You need to do this instead:

    data = new unsigned char[width * height* 4];
    for(int i = 0; i < width * height * 4; i++)data[i] = 255;

  3. #3
    Junior Member Newbie rnodal's Avatar
    Join Date
    Jun 2008
    Posts
    24

    Re: Creating white texture.

    Here is the revised code but still I can't see my quad. This issue is really bothering me.
    Code :
    unsigned char* data;
     
     
            // Allocate the needed space.
            int width;
            int height;
            width = height = 128;
     
            data = new unsigned char[width * height * sizeof(unsigned char)];
     
            for(int i = 0; i < (int)(width * height * sizeof(unsigned char)); i++)
            {
                data[i] = 255;
            }
     
            // Generate white OpenGL texture.
            GLuint whiteTextureID;
            glGenTextures(1, &amp;whiteTextureID);
            glBindTexture(GL_TEXTURE_2D, whiteTextureID);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

    I don't get it.

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: Creating white texture.

    try internalFormat=GL_RGBA8 :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

    and your array-size is not width*height*1, it's width*height*4.

    I usually use (for now):
    gluBuild2DMipmaps(GL_TEXTURE_2D,4,wid,hei,GL_RGBA, GL_UNSIGNED_BYTE,data);

  5. #5
    Junior Member Newbie rnodal's Avatar
    Join Date
    Jun 2008
    Posts
    24

    Re: Creating white texture.


    OK, I'm very sorry. I really hate the fact that the problem was somewhere else. I'm using an special function just to render textures and there was a conflict between that function and another function. The states set in one were affecting the other so if one was used before the other then whatever the other was going to do did not work. Thanks for the help and sorry for wasting your time.

    P.S The code above was one of my random attempts. But I did really try your first solution and it works just fine. Thanks!

    -r

  6. #6
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: Creating white texture.

    np, it happens

  7. #7
    Junior Member Newbie rnodal's Avatar
    Join Date
    Jun 2008
    Posts
    24

    Re: Creating white texture.

    Just for the record. Another reason why it was failing was because I was creating the texture before the OpenGL was completely initialized. Noob mistakes .


    -r

Similar Threads

  1. How can I colorize a texture without losing white?
    By patrick99e99 in forum OpenGL: Basic Coding
    Replies: 34
    Last Post: 11-15-2016, 12:39 AM
  2. Depth texture issues - All white texture
    By Illiander in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-17-2014, 03:56 AM
  3. Creating a white outline around text texture Open-ES 2.0
    By Hank Finley in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 10-29-2013, 11:20 PM
  4. Texture only makes white square
    By paradoxresolved in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 09-27-2011, 01:58 PM
  5. White depth texture using FBO
    By Maire Nicolas in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-28-2010, 01:15 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