将OpenGL纹理打印到文件而不显示? [英] Print an OpenGL Texture to File without Display?

查看:123
本文介绍了将OpenGL纹理打印到文件而不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenGL来帮助处理将Kinect深度图输入到图像中.目前,我们将Kinect用作基本的运动传感器,该程序会计算经过的人数,并在每次检测到新人时进行截屏.

I'm trying to use OpenGL to help with processing Kinect depth map input into an image. At the moment we're using the Kinect as a basic motion sensor, and the program counts how many people walk by and takes a screen shot each time it detects someone new.

问题是我需要让该程序运行而不需要访问显示器.我们希望通过SSH远程运行它,而来自其他服务的网络流量对于X11转发来说不是一个好主意.可以在运行程序的机器上附加显示器,但是出于能源消耗的原因,我们希望避免这样做.

The problem is that I need to get this program to run without access to a display. We're wanting to run it remotely over SSH, and the network traffic from other services is going to be too much for X11 forwarding to be a good idea. Attaching a display to the machine running the program is a possibility, but we're wanting to avoid doing that for energy consumption reasons.

程序确实为OpenGL生成2D纹理对象,并且通常只在读取像素之前使用GLUT渲染它,然后使用FreeImage将它们输出到.PNG文件.我遇到的问题是,一旦删除了GLUT函数调用,所有打印到.PNG文件的内容都只是黑匣子.

The program does generate a 2D texture object for OpenGL, and usually just uses GLUT to render it before a read the pixels and output them to a .PNG file using FreeImage. The issue I'm running into is that once GLUT function calls are removed, all that gets printed to the .PNG files are just black boxes.

我正在为Kinect使用OpenNI和NITE驱动程序.编程语言是C ++,由于目标设备的硬件限制,我需要使用Ubuntu 10.04.

I'm using the OpenNI and NITE drivers for the Kinect. The programming language is C++, and I'm needing to use Ubuntu 10.04 due to the hardware limitations of the target device.

我尝试使用OSMesa或FrameBuffer对象,但是我是一个完整的OpenGL新手,因此我没有获得OSMesa来代替GLUT函数正确渲染,并且我的编译器找不到任何OpenGL FrameBuffer函数在GL/glext.h或GL/gl.h中.

I've tried using OSMesa or FrameBuffer objects, but I am a complete OpenGL newbie so I haven't gotten OSMesa to render properly in place of the GLUT functions, and my compilers can't find any of the OpenGL FrameBuffer functions in GL/glext.h or GL/gl.h.

我知道纹理可以从图像文件读取到程序中,而我想要输出的只是一个2D纹理.在这种情况下,是否有一种方法可以跳过屏幕外渲染的麻烦,直接将纹理打印到图像文件而无需OpenGL首先渲染它?

I know that textures can be read into a program from image files, and all I want to output is a single 2-D texture. Is there a way to skip the headache of off-screen rendering in this case and print a texture directly to an image file without needing OpenGL to render it first?

推荐答案

OSMesa库既不能代替GLUT,也不能一起工作.如果只需要屏幕外渲染部分而不进行交互,则必须自己实现一个简单的事件循环.

The OSMesa library is neither a drop-in replacement for GLUT, nor can work together. If you only need the offscreen rendering part without interaction you have to implement a simple event loop yourself.

例如:

/* init OSMesa */
OSMesaContext        mContext;
void                *mBuffer;
size_t               mWidth;
size_t               mHeight;

// Create RGBA context and specify Z, stencil, accum sizes
mContext = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
OSMesaMakeCurrent(mContext, mBuffer, GL_UNSIGNED_BYTE, mWidth, mHeight);

此片段后,您可以使用常规的OpenGL调用进行渲染,并且在 glFinish()调用之后,可以通过 mBuffer 指针访问结果.

After this snipped you can use the normal OpenGL calls to render and after a glFinish() call the results can be accessed through the mBuffer pointer.

在事件循环中,您可以调用常规的 onDisplay onIdle 等回调.

In you event loop you can call your normal onDisplay, onIdle, etc callbacks.

这篇关于将OpenGL纹理打印到文件而不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆