OpenGL-特定深度的像素颜色 [英] OpenGL - Pixel color at specific depth

查看:77
本文介绍了OpenGL-特定深度的像素颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从gluOrtho角度看,我已经在OpenGL中渲染了3D场景.在我的应用程序中,我正在查看体积为100x70x60mm(我为1000x700x600像素)的立方体的正面.在此立方体内部,我绘制了一个简单的蓝色球体,该球体恰好位于中间,并且填充"了立方体(半径为300像素).

I have rendered a 3D scene in OpenGL viewed from the gluOrtho perspective. In my application I am looking at the front face of a cube of volume 100x70x60mm (which I have as 1000x700x600 pixels). Inside this cube I have rendered a simple blue sphere which sits exactly in the middle and 'fills' the cube (radius 300 pixels).

我现在想读取立方体内特定点的像素的颜色值(以3D表示);即我想知道说点(100,100,-200)是蓝色还是空白(黑色).

I now want to read the color value of pixels (in 3D) at specific points within the cube; i.e. I wish to know if say point (100,100,-200) is blue or blank (black).

glReadPixels只允许2D提取颜色,我已经用DEPTH_COMPONENT尝试过,但是不确定这应该以字节形式返回什么?有没有办法将两者结合起来?我想念什么吗?

glReadPixels only allows 2D extraction of color and I have tried it with the DEPTH_COMPONENT but am unsure what this should return in byte form? Is there a way to combine the two? Am I missing something?

我正在将Eclipse与Java和JOGL一起使用.

I am using Eclipse with Java and JOGL.

推荐答案

您并不是第一个因这种误解而堕落的人,因此我说的是最直截了当的方式:OpenGL不能那样工作. OpenGL never(!)处理对象或任何复杂的场景. OpenGL唯一了解的是帧缓冲区,着色器和单个三角形.每当您绘制通常由三角形组成的对象时,OpenGL一次只会看到每个三角形.并且一旦将某些内容吸引到帧缓冲区,以前丢失的内容都会丢失.

You're not the first to fall for this misconception, so I say it the most blunt way possible: OpenGL doesn't work that way. OpenGL never(!) deals with objects or any complex scenes. The only thing OpenGL knows about are framebuffers, shaders and single triangles. Whenever you draw an object, usually composed of triangles, OpenGL will only see each triangle at a time. And once something has been drawn to the framebuffer, whatever has been there before is lost.

有一些基于光栅化器概念的算法(例如OpenGL是),可以将渲染的场景分解为各个部分,深度剥离就是其中之一.

There are algorithms based on the concepts of rasterizers (like OpenGL is) that decompose a rendered scene into it's parts, depth peeling would be one of them.

这篇关于OpenGL-特定深度的像素颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆