this.isManaged = managed;\r
this.isMipMapped = TextureFilter.isMipMap(minFilter);\r
\r
- if (!isMipMapped && file.path().endsWith(".png")) {\r
- // Fast path.\r
- loadPNG(file);\r
- } else {\r
- BufferedImage image = (BufferedImage)Gdx.graphics.newPixmap(file).getNativePixmap();\r
- loadMipMap(image);\r
- }\r
+ BufferedImage image = (BufferedImage)Gdx.graphics.newPixmap(file).getNativePixmap();\r
+ loadMipMap(image);\r
+\r
bind();\r
GL20 gl = Gdx.graphics.getGL20();\r
gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, getTextureFilter(minFilter));\r
int stride = texWidth * 4;\r
ensureBufferSize(stride * texHeight);\r
\r
- Format pngFormat = pngDecoder.decideTextureFormat(PNGDecoder.Format.RGBA);\r
+ Format pngFormat = pngDecoder.decideTextureFormat(PNGDecoder.Format.BGRA);\r
int glFormat, glInternalFormat;\r
switch (pngFormat) {\r
case ALPHA:\r
ensureBufferSize(width * height * 4);\r
\r
Raster raster = image.getRaster();\r
- if (image.getType() == BufferedImage.TYPE_INT_ARGB)\r
- intBuffer.put(((DataBufferInt)raster.getDataBuffer()).getData(), 0, width * height);\r
+ if (image.getType() == BufferedImage.TYPE_INT_ARGB ||\r
+ image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {\r
+ int[] pixels = ((DataBufferInt)raster.getDataBuffer()).getData();\r
+ for(int i = 0; i < pixels.length; i++) {\r
+ int col = pixels[i];\r
+ col = ((col & 0xffffff) << 8) |\r
+ ((col & 0xff000000) >>> 24);\r
+ pixels[i] = col;\r
+ }\r
+ intBuffer.put(pixels, 0, width * height);\r
+ }\r
else {\r
// Same as image.getRGB() without allocating a large int[].\r
ColorModel colorModel = image.getColorModel();\r
Object data = raster.getDataElements(0, 0, null);\r
for (int y = 0; y < height; y++)\r
- for (int x = 0; x < width; x++)\r
- intBuffer.put(colorModel.getRGB(raster.getDataElements(x, y, data)));\r
+ for (int x = 0; x < width; x++) {\r
+ int col = colorModel.getRGB(raster.getDataElements(x, y, data));\r
+ col = ((col & 0xffffff) << 8) |\r
+ ((col & 0xff000000) >>> 24);\r
+ intBuffer.put(col);\r
+ }\r
}\r
\r
buffer.limit(intBuffer.position() * 4);\r
if (buffer == null || buffer.capacity() < size) {\r
buffer = BufferUtils.newByteBuffer(size);\r
ByteBuffer temp = buffer.slice();\r
- temp.order(ByteOrder.LITTLE_ENDIAN);\r
+ temp.order(ByteOrder.BIG_ENDIAN);\r
intBuffer = temp.asIntBuffer();\r
} else {\r
buffer.clear();\r
return scaled;\r
}\r
\r
- private void loadMipMap (BufferedImage image) {\r
+ private void loadMipMap (BufferedImage image) { \r
int level = 0;\r
int height = image.getHeight();\r
int width = image.getWidth();\r
\r
package com.badlogic.gdx.tests;\r
\r
-import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.graphics.GL10;\r
import com.badlogic.gdx.graphics.GL20;\r
import com.badlogic.gdx.graphics.Mesh;\r
+import com.badlogic.gdx.graphics.Pixmap;\r
+import com.badlogic.gdx.graphics.Pixmap.Format;\r
import com.badlogic.gdx.graphics.SpriteBatch;\r
import com.badlogic.gdx.graphics.Texture;\r
-import com.badlogic.gdx.graphics.VertexAttribute;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.VertexAttribute;\r
import com.badlogic.gdx.graphics.VertexAttributes.Usage;\r
import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
import com.badlogic.gdx.math.Matrix4;\r
+ "varying vec2 v_texCoords;"\r
+ "void main() \n"\r
+ "{ \n"\r
- + " v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n"\r
+ + " v_color = vec4(1, 1, 1, 1); \n"\r
+ " v_texCoords = a_texCoords; \n"\r
+ " gl_Position = u_worldView * a_position; \n"\r
+ "} \n";\r
System.exit(0);\r
}\r
\r
- mesh = new Mesh(true, 3, 3, new VertexAttribute(Usage.Position, 3,\r
+ mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3,\r
"a_position"), new VertexAttribute(Usage.Color, 4, "a_color"),\r
new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));\r
\r
- mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 1, 0, 0, 1, 0, 0, 0.5f,\r
- -0.5f, 0, 0, 1, 0, 1, 1, 0, 0, 0.5f, 0, 0, 0, 1, 1, 0.5f, 1 });\r
- mesh.setIndices(new short[] { 0, 1, 2 });\r
+ mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 1, 1, 1, 1, 0, 1,\r
+ 0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1,\r
+ 0.5f, 0.5f, 0, 1, 1, 1, 1, 1, 0,\r
+ -0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 0});\r
+ mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });\r
+\r
\r
+ Pixmap pixmap = Gdx.graphics.newPixmap(2, 1, Format.RGBA8888);\r
+// pixmap.drawPixel(0, 0, 0xffff0000);\r
+// pixmap.drawPixel(1, 0, 0xff00ff00);\r
+// pixmap.drawPixel(0, 1, 0xff0000ff);\r
+// pixmap.drawPixel(0, 0, 0xffff00ff);\r
+// pixmap.drawPixel(1, 0, 0xffffff00);\r
+// texture = Gdx.graphics.newUnmanagedTexture(pixmap, TextureFilter.Nearest, TextureFilter.Nearest, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
texture = Gdx.graphics.newTexture(Gdx.files.getFileHandle(\r
- "data/badlogic.jpg", FileType.Internal), TextureFilter.MipMap,\r
+ "data/bobrgb888-32x32.png", FileType.Internal), TextureFilter.MipMap,\r
TextureFilter.Linear, TextureWrap.ClampToEdge,\r
TextureWrap.ClampToEdge);\r
\r
Gdx.graphics.getGL20().glClearColor(0.2f, 0.2f, 0.2f, 1);\r
Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);\r
Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D);\r
+ Gdx.graphics.getGL20().glEnable(GL10.GL_BLEND);\r
+ Gdx.graphics.getGL20().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);\r
texture.bind();\r
shader.begin();\r
shader.setUniformMatrix("u_worldView", matrix);\r