[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[gef3d-commits] r515 - branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font
|
- From: genie@xxxxxxxxxxx
- Date: Mon, 16 Aug 2010 11:48:47 -0400 (EDT)
- Delivered-to: gef3d-commits@eclipse.org
Author: kduske
Date: 2010-08-16 11:48:47 -0400 (Mon, 16 Aug 2010)
New Revision: 515
Added:
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureGlyphVector.java
Modified:
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AWTBasedFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorFont.java
Log:
Partially implemented texture rendering of fonts.
Modified: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AWTBasedFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AWTBasedFont.java 2010-08-16 12:12:01 UTC (rev 514)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AWTBasedFont.java 2010-08-16 15:48:47 UTC (rev 515)
@@ -11,8 +11,6 @@
package org.eclipse.draw3d.font;
import java.awt.Font;
-import java.awt.font.FontRenderContext;
-import java.awt.font.GlyphVector;
/**
* AWTBasedFont There should really be more documentation here.
@@ -52,14 +50,10 @@
if (i_string.length() == 0)
return null;
- FontRenderContext ctx = new FontRenderContext(null, true, false);
- GlyphVector glyphs = m_font.createGlyphVector(ctx, i_string);
-
- return doCreateGlyphVector(glyphs);
+ return doCreateGlyphVector(i_string);
}
- protected abstract IDraw3DGlyphVector doCreateGlyphVector(
- GlyphVector i_glyphs);
+ protected abstract IDraw3DGlyphVector doCreateGlyphVector(String i_string);
protected Font getAwtFont() {
return m_font;
Modified: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureFont.java 2010-08-16 12:12:01 UTC (rev 514)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureFont.java 2010-08-16 15:48:47 UTC (rev 515)
@@ -17,12 +17,11 @@
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
+import java.awt.font.LineMetrics;
import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
+import java.awt.image.DataBufferByte;
+import java.awt.image.Raster;
-import javax.imageio.ImageIO;
-
/**
* LwjglTextureFont There should really be more documentation here.
*
@@ -41,12 +40,15 @@
/**
* {@inheritDoc}
*
- * @see org.eclipse.draw3d.font.AWTBasedFont#doCreateGlyphVector(java.awt.font.GlyphVector)
+ * @see org.eclipse.draw3d.font.AWTBasedFont#doCreateGlyphVector(String)
*/
@Override
- protected IDraw3DGlyphVector doCreateGlyphVector(GlyphVector i_glyphs) {
+ protected IDraw3DGlyphVector doCreateGlyphVector(String i_string) {
FontRenderContext ctx = new FontRenderContext(null, true, true);
- Rectangle bounds = i_glyphs.getPixelBounds(ctx, 0, 0);
+ LineMetrics lineMetrics = getAwtFont().getLineMetrics(i_string, ctx);
+ GlyphVector glyphs = getAwtFont().createGlyphVector(ctx, i_string);
+
+ Rectangle bounds = glyphs.getPixelBounds(ctx, 0, 0);
BufferedImage img =
new BufferedImage(bounds.width, bounds.height,
BufferedImage.TYPE_BYTE_GRAY);
@@ -67,22 +69,17 @@
g.setColor(Color.WHITE);
g.fillRect(0, 0, bounds.width, bounds.height);
- g.translate(0, bounds.height);
+ g.translate(0, lineMetrics.getAscent() - 1);
g.setColor(Color.BLACK);
- for (int i = 0; i < i_glyphs.getNumGlyphs(); i++) {
- Shape outline = i_glyphs.getOutline();
+ g.setFont(getAwtFont());
+
+ for (int i = 0; i < glyphs.getNumGlyphs(); i++) {
+ Shape outline = glyphs.getGlyphOutline(i);
g.fill(outline);
}
- String path =
- "/Users/kristian/Temp/font_" + getAwtFont() + "_"
- + System.currentTimeMillis() + ".png";
- File f = new File(path);
- try {
- ImageIO.write(img, "png", f);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ Raster data = img.getData();
+ DataBufferByte dataBuffer = (DataBufferByte) data.getDataBuffer();
return null;
}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureGlyphVector.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureGlyphVector.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureGlyphVector.java 2010-08-16 15:48:47 UTC (rev 515)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Jens von Pilgrim and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kristian Duske - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.draw3d.font;
+
+import static org.lwjgl.opengl.GL11.*;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.awt.image.Raster;
+import java.nio.IntBuffer;
+
+import org.eclipse.draw3d.util.BufferUtils;
+import org.eclipse.draw3d.util.Draw3DCache;
+
+/**
+ * LwjglTextureGlyphVector There should really be more documentation here.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 16.08.2010
+ */
+public class LwjglTextureGlyphVector implements IDraw3DGlyphVector {
+
+ private enum State {
+ UNINITIALIZED, INITIALIZED, DISPOSED
+ }
+
+ private int m_textureId = 0;
+
+ private State m_state = State.UNINITIALIZED;
+
+ private BufferedImage m_image;
+
+ public LwjglTextureGlyphVector(BufferedImage i_image) {
+ if (i_image == null)
+ throw new NullPointerException("i_image must not be null");
+ m_image = i_image;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DGlyphVector#dispose()
+ */
+ public void dispose() {
+ if (m_state == State.DISPOSED)
+ throw new IllegalStateException(this + " + is disposed");
+
+ if (m_textureId > 0) {
+ IntBuffer idBuf = Draw3DCache.getIntBuffer(1);
+ try {
+ BufferUtils.put(idBuf, m_textureId);
+ glDeleteTextures(idBuf);
+ m_textureId = 0;
+ } finally {
+ Draw3DCache.returnIntBuffer(idBuf);
+ }
+ }
+
+ if (m_image != null)
+ m_image = null;
+
+ m_state = State.DISPOSED;
+ }
+
+ private void initialize() {
+ if (m_state == State.INITIALIZED)
+ return;
+
+ Raster data = m_image.getData();
+ DataBufferByte dataBuffer = (DataBufferByte) data.getDataBuffer();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DGlyphVector#render()
+ */
+ public void render() {
+ if (m_state == State.DISPOSED)
+ throw new IllegalStateException(this + " is disposed");
+ }
+
+}
Modified: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorFont.java 2010-08-16 12:12:01 UTC (rev 514)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorFont.java 2010-08-16 15:48:47 UTC (rev 515)
@@ -11,6 +11,7 @@
package org.eclipse.draw3d.font;
import java.awt.Shape;
+import java.awt.font.FontRenderContext;
import java.awt.font.GlyphMetrics;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
@@ -134,18 +135,21 @@
/**
* {@inheritDoc}
*
- * @see org.eclipse.draw3d.font.AWTBasedFont#doCreateGlyphVector(java.awt.font.GlyphVector)
+ * @see org.eclipse.draw3d.font.AWTBasedFont#doCreateGlyphVector(String)
*/
@Override
- protected IDraw3DGlyphVector doCreateGlyphVector(GlyphVector i_glyphs) {
+ protected IDraw3DGlyphVector doCreateGlyphVector(String i_string) {
+ FontRenderContext ctx = new FontRenderContext(null, true, false);
+ GlyphVector glyphs = getAwtFont().createGlyphVector(ctx, i_string);
+
AffineTransform at = new AffineTransform();
at.translate(0, getAwtFont().getSize());
double flatness = 1.9d * (1 - m_precision) + 0.1d;
- VectorChar[] stringChars = new VectorChar[i_glyphs.getNumGlyphs()];
+ VectorChar[] stringChars = new VectorChar[glyphs.getNumGlyphs()];
- for (int i = 0; i < i_glyphs.getNumGlyphs(); i++)
- stringChars[i] = createVectorChar(i_glyphs, i, at, flatness);
+ for (int i = 0; i < glyphs.getNumGlyphs(); i++)
+ stringChars[i] = createVectorChar(glyphs, i, at, flatness);
return new LwjglVectorGlyphVector(stringChars);
}