fixing lwjgl stuff

This commit is contained in:
Hannes Janetzek
2013-06-24 04:59:19 +02:00
parent 5521583bd8
commit 30839efffd
24 changed files with 285 additions and 166 deletions

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="assets"/>
<classpathentry combineaccessrules="false" kind="src" path="/vtm-gdx"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="libs/gdx-backend-lwjgl.jar" sourcepath="libs/gdx-backend-lwjgl-sources.jar"/>
<classpathentry kind="lib" path="libs/gdx-backend-lwjgl-natives.jar"/>
<classpathentry kind="lib" path="libs/gdx-natives.jar"/>
<classpathentry kind="lib" path="/vtm/libs/vtm-jni-natives.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="assets"/>
<classpathentry combineaccessrules="false" kind="src" path="/vtm-gdx"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="lib" path="libs/gdx-backend-lwjgl-natives.jar"/>
<classpathentry kind="lib" path="libs/gdx-backend-lwjgl.jar" sourcepath="libs/gdx-backend-lwjgl-sources.jar"/>
<classpathentry kind="lib" path="libs/gdx-natives.jar"/>
<classpathentry kind="lib" path="/vtm/libs/vtm-jni-natives.jar"/>
</classpath>

View File

@@ -7,6 +7,7 @@ import java.nio.IntBuffer;
import javax.imageio.ImageIO;
import org.oscim.backend.Log;
import org.oscim.backend.canvas.Bitmap;
import com.badlogic.gdx.Gdx;
@@ -27,6 +28,10 @@ public class AwtBitmap implements Bitmap {
AwtBitmap(InputStream inputStream) throws IOException {
this.bitmap = ImageIO.read(inputStream);
this.width = this.bitmap.getWidth();
this.height = this.bitmap.getHeight();
if(!this.bitmap.isAlphaPremultiplied())
this.bitmap.coerceData(true);
}
@Override
public int getWidth() {
@@ -49,20 +54,23 @@ public class AwtBitmap implements Bitmap {
// TODO Auto-generated method stub
}
private static IntBuffer tmpBuffer = BufferUtils.newIntBuffer(256 * 256);
private static int[] tmpPixel = new int[256 * 256];
private static IntBuffer tmpBuffer = BufferUtils.newIntBuffer(512 * 256);
private static int[] tmpPixel = new int[512 * 256];
@Override
public int uploadToTexture(boolean replace) {
int[] pixels;
IntBuffer buffer;
if (width == 256 && height == 256){
if (width == 512 && height == 256){
pixels = tmpPixel;
buffer = tmpBuffer;
buffer.clear();
Log.d("AwtBitmap", "default texture");
}else{
pixels = new int[width * height];
buffer = BufferUtils.newIntBuffer(width * height);
Log.d("AwtBitmap", "create texture buffer " + width + "x" + height);
}

View File

@@ -1,9 +1,27 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.awt;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.backend.canvas.Canvas;
@@ -44,17 +62,48 @@ public class AwtCanvas implements Canvas {
}
@Override
public void drawText(String string, float x, float y, Paint stroke) {
AwtPaint p = (AwtPaint)stroke;
public void drawText(String text, float x, float y, Paint paint) {
canvas.setFont(p.font);
canvas.setColor(p.color);
// if (paint.isTransparent()) {
// return;
// }
canvas.drawString(string, (int)x, (int)y);
AwtPaint awtPaint = (AwtPaint)paint;
//AwtPaint awtPaint = AwtGraphicFactory.getAwtPaint(paint);
if (awtPaint.stroke == null) {
canvas.setColor(awtPaint.color);
canvas.setFont(awtPaint.font);
canvas.drawString(text, x, y);
} else {
setColorAndStroke(awtPaint);
TextLayout textLayout = new TextLayout(text, awtPaint.font, canvas.getFontRenderContext());
AffineTransform affineTransform = new AffineTransform();
affineTransform.translate(x, y);
canvas.draw(textLayout.getOutline(affineTransform));
}
}
private void setColorAndStroke(AwtPaint awtPaint) {
canvas.setColor(awtPaint.color);
if (awtPaint.stroke != null) {
canvas.setStroke(awtPaint.stroke);
}
}
// @Override
// public void drawText(String string, float x, float y, Paint stroke) {
// AwtPaint p = (AwtPaint)stroke;
//
// canvas.setFont(p.font);
// canvas.setColor(p.color);
//
// canvas.drawString(string, (int)x, (int)y);
// }
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
// TODO Auto-generated method stub

View File

@@ -52,7 +52,7 @@ public class AwtGraphics extends CanvasAdapter {
static final Graphics2D canvas;
static {
image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
canvas = image.createGraphics();
canvas.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
//canvas.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
@@ -72,7 +72,8 @@ public class AwtGraphics extends CanvasAdapter {
}
static synchronized float getTextWidth(FontMetrics fm, String text) {
return (float)fm.getStringBounds(text, canvas).getWidth();
//return (float)fm.getStringBounds(text, canvas).getWidth();
return fm.stringWidth(text);
}
@Override

View File

@@ -1,22 +1,50 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.awt;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Stroke;
import java.awt.font.TextAttribute;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.HashMap;
import java.util.Map;
//import org.oscim.graphics.Align;
import org.oscim.backend.canvas.Bitmap;
//import org.oscim.graphics.Cap;
//import org.oscim.graphics.FontFamily;
//import org.oscim.graphics.FontStyle;
import org.oscim.backend.canvas.Paint;
//import org.oscim.graphics.Style;
import com.badlogic.gdx.Gdx;
public class AwtPaint implements Paint {
private static int getCap(Cap cap) {
switch (cap) {
case BUTT:
return BasicStroke.CAP_BUTT;
case ROUND:
return BasicStroke.CAP_ROUND;
case SQUARE:
return BasicStroke.CAP_SQUARE;
}
throw new IllegalArgumentException("unknown cap: " + cap);
}
static final Font defaultFont;
static {
Map<Attribute, Object> textAttributes = new HashMap<Attribute, Object>();
@@ -25,13 +53,16 @@ public class AwtPaint implements Paint {
textAttributes.put(TextAttribute.SIZE, 13);
defaultFont = Font.getFont(textAttributes);
}
Font font = defaultFont; //new Font("Default", Font.PLAIN, 13);
Font font = defaultFont; // new Font("Default", Font.PLAIN, 13);
Stroke stroke;
FontMetrics fm;
Color color = new Color(0.1f,0.1f,0.1f,1);
Color color = new Color(0.1f, 0.1f, 0.1f, 1);
private int cap;
private float strokeWidth;
private Align mAlign;
@Override
public int getColor() {
@@ -58,13 +89,11 @@ public class AwtPaint implements Paint {
}
@Override
public void setColor(int color) {
this.color = new Color(
((color >> 16) & 0xff)/255f,
((color >> 8) & 0xff)/255f,
((color >> 0) & 0xff)/255f,
((color >> 24) & 0xff)/255f
);
public void setColor(int c) {
color = new Color(((c >> 16) & 0xff) / 255f,
((c >> 8) & 0xff) / 255f,
((c >> 0) & 0xff) / 255f,
((c >> 24) & 0xff) / 255f);
}
@Override
@@ -75,14 +104,17 @@ public class AwtPaint implements Paint {
@Override
public void setStrokeCap(Cap cap) {
// TODO Auto-generated method stub
this.cap = getCap(cap);
createStroke();
}
@Override
public void setStrokeWidth(float width) {
//int size = font.getSize();
//font = font.deriveFont(size + width * 4);
strokeWidth = width;
createStroke();
// int size = font.getSize();
// font = font.deriveFont(size + width * 4);
// TODO Auto-generated method stub
@@ -96,8 +128,7 @@ public class AwtPaint implements Paint {
@Override
public void setTextAlign(Align align) {
// TODO Auto-generated method stub
mAlign = align;
}
@Override
@@ -116,12 +147,13 @@ public class AwtPaint implements Paint {
public float measureText(String text) {
if (fm == null)
fm = AwtGraphics.getFontMetrics(this.font);
float w = AwtGraphics.getTextWidth(fm, text);
//Gdx.app.log("text width:", text + " " + w);
return w;
//return fm.getStringBounds(text, A).getWidth();
//return AwtGraphics.getTextWidth(fm, text);
//return fm.stringWidth(text);
// return fm.getStringBounds(text, A).getWidth();
// return AwtGraphics.getTextWidth(fm, text);
// return fm.stringWidth(text);
}
@Override
@@ -131,7 +163,6 @@ public class AwtPaint implements Paint {
float height = fm.getHeight();
//Gdx.app.log("text height", " " + height);
return height;
}
@@ -141,9 +172,14 @@ public class AwtPaint implements Paint {
fm = AwtGraphics.getFontMetrics(this.font);
float desc = fm.getDescent();
//Gdx.app.log("text descent", " " + desc);
return desc;
}
private void createStroke() {
if (strokeWidth <= 0) {
return;
}
stroke = new BasicStroke(strokeWidth, cap, BasicStroke.JOIN_ROUND, 0, null, 0);
}
}

View File

@@ -4,9 +4,11 @@ import org.oscim.awt.AwtGraphics;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.GLAdapter;
import org.oscim.core.Tile;
import org.oscim.renderer.GLRenderer;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.utils.SharedLibraryLoader;
public class Main {
@@ -17,12 +19,16 @@ public class Main {
cfg.width = 1280;
cfg.height = 800;
cfg.stencil= 8;
cfg.foregroundFPS = 20;
//cfg.samples = 4;
// set our globals
CanvasAdapter.g = AwtGraphics.INSTANCE;
GLAdapter.INSTANCE = new GdxGLAdapter();
Tile.SIZE = 256;
GLRenderer.alwaysAllocBuffer = true;
new SharedLibraryLoader().load("vtm-jni");
new LwjglApplication(new GdxMap(), cfg);
}