Libgdx - Texture packer n^2 - android

If I create a texture atlas 2048x2048, must I also make each and every texture imported into the atlas a square of 2 dimension.
Because I'm wasting a lot of space if I do that.
But my guess also is that I have to, because the MipMap filter scales it down diagonally... So if I make a rectangle, it wouldn't know how to scale it...
Any ideas?

From my experience you don't need to use n^2 images in libGDX. You can just put in any sized image in the atlas and libGDX will handle it correctly.
I never had any problems with scaling rectangular images, just using the libGDX code..
I hope this answers your question.

Related

Android, Open GL ES, crop and scale texture

I have some troubles with video processing. I'm using Surface with Texture to process video with MediaCodec and MediaMuxer (decode, crop, encode with lower quality).
And on middle-step, which is cropping, I've got problems. Basically, what I want to do is to take lesser dimension of video, then, based on this side, define offsets for bigger side and crop it out. Then result should be properly scaled into 640x640 square. I searched for pretty big amount of time, but all information that I have found points that Open GL should scale image itself. Yes, I should admit that it's doing some scale, but result is looking very ugly it seems to be "compressed" verticaly quite hardly.
So, now the question itself. Can somebody provide to me some explanation or maybe even snipet of code that perfrom desired functions in Open GL ES?
I already tried to adjust Viewport thought.
GLES20.glViewport(0, 0, 640, 640)
UPDATE
Idea that Isogen74 have proposed more less worked for me. It's still stretched quite significantly, but it's better then nothing.
Here you can find updated code: OpenGL setup
Cropping - change your texture coordinates that you loading from when loading the texture; e.g. if you you want to crop the top and bottom 10% off the image load from (0.0, 0.1) to (1.0, 0.9).
Scaling - the answer depends how big your downscale to 640*640 is. OpenGL filtering isn't designed to handle large downscaling ratios directly - it's not an image processing library - but assuming relatively small scaling ratios just ensure you have turned on GL_LINEAR texture filtering rather than GL_NEAREST.
If you have a large downscale you may need to mipmap the texture first and GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR as your minification filter, but just be aware that this isn't going to give you something as good as, for example a proper scaling algorithm you might get in image processing software (e.g. bicubic, or something like that).

Is BitmapTextureAtlas useful in Andengine GLES2

I read some threads about BitmapTextureAtlas in Andengine, but AFAIK, the newest version of Andengine dont need POT anymore. If I use many ITextures instead of singe big BitmapTextureAtlas is better or not? (example, I have 1 background texture: 480x800 and some small sprite textures. All textures can be put in a 1024x1024 BitmapTextureAtlas --> I wasted memory, dont I?) Can anyone tell me about how useful BitmapTextureAtlas it is in GLES2? When I should use it? thank you very much.
I think it's easier to use a BuildableBitmapTextureAtlas in GLES2
jaym describes it the diference here.
"Buildable texture atlas allows andengine to automatically place the textures on the texture atlas whereas bitmap texture atlas requires you to manually define location on textures inside the texture atlas."
You can use one big BuildableTextureAtlas and automatically build multiple textures onto it, providing they fit. I take the lazy approach and make a BuildableTextureAtlas for each TextureRegion.
Onto the better news: The power of 2 rule now only applies to repeating backgrounds,
Read RealMayo's explenation. Keep in mind when creating your TextureAtlas to make it a little bigger then your image or it will fail to load.

What are the Best Practices in Creating Animation to be used in a LibGDX Game?

I've just learned about the capabilities of libGDX in terms of animation. I know how to use the texture packer,read atlases to be used animation, and use the animation class.
I use Adobe Flash to create animations and export them into PNG sequences then use the texture packer. But it fails when there are too many images to be converted. I tested it by using 80 images(600X600). I was trying to rotate a big magic circle.
My question is, what are the other methods to create animation? What is the best way to create PNG Sequences?
EDIT: I used the TexturePacker-Gui:
http://www.aurelienribon.com/blog/2012/06/texturepacker-gui-support-for-multiple-packs/
and was able to pack my sprites into an atlas..Clicking 'Pack Selected' instead of 'Pack Em All' did the trick (maybe a bug for the program). And rotating that magic circle by sprite animation was a big mistake. The only question that remains is if there is any better way to create animation other than using Flash?
I have some tool form create spritesheet.
I didnt use this one
libgdx-texturepacker-gui, maybe you can try.
I am using this Texture Packer
If you want to just rotate something you don't need animation. You can create a Sprite using only one image and then do something like sprite.rotate(...);

Display and scroll over big layout

would be very grateful if anyone can advice how to solve the problem.
I got to draw a large and rather complicated structure (railway track layout). In order to have a smooth scrolling I wanted to draw the layout into a bitmap and then just to copy necessary part into the screen canvas in onDraw method.
The problem is that the layout is much larger than 2048x2048 (max allowed texture size on my Asus Prime) and I'm getting 'Bitmap too large to be uploaded into a texture'.
And this's even without zoom.
The layout is just a set of 2d geometrical primitives so maybe it's possible to work on geometrical rather than bitmap level, but how to implement smooth scroll and zoom then ?
What are common ways of solving this issue ?
Thanks in advance.
You should use a tiled approach. Divide your large map within small ones and render them while you move. Like google maps does.
You could use the TMX format: http://www.mapeditor.org/
AndEngine http://www.andengine.org/ has an implementation for it.

Drawing Low Resolution Images Really Big

I am creating a game for android and I would like the sprites to have the look of an old NES game. I have some 12x12 pixel images and would like them to keep their pixelated look as they are scaled up.
Please view the following link
http://imgur.com/a/LR3eK/all
One image is a screenshot of the image as it looks in an editor. This is how I would like it to look in game. The other image is what it actually looks like blown up in game (blurry).
The image is imported as a Drawable and I'm calling Drawable.draw(Canvas canvas) on it.
I've read up on the problem and found some info here (Android: drawable resolutions). I believe it's either that anti aliasing or some kind of interpolation needs to be disabled but I cannot figure out how to do this with a Drawable.
I did however find out that it is possible with Bitmaps but my game requires lots of sprite re-scaling and, although I found this Resize Bitmap in Android I do not think re-scaling bitmaps is a good idea.
I am new Android and no where near a professional programmer so please shed some light on me.
In my app I had to do the exact same thing!
Paint paint = new Paint();
paint.setDither(false);
paint.setAntiAlias(false);
And I used pixel-sized images to save space, and a Matrix to handle rotation and scaling (though that's your choice).
Hope this helps, good luck!
EDIT:
also if you're using the createScaledBitmap, or any similar functions, make sure you pass false for any filtering parameters.

Categories

Resources