我正在创建一个REST API
,以根据用户输入和提供的动画类型动态生成视频。因此,我为此使用处理 2.2.1。
我想使用 OPENGL
生成 3D 动画。但是 OPENGL 需要 Window 对象。由于我在后台使用处理来生成帧,因此如何使用 OPENGL 处理来生成动画帧,而无需交互方式而不显示窗口。
我的示例代码
import com.hamoid.VideoExport;
import processing.core.*;
public class CircleSketch extends PApplet {
private VideoExport videoExport;
public void setup() {
size(400, 400,OPENGL);
videoExport = new VideoExport(this, "F:/work/tmp.mp4");
background(0);
}
public void draw() {
background(0);
fill(200);
rotateX(radians(50));
rectMode(CENTER);
rect(width/2,height/2, 100, 100);
videoExport.saveFrame();
}
}
DisplayFrame
类
public class DisplayFrame extends javax.swing.JFrame {
public DisplayFrame(){
this.setSize(600, 600); //The window Dimensions
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.JPanel panel = new javax.swing.JPanel();
panel.setBounds(20, 20, 600, 600);
processing.core.PApplet sketch = new CircleSketch();
panel.add(sketch);
this.add(panel);
this.setVisible(false);
//this is the function used to start the execution of the sketch
sketch.init();
}
public static void main(String[] args) {
new DisplayFrame().setVisible(false);
}
}
请问有什么建议吗???
最佳答案
how can I use processing with OPENGL to generate animated frames without interactive means without displaying the window.
简而言之:鉴于当前的 OpenGL 驱动程序模型您不能(只要您想使用 GPU 进行渲染)。就是这样。
如果您可以忍受软件渲染(缓慢),那么 OSMesa 。此外,在可预见的将来,驱动程序模型应该会发生变化,从而允许在 headless 环境中使用 OpenGL。在那之前,您需要在图形环境上有某种类型的窗口,该窗口实际上主动提供显示输出(因此启动 X11 服务器并将其置于后台是不够的)。
关于java - 使用处理 opengl 创建视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31825147/