Results 1 to 3 of 3

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

  1. #1
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    [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
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    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
    Member Contributor
    Join Date
    Dec 2010
    Posts
    92

    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.

Similar Threads

  1. Attaching Grayscale Image to FrameBuffer object in OpenGL ES
    By Devikaelangovan in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-07-2016, 01:56 PM
  2. Uploading an image using DevIL: Linker errors
    By annette in forum OpenGL: Basic Coding
    Replies: 31
    Last Post: 02-01-2012, 08:37 AM
  3. DXTC image uploading issues
    By skynet in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 05-31-2008, 01:00 PM
  4. Grayscale image processing
    By axiao in forum OpenGL: Linux
    Replies: 0
    Last Post: 08-29-2005, 01:02 PM
  5. How to texture a RGB image in grayscale?
    By Klynn in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-09-2003, 02:10 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