本文整理了Java中com.badlogic.gdx.graphics.glutils.FrameBuffer
类的一些代码示例,展示了FrameBuffer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FrameBuffer
类的具体详情如下:
包路径:com.badlogic.gdx.graphics.glutils.FrameBuffer
类名称:FrameBuffer
[英]Encapsulates OpenGL ES 2.0 frame buffer objects. This is a simple helper class which should cover most FBO uses. It will automatically create a texture for the color attachment and a renderbuffer for the depth buffer. You can get a hold of the texture by FrameBuffer#getColorBufferTexture(). This class will only work with OpenGL ES 2.0.
FrameBuffers are managed. In case of an OpenGL context loss, which only happens on Android when a user switches to another application or receives an incoming call, the framebuffer will be automatically recreated.
A FrameBuffer must be disposed if it is no longer needed
[中]封装OpenGL ES 2.0帧缓冲区对象。这是一个简单的助手类,应该涵盖大多数FBO使用。它将自动为颜色附件创建纹理,并为深度缓冲区创建渲染缓冲区。您可以通过帧缓冲区#getColorBufferTexture()获取纹理。此类仅适用于OpenGL ES 2.0。
帧缓冲区被管理。在OpenGL上下文丢失的情况下,只有当用户切换到另一个应用程序或接收到传入呼叫时,才会在Android上发生这种情况,帧缓冲区将自动重新创建。
如果不再需要帧缓冲区,则必须将其释放
代码示例来源:origin: libgdx/libgdx
@Override
public void render () {
frameBuffer.begin();
Gdx.gl20.glViewport(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
Gdx.gl20.glClearColor(0f, 1f, 0f, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
mesh.render(meshShader, GL20.GL_TRIANGLES);
meshShader.end();
frameBuffer.end();
stencilFrameBuffer.begin();
Gdx.gl20.glViewport(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
Gdx.gl20.glClearColor(1f, 1f, 0f, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_STENCIL_BUFFER_BIT);
stencilFrameBuffer.end();
spriteBatch.draw(frameBuffer.getColorBufferTexture(), 0, 0, 256, 256, 0, 0, frameBuffer.getColorBufferTexture().getWidth(),
frameBuffer.getColorBufferTexture().getHeight(), false, true);
spriteBatch.draw(stencilFrameBuffer.getColorBufferTexture(), 256, 256, 256, 256, 0, 0, frameBuffer.getColorBufferTexture()
.getWidth(), frameBuffer.getColorBufferTexture().getHeight(), false, true);
spriteBatch.end();
代码示例来源:origin: libgdx/libgdx
@Override
public FrameBuffer build () {
return new FrameBuffer(this);
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public void dispose () {
if (fbo != null) fbo.dispose();
fbo = null;
}
}
代码示例来源:origin: libgdx/libgdx
public void begin () {
final int w = fbo.getWidth();
final int h = fbo.getHeight();
fbo.begin();
Gdx.gl.glViewport(0, 0, w, h);
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
Gdx.gl.glScissor(1, 1, w - 2, h - 2);
}
代码示例来源:origin: stackoverflow.com
m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
m_fboRegion.flip(false, true);
m_fbo.begin();
m_fbo.end();
代码示例来源:origin: libgdx/libgdx
public void render () {
angle += 45 * Gdx.graphics.getDeltaTime();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
cam.update();
matrix.setToRotation(0, 1, 0, angle);
cam.combined.mul(matrix);
fbo.begin();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
modelBatch.begin(cam);
modelBatch.render(sceneInstance);
modelBatch.end();
fbo.end();
batch.begin();
batch.disableBlending();
batchShader.setUniformi("u_filterSize", filter.length);
batchShader.setUniform1fv("u_filter", filter, 0, filter.length);
batchShader.setUniform2fv("u_offsets", offsets, 0, offsets.length);
batch.draw(fboRegion, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.end();
logger.log();
}
}
代码示例来源:origin: manuelbua/libgdx-contribs
@Override
public void render (FrameBuffer src, FrameBuffer dest) {
restoreViewport(dest);
if (dest != null) {
motionFilter.setInput(src).setOutput(dest).render();
fbo = dest;
} else {
if (fbo == null) {
// Init frame buffer
fbo = new FrameBuffer(Format.RGBA8888, src.getWidth(), src.getHeight(), false);
}
motionFilter.setInput(src).setOutput(fbo).render();
// Copy fbo to screen
copyFilter.setInput(fbo).setOutput(dest).render();
}
// Set last frame
motionFilter.setLastFrameTexture(fbo.getColorBufferTexture());
}
代码示例来源:origin: libgdx/libgdx
@Override
public TextureDescriptor getDepthMap () {
textureDesc.texture = fbo.getColorBufferTexture();
return textureDesc;
}
代码示例来源:origin: libgdx/libgdx
frameBuffer.begin();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
frameBuffer.end();
renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(DIFFUSE_ATTACHMENT)));
mrtSceneShader.setUniformi("u_normalTexture",
renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(NORMAL_ATTACHMENT)));
mrtSceneShader.setUniformi("u_positionTexture",
renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(POSITION_ATTACHMENT)));
mrtSceneShader.setUniformi("u_depthTexture", renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(DEPTH_ATTACHMENT)));
for (int i = 0; i < lights.size; i++) {
Light light = lights.get(i);
batch.draw(frameBuffer.getTextureAttachments().get(DIFFUSE_ATTACHMENT), 0, 0, Gdx.graphics.getWidth() / 4f,
Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
batch.draw(frameBuffer.getTextureAttachments().get(NORMAL_ATTACHMENT), Gdx.graphics.getWidth() / 4f, 0,
Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
batch.draw(frameBuffer.getTextureAttachments().get(POSITION_ATTACHMENT), 2 * Gdx.graphics.getWidth() / 4f, 0,
Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
batch.draw(frameBuffer.getTextureAttachments().get(DEPTH_ATTACHMENT), 3 * Gdx.graphics.getWidth() / 4f, 0,
Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f);
batch.end();
代码示例来源:origin: libgdx/libgdx
/** End pass n.
* @param n Pass number */
protected void endPass (int n) {
frameBuffers[n].end();
}
代码示例来源:origin: langurmonkey/gaiasky
public TextureWidget(FrameBuffer fb) {
super();
this.fb = fb;
this.width = fb.getWidth();
this.height = fb.getHeight();
}
代码示例来源:origin: LonamiWebs/Klooni1010
@Override
public void resize(int width, int height) {
this.width = width;
this.height = height;
if (frameBuffer != null)
frameBuffer.dispose();
frameBuffer = new FrameBuffer(Pixmap.Format.RGB565, width, height, false);
bufferTexture = new TextureRegion(frameBuffer.getColorBufferTexture());
bufferTexture.flip(false, true);
}
代码示例来源:origin: libgdx/libgdx
public void create () {
ShaderProgram.pedantic = false;
/*
* shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal(
* "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest",
* "couldn't compile scene shader: " + shader.getLog()); }
*/
batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal(
"data/shaders/convolution.frag").readString());
if (!batchShader.isCompiled()) {
Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());
}
ObjLoader objLoader = new ObjLoader();
scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
sceneInstance = new ModelInstance(scene);
modelBatch = new ModelBatch();
fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 0, 10);
cam.lookAt(0, 0, 0);
cam.far = 30;
batch = new SpriteBatch();
batch.setShader(batchShader);
fboRegion = new TextureRegion(fbo.getColorBufferTexture());
fboRegion.flip(false, true);
logger = new FPSLogger();
calculateOffsets();
}
代码示例来源:origin: libgdx/libgdx
/** Begin pass n.
* @param n Pass number */
protected void beginPass (int n) {
frameBuffers[n].begin();
};
代码示例来源:origin: dingjibang/GDX-RPG
public final void render () {
if (outputBuffer != null) {
outputBuffer.begin();
realRender();
outputBuffer.end();
} else {
realRender();
}
}
代码示例来源:origin: dsaltares/libgdx-cookbook
private void applyBlur(float blur) {
// Horizontal blur from FBO A to FBO B
fboB.begin();
batch.setShader(shader);
shader.setUniformf("dir", 1.0f, 0.0f);
shader.setUniformf("radius", blur);
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
drawTexture(fboA.getColorBufferTexture(), 0.0f, 0.0f);
batch.flush();
fboB.end();
// Vertical blur from FBO B to the screen
shader.setUniformf("dir", 0.0f, 1.0f);
shader.setUniformf("radius", blur);
drawTexture(fboB.getColorBufferTexture(), 0.0f, 0.0f);
batch.flush();
}
代码示例来源:origin: manuelbua/uracer-kotd
@Override
public void render (FrameBuffer src, FrameBuffer dest) {
restoreViewport(dest);
if (dest != null) {
motionFilter.setInput(src).setOutput(dest).render();
fbo = dest;
} else {
if (fbo == null) {
// Init frame buffer
fbo = new FrameBuffer(Format.RGBA8888, src.getWidth(), src.getHeight(), false);
}
motionFilter.setInput(src).setOutput(fbo).render();
// Copy fbo to screen
copyFilter.setInput(fbo).setOutput(dest).render();
}
// Set last frame
motionFilter.setLastFrameTexture(fbo.getColorBufferTexture());
}
代码示例来源:origin: libgdx/libgdx
public void begin () {
final int w = fbo.getWidth();
final int h = fbo.getHeight();
fbo.begin();
Gdx.gl.glViewport(0, 0, w, h);
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
Gdx.gl.glScissor(1, 1, w - 2, h - 2);
}
代码示例来源:origin: libgdx/libgdx
@Override
public TextureDescriptor getDepthMap () {
textureDesc.texture = fbo.getColorBufferTexture();
return textureDesc;
}
代码示例来源:origin: libgdx/libgdx
public void end () {
Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
fbo.end();
}
内容来源于网络,如有侵权,请联系作者删除!