Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Generating Textures

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2000
    Location
    Pendleton, SC, USA
    Posts
    19

    Generating Textures

    I am trying to build a 2x2 texture that is a solid color. This is the function I have been trying to use but it doesn't work. If I make the texture GL_RGBA and add a 4th alpha bit, it works fine. So what's up?


    void GLTexture::BuildColorTexture(unsigned char r, unsigned char g, unsigned char b)
    {
    unsigned char data[12];

    // Store the data
    for (int i = 0; i < 12; i+=3)
    {
    data[i] = r;
    data[i+1] = g;
    data[i+2] = b;
    }

    // Generate the OpenGL texture id
    glGenTextures(1, &texture[0]);

    // Bind this texture to its id
    glBindTexture(GL_TEXTURE_2D, texture[0]);

    // Use linear filters
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

    // Generate the texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
    }

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Sep 2000
    Location
    Santa Clara, CA
    Posts
    1,463

    Re: Generating Textures

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    ...should fix your problem. It's a common issue.

    - Matt

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2000
    Location
    spanaway, wa, usa
    Posts
    17

    Re: Generating Textures

    now where would you add that pixelstorei? gotta give specific info pls.
    "...gameplay is what counts..."

  4. #4
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: Generating Textures

    well anywhere before the last line glTexImage2D(..) should be ok

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •