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 3 of 3

Thread: [SOLVED]- Uploading a grayscale image to OpenGL

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    [SOLVED]- Uploading a grayscale image to OpenGL

    Hi all,
    I m using opengl3.3 core profile. Previously for loading an 8bit image, I would simply call
    Code :
    glTexImage2D(GL_TEXTURE_2D,0,GL_INTENSITY,w,h,0,GL_LUMINANCE, GL_UNSIGNED_BYTE, pData)
    and it worked out fine.

    I just see the latest specs and both GL_INTENSITY and GL_LUMINANCE are deprecated and thus the error bit is set in the forward compatible context. My question is what is the replacement of these? I can put my data in red/green/blue channel using GL_[RED,GREEN,BLUE] format but it comes out in colors (red/green/blue resp.). Do i need to explicity generate the other two components also with the same value and pass it using GL_RGB? or is there another alternate which accepts the single intensity value so that i dont have to replicate the two channels needlessly?
    Regards,
    Mobeen

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: Uploading a grayscale image to OpenGL

    Nevermind I got it. I can use a single channel (GL_RED for instance to pass the data to this channel only) and in shader assign it to the remaining channels like this.
    Code :
    vFragColor.rgb = texture(textureMap,uv).rrr;
    Regards,
    Mobeen

  3. #3
    Intern Contributor
    Join Date
    Jul 2010
    Posts
    74

    Re: Uploading a grayscale image to OpenGL

    Reference for people reading this:
    ARB_texture_swizzle

    Also allows the equivalent behaviour of GL_INTENSITY and GL_LUMINANCE without adding extra code to the shader.

    It also allows the texture fetch hardware to do the swizzle rather than adding extra operations to the compiled shader.

Posting Permissions

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