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

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

问题描述

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

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.

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

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

推荐答案

无论如何,您几乎肯定不想要 GLUT.你的需求不符合它的意图(即使你的需求确实符合它的预期目的,你通常也不想要它).

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).

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

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天全站免登陆