LIBGDX, OpenGL 1.x requires that the image must be 2 of the length of the full power, generally the following workaround
1. Change OpenGL 1.x to OpenGL 2.0. (LIBGDX 1.0 version does not support 1.x, of course, there is no problem, this is for the 0.9.9 version)
2. Use Texturepacker to package the picture and add it as a large image.
The second method is a common method, but not too flexible to add, delete some of the pictures is not very convenient, large changes. Here you can consider using Pixmappacker to dynamically package the images.
Main methods:
Pack (String name, Pixmap pixmap) to package a picture and make a name
Generateatlas (TextureFilter minfilter, TextureFilter magfilter, Boolean usemipmap) generate Picture Resource bundle
Example code:
1 Packagecom.fxb.newtest;2 3 ImportCom.badlogic.gdx.ApplicationAdapter;4 ImportCom.badlogic.gdx.Gdx;5 Importcom.badlogic.gdx.graphics.GL10;6 ImportCom.badlogic.gdx.graphics.Pixmap;7 ImportCom.badlogic.gdx.graphics.Pixmap.Format;8 ImportCom.badlogic.gdx.graphics.Texture.TextureFilter;9 ImportCom.badlogic.gdx.graphics.g2d.PixmapPacker;Ten ImportCom.badlogic.gdx.graphics.g2d.SpriteBatch; One ImportCom.badlogic.gdx.graphics.g2d.TextureAtlas; A Importcom.badlogic.gdx.graphics.g2d.TextureRegion; - - Public classLib019_texturepackextendsapplicationadapter{ the - Textureatlas Atlas; - textureregion Region1, Region2; - spritebatch Batch; + - @Override + Public voidCreate () { A //TODO auto-generated Method Stub at Super. Create (); - -Pixmappacker Packer =NewPixmappacker (format.rgb565, 2,true ); - //Packer.pack ("First", PIXMAP1); -Pixmap PIXMAP1 =NewPixmap (Gdx.files.internal ("Data/badlogic.jpg" ) ); -Pixmap PIXMAP2 =NewPixmap (Gdx.files.internal ("Data/pal4_1.jpg" ) ); inPacker.pack ("First", PIXMAP1); -Packer.pack ("Second", PIXMAP2); to +Atlas = Packer.generatetextureatlas (Texturefilter.nearest, Texturefilter.nearest,false ); -Region1 = Atlas.findregion ("First" ); theRegion2 = Atlas.findregion ("Second" ); * $ pixmap1.dispose ();Panax Notoginseng pixmap2.dispose (); - theBatch =NewSpriteBatch (); + } A the @Override + Public voidrender () { - //TODO auto-generated Method Stub $ Super. Render (); $Gdx.gl.glClearColor (0, 1, 1, 1 ); - Gdx.gl.glClear (gl10.gl_color_buffer_bit); - the Batch.begin (); -Batch.draw (Region1, 10, 10 );WuyiBatch.draw (Region2, 20+region1.getregionwidth (), 10 ); the batch.end (); - Wu } - About @Override $ Public voidDispose () { - //TODO auto-generated Method Stub - atlas.dispose (); - Super. Dispose (); A } + the}
Operation Result: