From 92f33a6c84ad83ba6f1d00f1d405d3418d058e65 Mon Sep 17 00:00:00 2001 From: badlogicgames Date: Thu, 30 Dec 2010 13:27:27 +0000 Subject: [PATCH] [added] Gdx2DPixmap, don't use this yet, it's a WIP. [fixed] #####libgdx.so issue on Android. --- gdx/jni/gdx2d/gdx2d.c | 22 +++++++-------- gdx/jni/gdx2d/gdx2d.h | 20 +++++++------- gdx/src/com/badlogic/gdx/Version.java | 8 +++--- gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java | 31 +++++++++++++++++----- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/gdx/jni/gdx2d/gdx2d.c b/gdx/jni/gdx2d/gdx2d.c index 0fb015e86..66014f4b2 100644 --- a/gdx/jni/gdx2d/gdx2d.c +++ b/gdx/jni/gdx2d/gdx2d.c @@ -20,9 +20,9 @@ static int gdx2d_blend = GDX2D_BLEND_NONE; static int gdx2d_scale = GDX2D_SCALE_NEAREST; -gdx2d_pixmap* gdx2d_load(const char *buffer, int len, int req_format) { +gdx2d_pixmap* gdx2d_load(const unsigned char *buffer, int len, int req_format) { int width, height, format; - const char* pixels = stbi_load_from_memory(buffer, len, &width, &height, &format, req_format); + const unsigned char* pixels = stbi_load_from_memory(buffer, len, &width, &height, &format, req_format); if(pixels == NULL) return NULL; @@ -39,7 +39,7 @@ gdx2d_pixmap* gdx2d_new(int width, int height, int format) { pixmap->width = width; pixmap->height = height; pixmap->format = format; - pixmap->pixels = (char*)malloc(width * height * format); + pixmap->pixels = (unsigned char*)malloc(width * height * format); return pixmap; } void gdx2d_free(const gdx2d_pixmap* pixmap) { @@ -55,31 +55,31 @@ void gdx2d_set_scale (int scale) { gdx2d_scale = scale; } -void gdx2d_clear(const gdx2d_pixmap* pixmap, int col) { - +void gdx2d_clear(const gdx2d_pixmap* pixmap, uint32_t col) { + } -void gdx2d_set_pixel(const gdx2d_pixmap* pixmap, int x, int y, int col) { +void gdx2d_set_pixel(const gdx2d_pixmap* pixmap, int x, int y, uint32_t col) { } -void gdx2d_draw_line(const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col) { +void gdx2d_draw_line(const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, uint32_t col) { } -void gdx2d_draw_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col) { +void gdx2d_draw_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, uint32_t col) { } -void gdx2d_draw_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, int col) { +void gdx2d_draw_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, uint32_t col) { } -void gdx2d_fill_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col) { +void gdx2d_fill_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, uint32_t col) { } -void gdx2d_fill_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, int col) { +void gdx2d_fill_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, uint32_t col) { } diff --git a/gdx/jni/gdx2d/gdx2d.h b/gdx/jni/gdx2d/gdx2d.h index 5270af5e2..02d754299 100644 --- a/gdx/jni/gdx2d/gdx2d.h +++ b/gdx/jni/gdx2d/gdx2d.h @@ -13,6 +13,8 @@ #ifndef __GDX2D__ #define __GDX2D__ +#include + #ifdef __cplusplus extern "C" { #endif @@ -49,23 +51,23 @@ typedef struct { int width; int height; int format; - const char* pixels; + const unsigned char* pixels; } gdx2d_pixmap; -extern gdx2d_pixmap* gdx2d_load (const char *buffer, int len, int req_format); +extern gdx2d_pixmap* gdx2d_load (const unsigned char *buffer, int len, int req_format); extern gdx2d_pixmap* gdx2d_new (int width, int height, int format); extern void gdx2d_free (const gdx2d_pixmap* pixmap); extern void gdx2d_set_blend (int blend); extern void gdx2d_set_scale (int scale); -extern void gdx2d_clear (const gdx2d_pixmap* pixmap, int col); -extern void gdx2d_set_pixel (const gdx2d_pixmap* pixmap, int x, int y, int col); -extern void gdx2d_draw_line (const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col); -extern void gdx2d_draw_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col); -extern void gdx2d_draw_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col); -extern void gdx2d_fill_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col); -extern void gdx2d_fill_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col); +extern void gdx2d_clear (const gdx2d_pixmap* pixmap, uint32_t col); +extern void gdx2d_set_pixel (const gdx2d_pixmap* pixmap, int x, int y, uint32_t col); +extern void gdx2d_draw_line (const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, uint32_t col); +extern void gdx2d_draw_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, uint32_t col); +extern void gdx2d_draw_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, uint32_t col); +extern void gdx2d_fill_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, uint32_t col); +extern void gdx2d_fill_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, uint32_t col); extern void gdx2d_draw_pixmap (const gdx2d_pixmap* src_pixmap, const gdx2d_pixmap* dst_pixmap, int src_x, int src_y, int src_width, int src_height, diff --git a/gdx/src/com/badlogic/gdx/Version.java b/gdx/src/com/badlogic/gdx/Version.java index 9cd06117c..a865d9045 100644 --- a/gdx/src/com/badlogic/gdx/Version.java +++ b/gdx/src/com/badlogic/gdx/Version.java @@ -25,11 +25,13 @@ public class Version { /** the current version of libgdx in the major.minor format **/ public static String VERSION = "0.81"; - public static void loadLibrary () { - if (GdxNativesLoader.loadLibraries()) return; - + public static void loadLibrary () { String os = System.getProperty("os.name"); String arch = System.getProperty("os.arch"); + String vm = System.getProperty("java.vm.name"); + + if(!(vm != null && vm.contains("Dalvik"))) + if (GdxNativesLoader.loadLibraries()) return; if (!arch.equals("amd64") || os.contains("Mac")) { System.loadLibrary("gdx"); diff --git a/gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java b/gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java index fac5451f7..5aa82e4a8 100644 --- a/gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java +++ b/gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java @@ -15,6 +15,7 @@ package com.badlogic.gdx.graphics; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.Buffer; import java.nio.ByteBuffer; /** @@ -23,10 +24,10 @@ import java.nio.ByteBuffer; * */ public class Gdx2DPixmap { - static final int GDX2D_FORMAT_ALPHA = 1; - static final int GDX2D_FORMAT_ALPHA_LUMINANCE = 2; - static final int GDX2D_FORMAT_RGB = 3; - static final int GDX2D_FORMAT_RGBA = 4; + public static final int GDX2D_FORMAT_ALPHA = 1; + public static final int GDX2D_FORMAT_ALPHA_LUMINANCE = 2; + public static final int GDX2D_FORMAT_RGB = 3; + public static final int GDX2D_FORMAT_RGBA = 4; final long basePtr; final int width; @@ -35,7 +36,7 @@ public class Gdx2DPixmap { final ByteBuffer pixelPtr; static final long[] nativeData = new long[4]; - private Gdx2DPixmap(InputStream in, int requestedFormat) throws IOException { + public Gdx2DPixmap(InputStream in, int requestedFormat) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int readBytes = 0; @@ -55,7 +56,7 @@ public class Gdx2DPixmap { format = (int)nativeData[3]; } - private Gdx2DPixmap(int width, int height, int format) throws IllegalArgumentException { + public Gdx2DPixmap(int width, int height, int format) throws IllegalArgumentException { pixelPtr = newPixmap(nativeData, width, height, format); if(pixelPtr == null) throw new IllegalArgumentException("couldn't load pixmap"); @@ -119,7 +120,7 @@ public class Gdx2DPixmap { } catch(IllegalArgumentException e) { return null; } - } + } private static native ByteBuffer load(long[] nativeData, byte[] buffer, int len, int requestedFormat); private static native ByteBuffer newPixmap(long[] nativeData, int width, int height, int format); @@ -135,4 +136,20 @@ public class Gdx2DPixmap { public static native void setBlend(int blend); public static native void setScale(int scale); + + public ByteBuffer getPixels () { + return pixelPtr; + } + + public int getHeight () { + return height; + } + + public int getWidth () { + return width; + } + + public int getFormat() { + return format; + } } -- 2.11.0