【发布时间】:2014-04-27 19:32:56
【问题描述】:
我目前正在创建一个 iOS 应用,但我无法理解从 ofGrabber 获取像素与使用 ofTexture 绘制它们之间的关系。
我当前的代码:
在 setup() 中:
//Set iOS orientation
ofSetOrientation(OF_ORIENTATION_90_LEFT);
//Inits the camera to specified dimensions and sets up texture to display on screen
grabber.initGrabber(640, 480, OF_PIXELS_BGRA); //Options: 1280x720, 640x480
//Allocate opengl texture
tex.allocate(grabber.width, grabber.height, GL_RGB);
//Create pix array large enough to store an rgb value for each pixel
//pix is a global that I use to do pixel manipulation before drawing
pix = new unsigned char[grabber.width * grabber.height * 3];
在更新()中
//Loads the new pixels into the opengl texture
tex.loadData(pix, grabber.width, grabber.height, GL_RGB);
在draw()中:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGSizeMake screenSize = CGSizeMake(screenBounds.size.width, screenBounds.size.height);
//Draws the texture we generated onto the screen
//On 1st generation iPad mini: width = 1024, height = 768
tex.draw(0, 0, screenSize.height, screenSize.width); //Reversed for 90 degree rotation
我在想什么:
1) 为什么 ofGrabber 和 ofTexture 使用看似不同的像素格式? (这些格式与 VideoGrabberExample 中使用的格式相同)
2) 以分辨率绘制的纹理究竟是什么?我正在将 pix 数组加载到纹理中。 pix 数组表示一个 640x480 的图像,而 ofTexture 将一个 1024x768(旋转时为 768x1024)的图像绘制到屏幕上。它是如何做到的?由于纵横比基本相同,它是否只是放大所有内容?
3) 是否有描述 OpenGL 和 OpenFrameworks 像素格式的列表?我已经搜索过这个,但没有找到太多。例如,为什么是 OF_PIXELS_BGRA 而不是 OF_PIXELS_RGBA?就此而言,如果我正在捕获 BGRA 格式的数据(我假设其中包含一个伽玛值),但我只绘制 RGB (你可以看到我的像素数组的大小适合 RGB 数据),为什么我的代码甚至可以工作。
我可能还会提到在 main() 中我有:
ofSetupOpenGL(screenSize.height, screenSize.width, OF_FULLSCREEN);
但是,更改上面的宽度/高度值似乎对我的应用没有任何影响。
【问题讨论】:
标签: ios opengl-es rgb video-capture openframeworks