首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用AntiAliasing在OpenGL中选色?

用AntiAliasing在OpenGL中选色?
EN

Stack Overflow用户
提问于 2011-05-25 10:13:09
回答 2查看 1K关注 0票数 3

我在OpenGL的选色和抗混叠方面有问题。当AA被激活时,glReadPixels的结果在目标边缘和目标交叉点上明显错误。例如:

我在一个框#32 (RGBA: 32,0,0,0)附近呈现一个框#28 (RGBA: 28,0,0,0)。使用AA,我可能得到一个错误的ReadPixel值(例如30),其中立方体和三角形重叠,或14的值在框边,由于AA算法。

我有大约4000件物品,我需要能够挑选(这是一个拼图游戏)。能够根据形状选择物体是非常重要的。

我尝试过用glDisable(GL_MULTISAMPLE)禁用AA (GL_MULTISAMPLE),但是它不适用于某些AA模式(我读到它依赖于AA实现- SS,MS,CS .)

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

  1. 一种使用不同缓冲区甚至呈现上下文的临时禁用AA?
  2. 的方法?
  3. 还有其他建议吗?
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-25 11:30:40

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

票数 7
EN

Stack Overflow用户

发布于 2015-04-12 09:51:15

我使用这个黑客:选择不只是一个像素,而是所有的3x3=9像素周围的采摘点。如果他们是一样的,我们是安全的。否则,它一定是在紧张,我们可以跳过这一点。

代码语言:javascript
复制
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
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6122791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档