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

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

Related

Libgdx painting game logic

i'm learning libgdx in purpose of building a realtime multiplayer painting game. Game will last in 120 second and 4 people with 4 different colors will race to paint more portion of the screen.
Now i'm trying to implement circular painting as player moves. As i made some researches, i saw that i can use pixmaps to implement such behaviour. As game updates, i will fill a circle at players x and y with radius r and draw a texture that scales the screen from pixmap( which is also game map). Is there a better way to achieve this?
And i must make it for all resolutions. 1024X1024 resolution versus 240x240 must be able to play. Can i do this by using lowest resolution pixmap and drawing a scaled texture from it? Thank you...
Thats the game im trying to do..
https://www.youtube.com/watch?v=EU8Eyh0tZOo&t=270s
You need to use Framebuffer for this kind of game. Pixmap is extremely slow for using every frame.
https://github.com/mattdesl/lwjgl-basics/wiki/framebufferobjects
And yes you can make all resolutions play together like this.

How to create lighting in libGDX

I have recently been making a platformer game with a shape as my player. The shape would be morphed into different shapes during the game: eg. square, triangle, etc.. Currently, the lighting system in my game is non-existent. I have a blur effect in my square.png texture currently. I just want to add a simple light effect in the current shape of the player without any external libraries (I'm talking to you, BOX2D!) or any other sprite assets or by using glsl. I find glsl a bit confusing, and I'm not using box2d in my game.
Thanks in advance!

Libgdx create sky / environment in 3D

I am developing a 3D game using the Libgx 3D api. Now i want to add some environment (not the Libgdx Environment, but a real environment), like the sky or some background. I have heard about the so called skybox, and i understood, more or less, how it works.
This "skybox" is a Box arround your Gameworld. So you are inside this box. You add a Texture to all 6 faces at the inside of this box. Now you set your camera to the center of this box, but with the right view direction, and start the rendering, so you have always the same distance to the faces, but you can rotate arround at look at other faces. Then you set your camera where you really are in the world and render all the models, objects, whatever. Did i understand that right?
I could not find a tutorial on how to do that with libgdx. So my question is: How do i create a "skybox" in libgdx, how do i add my Textures to it and how do i render it as background/environment? Or are there other, maybe easier possibilities?
You can use big sphere which is textured inside around your world. If use blender, just create sphere object and unwrap this mesh. Then flip normals to see texture inside the sphere.
Another way is to create cubemap as you described above. I have made a class which works with cubemap. Just follow this link: LibGDX 0.9.9 - Apply cubemap in environment

LWJGL Texture a cube

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.

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