1
\$\begingroup\$

Today I came across a tutorial about color picking and I implemented it on my machine. But there is a problem: when I disable the texture and draw the object I want to pick with its picking color, it turns to black (the first colorID) and then switches to the texture which I am placing on pick.

That is the case when I enable the textures after rendering the object. When I enable texturing before rendering my object, as in:

void MenuButton::Render(double windowWidth, double windowHeight)
{
    glEnable(GL_TEXTURE_2D);
    gui_OrthogonalStart(windowWidth, windowHeight);
        TextureManager::Inst()->BindTexture(gui_TextureID);
         glBegin(GL_QUADS);
            glTexCoord2f(0.0f, 1.0f); glVertex2f(gui_Position.GetX(), gui_Position.GetY() - 25.0f);
            glTexCoord2f(1.0f, 1.0f); glVertex2f(gui_Position.GetX() + 100.0f, gui_Position.GetY() - 25.0f);
            glTexCoord2f(1.0f, 0.0f); glVertex2f(gui_Position.GetX() + 100.0f, gui_Position.GetY());
            glTexCoord2f(0.0f, 0.0f); glVertex2f(gui_Position.GetX(), gui_Position.GetY()); 
         glEnd();
    gui_OrthogonalEnd();
}

Then the texture cannot be disabled and the color picking isn't working. I hope I explained it well. If the code provided in the link isn't enough tell me and I will post more.

Can this problem be solved in some way?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

If you want do it this way (render colors for color picking and use texture for texturing in one rendering), I think you have to use frame buffer objects or / and shaders.

You can use only frame buffers but you have to render your scene twice - first use only colors and store output image (render) to frame buffer, then draw scene normally (with textures) and use first render for color picking.

If you use shaders, you can store colors for picking (in frame buffer) and use texturing in the same time. But you have to write your own fragment (pixel) shader.

\$\endgroup\$
5
  • \$\begingroup\$ Well, I haven't dealt with shaders before, so I think I will stick to the FBOs. I will try it. \$\endgroup\$ Commented Jan 16, 2012 at 18:36
  • \$\begingroup\$ Is this way the solution to the problem? \$\endgroup\$ Commented Jan 16, 2012 at 18:52
  • \$\begingroup\$ Yes. It looks like solution. \$\endgroup\$ Commented Jan 16, 2012 at 19:54
  • \$\begingroup\$ You do have to render twice, but you don't necessarily need to store to frame buffer... you can render your picking color and read out the pixel(s) you want to pick, then clear the buffer and render the visible stuff. \$\endgroup\$ Commented Jan 17, 2012 at 11:19
  • \$\begingroup\$ Well, I am new to OpenGL. If you can tell me how to do it(maybe little dumb question of mine) I will appreciate it :) \$\endgroup\$ Commented Jan 17, 2012 at 18:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.