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
Related
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.
I'm trying to blur an object in my scene with a GLSL shader.
What I do is when I'm drawing my scene, I may reach an object that needs to be blurred. When I do, I do so in two passes (from what I understand this is more optimized than doing so in a single pass).
So I draw the object to an off-screen FBO (transparent BG) with a horizontal blur. I then draw this FBO to the screen's default FBO with the vertical blur.
This is the result (method #1 in this image):
The white "glow" is problematic. However, if I draw the object to an off-screen FBO that does not have a transparent BG, I get the correct blur result from method #2 in the above image. However, I now obviously have a white BG behind the object - also not good.
What I'm asking is how exactly are you supposed to blur with the two-pass approach if you can't use a transparent-BG FBO? Or is there some trick I can do to fix this? Maybe mess with the blending src/dst functions?
I'm using the Slick2D library in order to render text to the screen but in order to render gl shapes like Rect, I need to first disable GL_TEXTURE_2D. I'm just curious as to why that is needed. Why does GL_TEXTURE_2D disable the rendering of shapes?
The way OpenGL works is basically one large, global state machine. When you bind a texture, every triangle you draw afterwards will use that texture.
The issue here is that the text drawing doesn't unbind it's texture afterwards, so the shapes you draw afterwards will be using that texture instead of no texture. The reason why you think it's "disabling" rendering is because the texture is made up of characters with everything else being transparent. What you're seeing is OpenGL drawing your shape with opacity at 0.
What happens when you disable GL_TEXTURE_2D is that the texture gets unbound and you draw regularly without a texture.
Because the string's texture is applied. As you probably don't set any texture coords it probably uses a section of the texture that is transparent and hence you see nothing.
I am writing a particle based game that is mainly built by drawing lots of colored shapes.
Question 1)
For most of the enemy units I am drawing 4 layered rectangles by setting the paint and then drawing the rectangle through the canvas.
I was wondering if it is better to draw using bitmaps, or to draw using the canvas drawing tools? I could easily make a single image of the enemy unit that I wish to draw.
Question 2)
For the images that I have to draw to the screen, I was wondering how I need to load them?
Right now I have tons of .png images loaded like this:
direction1 = BitmapFactory.decodeStream(assetMgr.open("direction1.png"));
I've read that RGB565 is the fasted image type to draw to the screen. Microsoft Paint has some saving options, but for the most part programs only save as a bitmap, not a type of bitmap. If I was to start using that new format would I:
Make new images and use the same loading code.
Use the same images and add something like Bitmap bmp =
Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); to
convert from the initial loaded format to the RGB565 format.
Make new images and change my loading code.
Thanks for any help! It is very appreciated.
None. It is always better to use OpenGL and the only downside is
that it requires more energy from a battery because it's hardware
accelerated.
RGB565 means that image uses 16 bits so that's the
option you should look for. Don't convert anything, just create them
in the format you will be using.
If the Bitmap aren't moving frame-by-frame, you should try to reduce invalidate() method call. The canvas should only be re-drawn when changes are made and should be updated.
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/