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 7849947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:41:41+00:00 2026-06-02T18:41:41+00:00

This might appear as a related question: OpenGL ES 2.0 Object Picking on iOS

  • 0

This might appear as a related question:

OpenGL ES 2.0 Object Picking on iOS

Which says Color picker is a good solution, and in deed after reading about it:

http://www.lighthouse3d.com/opengl/picking/index.php?color1

It does seem like a very simple solution so this brings me to this question

OpenGL ES color picking on the iPhone

Which unfortunately uses opengl es 1.0, I am trying to do it in 2.0 so I have no access
to the functions described in that question.

But the theory seems simple and here is what I think I should do:

On touches begin I render my objects with a unique color.

On touches ended I get the pixel from that position and check it for the color
to get my object. (probably with glReadPixels)

The problem is that I dont know how to do the “Render to the back buffer and read from it”.

My code so far simply uses “Draw”, I suspect I have to do something like glBindthe other buffer but I would appreciate some help.

My Drawing code is like this:

glClearColor(0, 0, 0, 0.0); 
glClear(GL_COLOR_BUFFER_BIT);

// Set the Projection Matrix
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(60), 2.0/3.0, 0, 50);


glUseProgram(_programHD);

glBindVertexArrayOES(_vao);

glActiveTexture(GL_TEXTURE1); 
glBindTexture(GL_TEXTURE_2D, _textureBuffer[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glUniform1i(uniforms[UNIFORM_TEXTURE_HD], 1);

// Drawing starts here //

// Pass the Model View Matrix to Open GL
_modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix,rotationMatrix);

glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX_HD], 1, GL_FALSE, _modelViewProjectionMatrix.m);

// Change texture coordinates to draw a different image

glUniform2fv(uniforms[TEXTURE_OFFSET_HD], 1, offSet.v);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);

//glUniform2i(uniforms[TEXTURE_OFFSET], 7, -5);
glUniform2fv(uniforms[TEXTURE_OFFSET_HD], 1, borderHD.v);

glDrawElements(GL_LINE_STRIP, 6, GL_UNSIGNED_SHORT, 0);



glBindVertexArrayOES(0);
glUseProgram(0);

I have stripped the drawing calculations to make it more understandable.
The point is I do not see anywhere where I specify to “where” am i drawing.

Thanks for your help.

  • 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-02T18:41:43+00:00Added an answer on June 2, 2026 at 6:41 pm

    I’ve actually just finished implementing a colour picking function into my iPhone game, using openGL ES 2.0, using the lighthouse tutorial funny enough.

    You should be drawing to the frame buffer.

    If you want to read from the frame buffer, then you’re correct in that you want to use glReadPixels. More information is here:

    http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml

    The only thing that’s different from the lighthouse tutorial is that you also want to store the alpha values.
    Here’s a quick function to get the colour of a specific pixel. Feel free to improve it or change it, but it does the job.

    + (void) ProcessColourPick : (GLubyte*) out : (Float32) x : (Float32) y
    {
        GLint viewport[4];
        //Get size of screen
        glGetIntegerv(GL_VIEWPORT,viewport);
    
        GLubyte pixel[4];
        //Read pixel from a specific point
        glReadPixels(x,viewport[3] - y,1,1,
                 GL_RGBA,GL_UNSIGNED_BYTE,(void *)pixel);
    
        out[0] = pixel[0];
        out[1] = pixel[1];
        out[2] = pixel[2];
        out[3] = pixel[3];
    }
    

    Hope this helps.

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

Sidebar

Related Questions

This might seem like a stupid question I admit. But I'm in a small
This might be an interesting question. I need to test that if I can
This might sound like a little bit of a crazy question, but how can
This might be an odd question, but when I scale my image in C#
This question is rather agnostic than related to a certain version control program. Assume
Possibly related to my last question (note: different error code): Why might the fatal
this might look silly to you but I am stuck here . I have
This might sound silly, but my umbraco 5.1 application (after upgrading from 5.0) simply
This might be a very simple thing for you gurus, but I'm not familiar
This might be on the discussy side, but I would really like to hear

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.