访问 ogre 中的视口像素值

发布于 2024-12-13 02:45:36 字数 141 浏览 7 评论 0原文

我正在使用 C++ 开发 ogre 项目。通常我使用 viewport:setbackground() 但这会导致整个窗口颜色相同。这次我想为每个视口的像素加载不同的 R、G、B 值。我的窗口是 600*600,我必须加载每个像素的 RGB 值。我该如何解决这个问题?

I'm working on ogre project by using C++. Normally I use viewport:setbackground() but this cause whole window same colour. This time I want to load different R, G, B values for each viewport's pixel. My window is 600*600 and I have to load RGB values for each pixel. How can I solve this question ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白日梦 2024-12-20 02:45:36

如果要设置背景,可以执行以下操作:

创建一个填充所有视口的矩形

Rectangle2D* rect = new Rectangle2D(true);
rect->setCorners(-1.0, 1.0, 1.0, -1.0);
rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
rect->setBoundingBox(AxisAlignedBox(-100000.0 * Vector3::UNIT_SCALE, 100000.0 * Vector3::UNIT_SCALE));
SceneNode * node = sceneManager->createChildSceneNode("Background");
node->attachObject(rect);

创建材质和纹理

TexturePtr texture = TextureManager::getSingleton().createManual("BackgroundTex", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 600, 600, 0, PF_R8G8B8, TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
MaterialPtr material = MaterialManager::getSingleton().create("BackgroundMat", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Technique* technique = material->createTechnique();
technique->createPass();
technique->getPass(0)->setLightingEnabled(false);
technique->getPass(0)->createTextureUnitState("BackgroundTex");
rect->setMaterial("BackgroundMat");

现在您可以将 RGB 数据直接复制到纹理帧缓冲区:

texture->getBuffer()->blitFromMemory(PixelBox(600, 600, 1, PF_R8G8B8, (void*) data));

编辑 2011-11-10

< strong>data 必须是指向原始 RGB 帧缓冲区的有效指针。您可以初始化它:

unsigned char* data = new unsigned char[600 * 600 * 3];

然后将黄色直接写入位置 x,y 处的像素。

unsigned char* red = &data[(x + y * width) * 3];
unsigned char* blue = &data[(x + y * width) * 3 + 1];
unsigned char* green = &data[(x + y * width) * 3 + 2];
*red = 255;
*blue = 0;
*green = 255;

或者直接写入 texture->getBuffer() ( Ogre API:HardwarePixelBuffer)

unsigned char* data = (unsigned char*)texture->getBuffer()->lock();

...直接写入pixelbuffer ...

texture->getBuffer()->unlock();

这个例子可以推广到其他宽度、长度、格式等...
您可以使用更优化的代码来查找缓冲区内的像素,这只是一个示例。

If you want to set a background you can do this:

Create a rectangle that fill all viewport

Rectangle2D* rect = new Rectangle2D(true);
rect->setCorners(-1.0, 1.0, 1.0, -1.0);
rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
rect->setBoundingBox(AxisAlignedBox(-100000.0 * Vector3::UNIT_SCALE, 100000.0 * Vector3::UNIT_SCALE));
SceneNode * node = sceneManager->createChildSceneNode("Background");
node->attachObject(rect);

Create a material and texture

TexturePtr texture = TextureManager::getSingleton().createManual("BackgroundTex", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 600, 600, 0, PF_R8G8B8, TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
MaterialPtr material = MaterialManager::getSingleton().create("BackgroundMat", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Technique* technique = material->createTechnique();
technique->createPass();
technique->getPass(0)->setLightingEnabled(false);
technique->getPass(0)->createTextureUnitState("BackgroundTex");
rect->setMaterial("BackgroundMat");

Now you can copy your RGB data directly to texture framebuffer:

texture->getBuffer()->blitFromMemory(PixelBox(600, 600, 1, PF_R8G8B8, (void*) data));

EDIT 2011-11-10

data must be a valid pointer to a framebuffer of raw RGB. You can initialize it:

unsigned char* data = new unsigned char[600 * 600 * 3];

And than write yellow directly to pixel at position x,y.

unsigned char* red = &data[(x + y * width) * 3];
unsigned char* blue = &data[(x + y * width) * 3 + 1];
unsigned char* green = &data[(x + y * width) * 3 + 2];
*red = 255;
*blue = 0;
*green = 255;

Or write directly to texture->getBuffer() (Ogre API: HardwarePixelBuffer)

unsigned char* data = (unsigned char*)texture->getBuffer()->lock();

... write directly to pixelbuffer ...

texture->getBuffer()->unlock();

This example can be generalized for other width, length, format etc...
You can use more optimized code to find pixel inside the buffer, this is just an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文