LibGDX从模型生成png [英] LibGDX Generating a png from a model
问题描述
标题几乎说明了一切,我需要从Model
获取图像,这可行吗?我搜索了此内容,却一无所获.
The title pretty much say it all, I need to get a image from a Model
is this posible? I searched for this and found nothing.
感谢@retodaredevil解决方案
Solution thanks to @retodaredevil
FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA4444, screenWidth, screenHeight, true);
ModelBatch batch = new ModelBatch();
fbo.begin(); // make fbo the current buffer
Gdx.gl.glViewport(0, 0,screenWidth, screenHeight);
Gdx.gl.glClear(GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
batch.begin(camera);
batch.render(instance, environment);
batch.end();
try{
FileHandle fh = new FileHandle(output);
Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0,0,screenWidth,screenHeight);
PixmapIO.writePNG(fh, pixmap);
pixmap.dispose();
}catch (Exception e){
e.printStackTrace();
}
fbo.end(); // Now you can draw on the display again
batch.dispose();
fbo.dispose();
推荐答案
据我了解,我们将不得不使用两个不同的教程
From what I understand, we'll have to use two different tutorials
https://github.com/mattdesl/lwjgl-basics/wiki/FrameBufferObjects
https://xoppa.github.io/blog/basic- 3d-using-libgdx/(您可能已经对此很熟悉)
https://xoppa.github.io/blog/basic-3d-using-libgdx/ (You're probably already familiar with this)
FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA4444, width, height, hasDepth);
// I've never used a FrameBuffer before so you may have to play around with constructor parameters
ModelBatch batch = // your ModelBatch initialization here
fbo.begin(); // make fbo the current buffer
glClearColor(0f, 0f, 0f, 1f);
glClear(GL_COLOR_BUFFER_BIT);
batch.resize(fbo.getWidth(), fbo.getHeight());
batch.begin();
batch.render(modelInstance, environment);
batch.end();
fbo.end(); // Now you can draw on the display again
// If you want to, you can resize your batch and use it to draw on the display
batch.resize(Display.getWidth(), Display.getHeight());
一旦对FrameBuffer做任何必要的操作,就可以得到纹理
Once you do whatever you need to do to your FrameBuffer, you can get the texture
fbo.getTexture();
该方法不存在,请查看OP的问题以寻求解决方案 FrameBuffer实际上有一个名为getColorBufferTexture()的方法
That method doesn't exist, look at OP's question for solution EDIT 2: FrameBuffer does actually have a method called getColorBufferTexture()
要保存纹理,请查看 https://www. badlogicgames.com/forum/viewtopic.php?p=8358#p8358 或
For saving a texture, look at https://www.badlogicgames.com/forum/viewtopic.php?p=8358#p8358 or https://www.badlogicgames.com/forum/viewtopic.php?t=5686
我用它来获得链接之一: Libgdx将SpriteBatch保存在纹理中我没有做的所有事情
I used this to get one of the links: Libgdx save SpriteBatch in a texture everything else I duckduckgoed
如果某事不起作用,请告诉我,我可以尝试环顾四周.
If something doesn't work let me know and I can try to look around more.
这篇关于LibGDX从模型生成png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!