- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
好的,所以我有了这个带有深度缓冲区和 4 种颜色附件的 FBO。我想读取光标所在位置的部门缓冲区和第四个颜色附件中的值。我似乎无法管理两者中的任何一个。我写了这个类:
class Picker3D{
public:
bool useAtachment;
GLenum atachment;
float PickerLastSignature;
point3f PickerLastPos;
Picker3D( bool useAtachment = true , GLenum atachment = GL_COLOR_ATTACHMENT3 ) : useAtachment(useAtachment) , atachment(atachment) {
}
void SetObjectSignature( float signature , GLSL_Prog prog ){
glUniform1f( glGetUniformLocation( prog.PR , "Signature" ) , signature );
}
float getSignature( float x , float y , float height ){
glGetError();
if( useAtachment )
glReadBuffer( atachment );
cout << " Error message1 : " << glGetError() << endl ;
float *pixels = new float[4];
glReadPixels( x , height - y , 1 , 1 , GL_RGB , GL_FLOAT , pixels );
PickerLastSignature = pixels[1];
cout << " Error message2 : " << glGetError() << endl ;
return PickerLastSignature;
}
point3f get3DPosition( float x , float y , float height ){
//glReadBuffer( GL_DEPTH_ATTACHMENT );
double depth;
glReadPixels( x , y , 1 , 1 , GL_DEPTH_COMPONENT , GL_FLOAT , &depth );
cout << depth << endl;
int viewport[4];
float *modelview;
double projection[16];
double ModelView[16];
modelview = mat4f::GetTopMatrix().returnTransposedMatrix().returnFloatArray();
for( int i = 0 ; i < 16 ; i++ ){
ModelView[i] = modelview[i];
}
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetIntegerv(GL_VIEWPORT, viewport);
double x1 , y1 , z1;
gluUnProject( x , height - y , depth , ModelView , projection , viewport , &x1 , &y1 , &z1 );
PickerLastPos = point3f( x1 , y1 , z1 );
return PickerLastPos;
}
};
我也是这样用的
//在主循环中
BindFrameBuffer();
drawStuff();
Picker.get3DPosition( x , y , height );
Picker.getSignature( x , y , height );
UnbindBuffer();
drawSecondPass();
endDrawSecondPass();
// check Values of PickerLastPos and PickerLastSignature
SwapBuffers();
深度没有改变,尽管它在屏幕上工作并且 getSignature 在 glReadBuffer 行给出错误 1282(无效操作,我认为)。
主循环是:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
/// deferred pass
DefFBO->drawFBO();
GeometryShader.UseNow();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
// load the view matrix and set the camera
cam.camera_set();
cam.camera_get( GeometryShader );
// load identity for model matrix
mat4f::LoadIdentity();
/// Geometry Drawing
mat4f::PushMatrix();
mat4f::Translate( 0 , 0 , -10 );
Picker.SetObjectSignature( 1.0f , GeometryShader );
T90.obj_rend( GeometryShader );
Picker.SetObjectSignature( 2.0f , GeometryShader );
Town.obj_rend( GeometryShader );
mat4f::PopMatrix();
Picker.get3DPosition( Window.Mouse->mouse_x , Window.Mouse->mouse_y , Window.Height );
/// setting the deferred read from buffer part
// last read from framebuffer
Picker.getSignature( Window.Mouse->mouse_x , Window.Mouse->mouse_y , Window.Height );
// unbind FBO
DefFBO->readFBO();
// use fragment shader, for lights and for post processing
FragmentShader.UseNow();
// send windows width and height and bind multiple textures
DefFBO->send_to_GLSL( FragmentShader.PR );
// send view matrix to the shader
cam.camera_get( FragmentShader );
glDepthMask(GL_FALSE);
glEnable(GL_DEPTH_TEST);
glUniform3f( glGetUniformLocation( FragmentShader.PR , "CameraPosition" ) , cam.x , cam.y , cam.z );
/// final draw
DefFBO->sendGlobalLight( FragmentShader , point3f( 0 , 1 , 0 ) , point3f( 0.3 , 0.3 , 0.3 ) , point3f( 0.9 , 0.9 , 0.9 ) );
cout << Picker.PickerLastPos << endl;
DefFBO->end_read();
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
最佳答案
正如@Andon 指出的那样,似乎我必须绑定(bind) fbo 以读取数据才能从中获取数据。我绑定(bind)了 GL DRAW FRAMEBUFFER。
关于c++ - 带有 FBO 附件的 glreadpixels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24272717/
我有一个具有两个线程的 Android OpenGL-ES 应用程序。将线程 1 称为“显示线程”,它将其当前纹理与来自线程 2 的纹理“混合”,也就是“工作线程”。线程 2 执行屏幕外渲染(渲染到纹
我正在使用 pyopengl 获取深度图。 我可以使用 glReadPixels() 获得标准化的深度图。如何将归一化值恢复为世界坐标中的实际深度? 我试过使用 glDepthRange(),但它总是
比如在片段着色器中 FragColor = vec4(TexCoords, MicrifiedCurrentPixelLevel, 0.5); notes:A'value is 0.5. 我想获得Fr
当我绘制一个点时,glReadPixels 不会立即更新。 glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_POINTS); glVertex2f(x,
我想使用 JOGL 保存我正在用 openGL 显示的视频。为此,我按如下方式将我的帧写入图片,然后,一旦我保存了所有帧,我将使用 ffmpeg。我知道这不是最好的方法,但我仍然不太清楚如何使用 te
我正在尝试使用 glReadPixels 从像素中获取数据。它工作了一段时间。但现在它停止工作了,我不知道为什么。 我需要制作Flood fill算法。 glBegin(GL_POINTS);
我正在使用代码渲染圆形渐变并通过触摸在渐变上创建十字准线( subview )。我现在想读取触摸位置的像素并让它返回 RGB 值,但它总是给我相同的值.. 编辑:添加了呈现渐变的代码 全新代码: vi
我尝试获取渲染像素的颜色。 gl.glColor3f(1f, 0, 0); //draw gl.glReadPixels(lastX - pw / 2, MyCanvas.this.getHeight
我就开门见山了:) 从上面的 480 x 320 图中,我想我可以像蠕虫游戏一样检测像素级别的碰撞。 我想知道的是如何对不同图层上的像素进行采样。正如您在图中看到的,当蠕虫下落时,我只想使用 glRe
经过一个多小时的寻找答案(尝试 Munshi 的“OpenGL ES 2.0 编程指南”中的内容、搜索 Apple 的文档、搜索 StackOverflow),我仍然对如何让 glReadPixels
当我将我的场景渲染到屏幕上时,场景使用了 _MultiSampling Anti-Aliasing 8x; 没问题。 但我想通过 glReadPixels() 读取像素缓冲区,我有一个带有别名线的别名
我正在尝试读取屏幕上绘制的矩形的颜色,但是当我尝试从坐标读取时,它似乎是从一个偏移量读取的,但这个偏移量并不一致。 (我正在使用 SDL2 库以防有帮助)我发现它正在反转坐标,例如如果 y 为 0,则
我使用 JOGL 来处理 OpenGL,但无法获取像素颜色。方法 glReadPixels() 始终返回一个全零的数组。 这就是我的使用方式: private static GL2 gl; stati
我正在尝试通过使用带有 C++ 代码的 glReadPixels 选择两个点(对角)来读取一个像素矩形。选择 Y 轴值时出现问题。 目前,我设法让 glReadPixels 工作直到缩放。当您放大(放
我遇到了 glReadPixels 无法读取颜色附件的问题。 我正在尝试做的事情: 读取非默认帧缓冲区的第三种颜色附件(下面的代码) glFlush(); glFinish(); //binds my
我有一个可以在显示器上渲染的 3d 场景。但是,除了渲染它以显示之外,我还希望能够将渲染的场景导出为图像(比如每 100 帧一次)(比如 JPG 或 PNG 图像),也许将其保存为文件保存在我的某个地
目前我的视口(viewport)上是: 这是我导出图片的方法。 void exportImage() { int width = 200; int height = 100; GLubyt
下面的代码工作正常 const char *title = "glReadOutput"; Mat out1, out2; out1.create(screenHeight,screenWidth,
我是 OpenGL 和 C++ 的新手,最近一直在尝试从我渲染的窗口中提取深度值。我注意到了一些有趣的事情,但我似乎无法弄清楚为什么会这样。 如果我使用与我的窗口大小匹配的“宽度”和“高度”值调用 g
我正在使用 glReadPixels 在 GLSurfaceView.Renderer 的 drawFrame 方法中定期拍摄快照。我需要定期拍摄此快照,以根据我的应用程序要求继续保存我的数据。 但是
我是一名优秀的程序员,十分优秀!