glreadpixels

Implementing render-to-vertex-array, glReadPixels fails (invalid operation)

孤者浪人 提交于 2019-12-04 13:21:10
I'm trying to copy vertex data from a texture to a vertex buffer, and then draw the vertex buffer. As far as I know the best way to do this is to bind the texture to a fbo, and use glReadPixels to copy it to a vbo. However, I can't seem to get this working: glReadPixels fails with the error "invalid operation". Corrections, examples and alternate methods welcome. :) Here's the relevant code: glEnable(GL_TEXTURE_2D) w, h = 32, 32 vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) glBufferData(GL_ARRAY_BUFFER, sizeof(c_float)*w*h*4, None, GL_STREAM_COPY) glBindBuffer(GL_ARRAY_BUFFER, 0)

glReadPixel stopped working with iOS6 Beta [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-04 10:13:11
This question already has answers here : Closed 7 years ago . Possible Duplicate: Why is glReadPixels() failing in this code in iOS 6.0? I currently have an App in Appstore that uses the Cocos2D framework. For collision detection I am using glReadPixels. The screen only has white and black pixels and detecting a black pixel means collision. Everything works fine up to iOS 5.1.1 but in iOS6 Beta (all of them) glReadPixels stopped working. Now the RGB values returned by glReadPixels are always 0,0,0. Does anyone have an idea what went wrong or how to fix that? Your help is much appreciated!

How to take screenshot in OpenGL

旧巷老猫 提交于 2019-12-02 10:26:28
How to take a screenshot of an OpenGL window in C++ and save it to file. I found the glReadPixels() function, but I don't know what to do next. Where I can set path to a file, for example? If not difficult, write code, please. huy This piece of code captures the OpenGL window and export to a BMP file. You must have FreeImage library to run it. // Make the BYTE array, factor of 3 because it's RBG. BYTE* pixels = new BYTE[3 * width * height]; glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); // Convert to FreeImage format & save to file FIBITMAP* image = FreeImage

how to use glreadpixels with android — usually get zeros

落爺英雄遲暮 提交于 2019-12-01 10:33:42
I'm trying to detect the opengl object under the cursor... I have read it referred to as picking. Here is my code: public int makeBuffer(GL10 gl, int x, int y) { ByteBuffer PixelBuffer = ByteBuffer.allocateDirect(4); PixelBuffer.order(ByteOrder.nativeOrder()); PixelBuffer.position(0); int mTemp = 0; gl.glReadPixels((int)x, (int) y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, PixelBuffer); Log.e("Picking", " xy: x" + x + " y"+ y); byte b [] = new byte[4]; PixelBuffer.get(b); Log.e("Picking", " rgba: r"+ PixelBuffer.get(0) + " g" + PixelBuffer.get(1) + " b" + PixelBuffer.get(2) + " a" +

how to use glreadpixels with android — usually get zeros

℡╲_俬逩灬. 提交于 2019-12-01 09:08:14
问题 I'm trying to detect the opengl object under the cursor... I have read it referred to as picking. Here is my code: public int makeBuffer(GL10 gl, int x, int y) { ByteBuffer PixelBuffer = ByteBuffer.allocateDirect(4); PixelBuffer.order(ByteOrder.nativeOrder()); PixelBuffer.position(0); int mTemp = 0; gl.glReadPixels((int)x, (int) y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, PixelBuffer); Log.e("Picking", " xy: x" + x + " y"+ y); byte b [] = new byte[4]; PixelBuffer.get(b); Log.e("Picking", "

How can I save OpenGL draw with OpenGL?

[亡魂溺海] 提交于 2019-12-01 08:07:42
问题 I draw a screen with OpenGL commands. And I must save this screen to .bmp or .png format. But I can't do it. I am using glReadpixels but I can't do continue. How can I save this drawing in c++ with OpenGL? 回答1: Here it comes! you must include WinGDI.h (which i think the GL will do it!) void SaveAsBMP(const char *fileName) { FILE *file; unsigned long imageSize; GLbyte *data=NULL; GLint viewPort[4]; GLenum lastBuffer; BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; bmfh.bfType='MB'; bmfh

Reading data using glReadPixel() with multisampling

浪子不回头ぞ 提交于 2019-11-30 17:22:06
问题 Presently I am trying to read the pixel data from the frame Buffer in order to capture the screen in IOS. GlreadPixels command works fine when using the following code to setup frame buffer :- //buffers // Create a depth buffer that has the same size as the color buffer. glGenRenderbuffersOES(1, &m_depthRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthRenderbuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT24_OES, width, height); // Create the

Android OpenGL ES 3.0 PBO instead of glReadPixels()

依然范特西╮ 提交于 2019-11-30 15:55:38
问题 I want to improve glReadPixels() performance using PBO (for GLES 3 devices) and I ran into a problem in this piece of code: final ByteBuffer pboByteBuffer = ByteBuffer.allocateDirect(4 * mWidth * mHeight); pboByteBuffer.order(ByteOrder.nativeOrder()); //set framebuffer to read from GLES30.glReadBuffer(GLES30.GL_BACK); // bind pbo GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, mPboHandleContainer[0]); // read pixels(should be instant) GLES30.glReadPixels(0, 0, mWidth, mHeight, GLES30.GL_RGBA

Android OpenGL ES 3.0 PBO instead of glReadPixels()

不羁的心 提交于 2019-11-30 15:22:28
I want to improve glReadPixels() performance using PBO (for GLES 3 devices) and I ran into a problem in this piece of code: final ByteBuffer pboByteBuffer = ByteBuffer.allocateDirect(4 * mWidth * mHeight); pboByteBuffer.order(ByteOrder.nativeOrder()); //set framebuffer to read from GLES30.glReadBuffer(GLES30.GL_BACK); // bind pbo GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, mPboHandleContainer[0]); // read pixels(should be instant) GLES30.glReadPixels(0, 0, mWidth, mHeight, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, pboByteBuffer); // map pbo to bb ByteBuffer byteBuffer = ((ByteBuffer)

Asynchronous glReadPixels with PBO

家住魔仙堡 提交于 2019-11-30 15:07:33
问题 I want to use two PBOs to read pixel in alternative way. I thought the PBO way will much faster, because glReadPixels returns immediately when using PBO, and a lot of time can be overlapped. Strangely there seems to be not much benefit. Considering some code like: glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); Timer t; t.start(); glReadPixels(0,0,1024,1024,GL_RGBA, GL_UNSIGNED_BYTE, buf); t.stop(); std::cout << t.getElapsedTimeInMilliSec() << " "; glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo)