如何使用GLUT / OpenGL渲染文件? [英] How to use GLUT/OpenGL to render to a file?

查看:163
本文介绍了如何使用GLUT / OpenGL渲染文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序模拟随时间变化的物理系统。我希望以预定的时间间隔(比如每10秒)将模拟状态的可视化输出到文件中。我想这样做很容易关闭可视化,并且根本不输出可视化文件。

我正在研究OpenGL和GLUT作为图形工具来做可视化。然而,问题似乎是,首先,它看起来只能输出到窗口,不能输出到文件。其次,为了生成可视化,您必须调用GLUTMainLoop并停止主函数的执行 - 从此开始调用的唯一函数是来自GUI的调用。不过,我不希望这是一个基于GUI的应用程序 - 我希望它只是一个从命令行运行的应用程序,它会生成一系列图像。有没有办法在GLUT / OpenGL中做到这一点?或者OpenGL是完全错误的工具,我应该使用其他的东西

解决方案

你几乎肯定不想要GLUT,不管。你的要求不符合它的目的(甚至当你的要求符合其预期目的时,你通常不希望它)。



你可以使用OpenGL。要在文件中生成输出,您基本上需要设置OpenGL以渲染纹理,然后将生成的纹理读入主内存并将其保存到文件中。至少在某些系统上(例如Windows),我相当肯定你仍然必须创建一个窗口并将渲染上下文与窗口关联起来,尽管如果窗口可能会很好总是隐藏。


I have a program which simulates a physical system that changes over time. I want to, at predetermined intervals (say every 10 seconds) output a visualization of the state of the simulation to a file. I want to do it in such a way that it is easy to "turn the visualization off" and not output the visualization at all.

I am looking at OpenGL and GLUT as graphics tools to do the visualization. However the problem seems to be that first of all, it looks like it only outputs to a window and can't output to a file. Second, in order to generate the visualization you have to call GLUTMainLoop and that stops the execution of the main function - the only functions that get called from then on are calls from the GUI. However I do not want this to be a GUI based application - I want it to just be an application that you run from the command line, and it generates a series of images. Is there a way to do this in GLUT/OpenGL? Or is OpenGL the wrong tool for this completely and I should use something else

解决方案

You almost certainly don't want GLUT, regardless. Your requirements don't fit what it's intended to do (and even when your requirements do fit its intended purpose, you usually don't want it anyway).

You can use OpenGL. To generate output in a file, you basically set up OpenGL to render to a texture, and then read the resulting texture into main memory and save it to a file. At least on some systems (e.g., Windows), I'm pretty sure you'll still have to create a window and associate the rendering context with the window, though it will probably be fine if the window is always hidden.

这篇关于如何使用GLUT / OpenGL渲染文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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