English 中文(简体)
OpenGL中使用消除混叠的颜色拾取?
原标题:Color picking with AntiAliasing in OpenGL?

我在OpenGL中遇到了颜色拾取和抗锯齿的问题。当AA被激活时,glReadPixels的结果在对象边缘和对象交叉点上显然是错误的。例如:

我在长方体#32(RGBA:32,0,0,O)附近渲染长方体#28(RGBA:28,0,0,0)。使用AA,由于AA算法,我可能会在立方体和三角形重叠的地方得到错误的ReadPixel值(例如30),或者在方框边缘得到值14。

我有大约40万件物品需要挑选(这是一款拼图游戏)。能够按形状选择对象是至关重要的。

我曾尝试使用glDisable(GL_MULTISAMPLE)禁用AA,但它不适用于某些AA模式(我读到它取决于AA实现-SS、MS、CS..)

那么,我该如何选择底层对象呢?

  1. A way do temporary disable AA?
  2. Using a different buffer or even rendering context?
  3. Any other suggestion?
最佳回答

为什么不使用FBO作为你的选择缓冲区?

问题回答

我使用这个技巧:不仅拾取一个像素,还拾取拾取点周围的所有3x3=9像素。如果他们都一样,我们就安全了。否则,它一定很紧张,我们可以跳过它。

int renderer::pick_(int x, int y)
{
    static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__,
            "only works on little-endian architecture");
    static_assert(sizeof(int) == 4,
            "only works on architecture that has int size of 4");

    // sort of edge detection. selection only happens at non-edge
    // since the edge may cause anti-aliasing glitch
    int ids[3*3];
    glReadPixels(x-1, y-1, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, ids);
    for (auto& id: ids) id &= 0x00FFFFFF;       // mask out alpha
    if (ids[0] == 0x00FFFFFF) return -1;        // pure white for background

    // prevent anti-aliasing glitch
    bool same = true;
    for (auto id: ids) same = (same && id == ids[0]);
    if (same) return ids[0];

    return -2;                                  // edge
}




相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签