now I'm working at a depth of field shader.
Here's how it works:
I render the whole scene to a FrameBuffer then apply the shader on it.
But, there's a problem: How do I pass the depthbuffer as an uniform to the shader? I couldn't find it anywhere in FrameBuffer's methods.
Any help is appreciated.
Not a LibGDX user (I use LWJGL), but in OpenGL you need to pass framebuffers as textures to a shader. In LibGDX, FrameBuffer extends GLFrameBuffer. In order to get the depth texture of a FrameBuffer, you need to call getDepthBufferHandle(), then treat it as you would a texture.
Related
I am trying to figure out how to flip a Texture in libgdx using Java. I can't find any methods of doing this and I can't just do some code to flip the Texture itself. Is there any way that I can flip the texture some way in libgdx?
You can make a Sprite object and when you initialize it, you can pass in the Texture object. Then you can call methods such as rotate, flip, etc. Here is a code example
Texture tex = new Texture("path");
Sprite sprite = new Sprite(tex);
sprite.flip(true, false);
true as the first parameter for flipping over x-axis and false for y-axis, which is what you are looking for in your specific example.
is there a possibility to save the framebuffer to texture. So that i can reuse the framebuffer to create a new texture?
com.badlogic.gdx.graphics.glutils.FrameBuffer.getColorBufferTexture()
will return the same texture everytime.
Edit:
I calculate shadow and don't wanna recalculate the static lights. So i want to save the static lights / shadow calculation in a texture. Currently i have to make a new framebuffer for each light to save them. And thats inperformant.
You can override the setupTexture method of the FrameBuffer class to provide a different texture object. Look at the default implementation of setupTexture in the libgdx code.
When I draw an image and then I try to draw and other geometry(2D), like a line or square... It wont work because the image is still bounded to GL (image.bind()). There is not method in the Texture class to un-bind the image. How do I unbind a image from GL?
In OpenGL you would call glBindTexture(GL_TEXTURE_2D, 0). Now if you use JOGL you can call Texture.disable(). However make sure you read the performance tips in any case
I'm currently rendering a cube with VBOs, and with color. I want to drop some texture on them, and I don't have any idea about it. Still learning OGL, but how can I render the cube with texture on them? I need another VBO for texture?
Thanks!
Yeah, you need another FloatBuffer, not to mention a texture.
When mapping a texture onto an object, you need to use texture coordinates (How do opengl texture coordinates work?). Use glTexCoordPointer() to map your texture onto the cube.
You can load textures with the slick library that comes with LWJGL.
I saw this Google IO session: http://code.google.com/intl/iw/events/io/2009/sessions/WritingRealTimeGamesAndroid.html
He says that the draw_texture function is the fastest and VBO is 2nd faster.
But I don't understand how to use it(the draw_texture method or the VBO way).
Any suggestion?
The source code for the sprite method test mentioned in the video is available here:
http://code.google.com/p/apps-for-android/source/browse/#svn/trunk/SpriteMethodTest
Here is an example from that where a VBO is used:
http://code.google.com/p/apps-for-android/source/browse/SpriteMethodTest/src/com/android/spritemethodtest/Grid.java#237
Here is an example from that where the draw texture extension is used:
http://code.google.com/p/apps-for-android/source/browse/SpriteMethodTest/src/com/android/spritemethodtest/GLSprite.java
One thing to watch out for, however, is that the draw texture extension is actually not the fastest for all games using sprites. Many games have groups of sprites that all share the same render state, for example. In that case it is much faster to put all sprites with the same render state in the same buffer and draw them with the same draw command. The draw texture command doesn't allow this. With the draw texture command you have to call it once per sprite.
This is the reason that atlas textures are often used. An atlas texture is a single bound texture object that has many different images in it. You can draw sprites with different images that way without having to bind to a different texture object. All you do is have them use different texture coordinates into the atlas texture. If the other render state is the same as well, such as the blending function needed, then you can draw the sprites together for better performance.
Here are some great Android OpenGL ES working examples.
http://code.google.com/p/android-gl/