LWJGL Texture a cube - java

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.

Related

LibGDX how do I get a depthbuffer from FrameBuffer?

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.

Fill a ShapeRenderer rectangle with an image(.png)?

I am new to libgdx. I am trying to write a basic android game with the libgdx framework
Is it possible at all to fill a rectangle drawn with libgdx ShapeRenderer with a given image?
If yes, how, and if no, is there any kind of hack or workaround?
Images to be put on the screen in Libgdx (and OpenGL) are known as "textures". The ShapeRenderer library does not support textures.
That said, the Libgdx texture and SpriteBatch APIs are optimized for drawing image rectangles. Check out the overview and tutorial here:
https://github.com/libgdx/libgdx/wiki/Spritebatch%2C-textureregions%2C-and-sprite

How to reuse framebuffer texture in libgdx

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.

Why do I need to disable GL_TEXTURE_2D after drawing string in order for shapes to render?

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.

What is the easiest way to draw texture with OpenGL ES?

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/

Categories

Resources