Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:54:02+00:00 2026-06-18T04:54:02+00:00

I am using opengl ES2.0 to render 16bit greyscale data on Android. (I’m handling

  • 0

I am using opengl ES2.0 to render 16bit greyscale data on Android. (I’m handling 16bit to 8bit dynamic range scaling in the shader, the 16bit input is mandatory because it is incoming format of the data.) The resolution is 640×512.

At the moment I have this working by pushing pixels 2 at a time into a 320×512 32bit RGBA texture. i.e:

texture2D(thData, vTextureCoord)[0] is pixel i lower byte,

texture2D(thData, vTextureCoord)[1] is pixel i upper byte,

texture2D(thData, vTextureCoord)[2] is pixel i+1 lower byte,

texture2D(thData, vTextureCoord)[3] is pixel i+1 upper byte.

I am able to reconstruct the data from this but I have reconstruct the original resolution by rendering to a 640×512 buffer and using gl_FragCoord.x and a conditional statement to determine whether to draw the pixel from channels 0,1 or 2,3. The code looks like this:

 private final String mFragmentShader =
    "precision highp float;\n" + 
    "varying vec2 vTextureCoord;\n" +
    "uniform sampler2D thData;\n" +
    "void main() {\n" +

    //This works out whether the pixel is in an odd or even column:
    "int odd = 0;\n" +
    "if (fract(gl_FragCoord.x/2.) >= 0.5) odd = 2;\n"+

    //This chooses the channels based on the column number
    "float data =((texture2D(thData, vTextureCoord)[odd]) + (texture2D(thData, vTextureCoord)[odd+1]*256.))*256.;\n" +

This would be fine in principle but for some reason I get seem to be getting some columns swapped, my guess is that it could be rounding errors causing an incorrect result from the conditional statement.

What I’d like to do is avoid the down sampling by using a 16bit full resolution texture in the first place, this seems really simple; I have just changed the glTexImage2D code from:

GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 320, 512, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, sBuffer);

To

GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE_ALPHA, 640, 512, 0, GLES20.GL_LUMINANCE_ALPHA, GLES20.GL_UNSIGNED_BYTE, sBuffer);

However, when I do this I appear to be getting strange data in the texture. texture2D(thData, vTextureCoord)[0] appears to be correct but texture2D(thData, vTextureCoord)[1] has the same data as element 0, the upper byte of the pixel is nowhere to be seen.

Am I missing anything here?

Or can anyone suggest an alternative approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:54:03+00:00Added an answer on June 18, 2026 at 4:54 am

    GL_LUMINANCE_ALPHA textures replicate the first component across all x, y, and z components. The second component is in w, as the “ALPHA” part of the enum name implies. See the definition of GL_LUMINANCE_ALPHA format from: http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am programming an Android 2d game using opengl es 2.0. After I draw
Okay, so I'm using Rajawali (See: http://www.rozengain.com/blog/2011/08/23/announcing-rajawali-an-opengl-es-2-0-based-3d-framework-for-android/ ) to create a 3D sphere with
I am using OpenGL 2.0 on the android platform (Samsung Galaxy S2). When I
I'm using OpenGL for Android to draw my 2D images. Whenever I draw something
I am using openGL ES 2.0 and GLSL shader and working on FBO with
I am working on processing video using OpenGL ES 2.0 on Android. The picture
I'm trying to draw a quadrilateral using OpenGL ES 2.0. My vertex shader looks
I am using OpenGL ES 2.0 (on Android) to draw simple 2D scene has
I'm currently developing a game for Android using OpenGL ES 2.0. I have almost
I am developing a 2d game on Android ICS using OpenGL es 2.0 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.