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

  • Home
  • SEARCH
  • 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 8245345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:08:54+00:00 2026-06-07T22:08:54+00:00

I am trying to retrieve a color in OpenGL ES with glReadPixels. I set

  • 0

I am trying to retrieve a color in OpenGL ES with glReadPixels. I set my objects’ colors with float[], e.g. {0.0f,0.5f,0.2f,1.0f}
How can I convert the glReadPixels value to the same float[], since it’s unsigned byte?

Setting the color:

gl.glColor4f(color[0], color[1], color[2], color[3]);

Getting the color:

ByteBuffer buf = ByteBuffer.allocate(4);
buf.order(ByteOrder.nativeOrder());

gl.glReadPixels((int) mx, height - (int) my, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, buf);
byte result[] = buff.array();

I don’t know if this has been asked/answered already, but I just haven’t found a solution and I’ve been trying it for a good while.

  • 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-07T22:08:55+00:00Added an answer on June 7, 2026 at 10:08 pm

    The reason you get byte / 255.f = -0.0039 is because the byte you get from the bytebuffer is a signed value in java.

    While OpenGL returns the unsigned value 255 = 0xFF, java interprets this as signed, in which 0xFF = -1.

    Take the byte you get (result[0]), cast it to an int int resultInt = ((int)result[0]) & 0xFF, and then divide that by 255. You should get a value close to 1.

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

Sidebar

Related Questions

I'm trying to retrieve the attribute value from an xsl:param and use it in
i trying to retrieve value by referencing primary key in multiple tables but unable
I am trying retrieve objects with the following model Tools: last_calibration_date: Date period:Integer .
I am trying retrieve user name from the code through graph api, the below
I´m trying to retrieve the id of the object I've just introduced into the
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve this page using Apache HttpClient: http://quick-dish.tablespoon.com/ Unfortunately, when I try
Hi I am trying to retrieve values from database. I have a row which
I am trying to retrieve RSS feed using php. The xml has many different
I'm trying to retrieve a stored date in a MS Access 2003 database ..

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.