English 中文(简体)
冰川碎裂使物体成为物体 ID
原标题:glsl fragmentshader render objectID
  • 时间:2012-05-12 10:56:55
  •  标签:
  • opengl
  • glsl

我如何妥善地将物体的分类格身份证明为愤怒的缓冲物?

我有一份案文2D,其内部格式是GL_LUMINomp16,并附上该文本作为我的联邦组织附属物。

在提出标的时,即向梯子传递一个愤怒的身份证,并愿将这种假象带入我的愤怒文本。

fragmentshader output is of type vec4 however. How do I properly transform my ID to four component float and avoid conversion inaccuracies such that in the end the integervalue in my integer texture target corresponds to the integer ID i wanted to render?

最佳回答

你的问题有几个问题。

首先,GL_LUMINRC16。 这是一种包含热化<>/em>不签名的立体值的案文。 它利用分类账代表范围上的浮动[0、1]。 如果你想储存实际的分类,你必须使用实际的integer 图像格式

第二,你不能给人一种精彩的文本;它们不是有色的。 如果你真想给单一渠道的文本,那么你就必须建立一个单一渠道图像格式。 因此,你不使用<代码>GL_LUMINRC16,而是使用GL_R16UI,该编码为16-bit one-channel unsign organic culture格式。

现在,你们的这种安排是正确的,很奇怪。 界定<条码>uint 碎块/薄块,且其具有碎块的斜体字面值。 www.un.org/spanish/ecosoc 可能来自透镜或穿制服;然而,你希望这样做。

显然,你还需要附上你的案文,或向一个财务机构提出,但我确信你知道这一点。

最后一件事:除非你指

问题回答

我仍不认为这里有明确答案。 因此,我是如何通过2D案文开展工作的:

// First, create a frame buffer:
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);

// Then generate your texture and define an unsigned int array:
glGenTextures(1, &textureid);
glBindTexture(GL_TEXTURE_2D, textureid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, w, h, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

// Attach it to the frame buffer object:
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, textureid, 0);

// Before rendering    
glBindFramebuffer(GL_FRAMEBUFFER, fbo);    
GLuint buffers[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; // this assumes that there is another     texture that is for the render buffer. Color attachment1 is preserved for the element ids.
glDrawBuffers(2, buffers);

// Clear and render here
glFlush(); // Flush after just in case
glBindFramebuffer(GL_FRAMEBUFFER, 0);

在全球生命线一侧,碎裂层应当有(这里有4.3条核心特征代码):

layout(location = 0) out vec4 colorOut; // The first element in  buffers  so location 0    
layout(location = 1) out uvec4 elementID; // The second element in  buffers  so location 1. unsigned int vector as color

// ...
void main()
{
//...

elementID = uvec4( elementid, 0, 0, 0 ); // Write the element id as integer to the red channel.

}

You can read the values on the host side:

unsigned int* ids = new unsigned int[ w*h ];
glBindTexture(GL_TEXTURE_2D, textureid);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, ids);




相关问题
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 ...

热门标签