[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[gef3d-commits] r516 - in branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font: . viewer
|
- From: genie@xxxxxxxxxxx
- Date: Tue, 17 Aug 2010 06:26:41 -0400 (EDT)
- Delivered-to: gef3d-commits@eclipse.org
Author: kduske
Date: 2010-08-17 06:26:41 -0400 (Tue, 17 Aug 2010)
New Revision: 516
Added:
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/AwtBasedTextureFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/EmptyText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java
Removed:
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/IDraw3DGlyphVector.java
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/LwjglVectorGlyphVector.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/TextureChar.java
Modified:
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglAWTGlyphCallback.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
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/VectorChar.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/viewer/Draw3DFontViewer.java
Log:
Implemented texture fonts, cleanup, javadoc.
Deleted: 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 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AWTBasedFont.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * 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 java.awt.Font;
-
-/**
- * AWTBasedFont There should really be more documentation here.
- *
- * @author Kristian Duske
- * @version $Revision$
- * @since 30.07.2010
- */
-public abstract class AWTBasedFont implements IDraw3DFont {
-
- private static final char DEF_FIRST_CHAR = ' ';
-
- private static final int DEF_NUM_CHARS = 96;
-
- private char m_firstChar = Character.MAX_VALUE;
-
- private Font m_font;
-
- private char m_lastChar = Character.MIN_VALUE;
-
- public AWTBasedFont(String i_name, int i_size, Flag... i_flags) {
- if (i_name == null)
- throw new NullPointerException("i_name must not be null");
-
- m_font = new Font(i_name, Flag.getAWTStyle(i_flags), i_size);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.IDraw3DFont#createGlyphVector(java.lang.String)
- */
- public IDraw3DGlyphVector createGlyphVector(String i_string) {
- if (i_string == null)
- throw new NullPointerException("i_string must not be null");
-
- if (i_string.length() == 0)
- return null;
-
- return doCreateGlyphVector(i_string);
- }
-
- protected abstract IDraw3DGlyphVector doCreateGlyphVector(String i_string);
-
- protected Font getAwtFont() {
- return m_font;
- }
-}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AwtBasedFont.java (from rev 515, 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 (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AwtBasedFont.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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 java.awt.Font;
+
+/**
+ * Base class for all fonts that use an AWT font to create their font data.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 30.07.2010
+ */
+public abstract class AwtBasedFont implements IDraw3DFont {
+
+ private Font m_font;
+
+ /**
+ * Creates a new instance with the given parameters.
+ *
+ * @param i_name the name of the font
+ * @param i_size the font size
+ * @param i_flags the {@link Flag} array
+ */
+ public AwtBasedFont(String i_name, int i_size, Flag... i_flags) {
+ if (i_name == null)
+ throw new NullPointerException("i_name must not be null");
+
+ m_font = new Font(i_name, Flag.getAWTStyle(i_flags), i_size);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DFont#createText(java.lang.String)
+ */
+ public IDraw3DText createText(String i_string) {
+ if (i_string == null || i_string.trim().length() == 0)
+ return EmptyText.INSTANCE;
+
+ return doCreateText(i_string);
+ }
+
+ /**
+ * Creates an instanceof {@link IDraw3DText} that renders the given string,
+ * which is guaranteed to not be <code>null</code> or empty.
+ *
+ * @param i_string the string, which is neither <code>null</code> or empty
+ * @return the {@link IDraw3DText} instance
+ */
+ protected abstract IDraw3DText doCreateText(String i_string);
+
+ /**
+ * Returns the AWT font which this font is based on.
+ *
+ * @return the AWT font
+ */
+ protected Font getAwtFont() {
+ return m_font;
+ }
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AwtBasedTextureFont.java (from rev 515, 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/AwtBasedTextureFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AwtBasedTextureFont.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * 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 java.awt.RenderingHints.*;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
+import java.awt.font.LineMetrics;
+import java.awt.image.BufferedImage;
+
+/**
+ * Base class for fonts that use textures to render text. The textures are
+ * created by rendering text to AWT images.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 04.08.2010
+ */
+public abstract class AwtBasedTextureFont extends AwtBasedFont {
+
+ private boolean m_disposed = false;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_flags the font flags
+ * @see {@link Flag}
+ */
+ public AwtBasedTextureFont(String i_name, int i_size, Flag[] i_flags) {
+ super(i_name, i_size, i_flags);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DFont#dispose()
+ */
+ public void dispose() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is already disposed");
+
+ m_disposed = true;
+ }
+
+ /**
+ * Creates a {@link IDraw3DText} instance that renders a texture with the
+ * given image.
+ *
+ * @param i_image the image to render
+ * @return the {@link IDraw3DText} instance
+ */
+ protected abstract IDraw3DText doCreateText(BufferedImage i_image);
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.AwtBasedFont#doCreateText(String)
+ */
+ @Override
+ protected IDraw3DText doCreateText(String i_string) {
+ FontRenderContext ctx = new FontRenderContext(null, true, true);
+ 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_4BYTE_ABGR);
+
+ Graphics2D g = img.createGraphics();
+ g.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(KEY_ALPHA_INTERPOLATION,
+ VALUE_ALPHA_INTERPOLATION_QUALITY);
+ g.setRenderingHint(KEY_FRACTIONALMETRICS, VALUE_FRACTIONALMETRICS_ON);
+ g.setRenderingHint(KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_GASP);
+ g.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BICUBIC);
+ g.setRenderingHint(KEY_RENDERING, VALUE_RENDER_QUALITY);
+
+ g.setFont(getAwtFont());
+ g.setColor(Color.BLACK);
+ g.setBackground(new Color(1, 1, 1, 0));
+
+ g.clearRect(0, 0, bounds.width, bounds.height);
+ g.translate(0, lineMetrics.getAscent() - 1);
+
+ for (int i = 0; i < glyphs.getNumGlyphs(); i++) {
+ Shape outline = glyphs.getGlyphOutline(i);
+ g.fill(outline);
+ }
+
+ return doCreateText(img);
+ }
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/EmptyText.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/EmptyText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/EmptyText.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * An implementation of {@link IDraw3DText} that does nothing. This is useful
+ * for empty strings and such.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 17.08.2010
+ */
+public class EmptyText implements IDraw3DText {
+
+ /**
+ * A single instance.
+ */
+ public static final EmptyText INSTANCE = new EmptyText();
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DText#dispose()
+ */
+ public void dispose() {
+ // nothing to do
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DText#render()
+ */
+ public void render() {
+ // nothing to do
+ }
+}
Modified: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DFont.java 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DFont.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -13,16 +13,39 @@
import java.awt.Font;
/**
- * IDraw3DFont There should really be more documentation here.
+ * A font that can be used to render text in the Draw3D subsystem. Fonts are
+ * used to create instances of {@link IDraw3DText} which are then used to render
+ * the actual text.
*
* @author Kristian Duske
* @version $Revision$
* @since 30.07.2010
*/
public interface IDraw3DFont {
+ /**
+ * The font face flags.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 17.08.2010
+ */
public enum Flag {
- BOLD, ITALIC;
+ /**
+ * The bold font face.
+ */
+ BOLD,
+ /**
+ * The italic font face.
+ */
+ ITALIC;
+ /**
+ * Returns the AWT style value for the given flags.
+ *
+ * @param i_flags the flags
+ * @return the AWT style
+ * @see Font#getStyle()
+ */
public static int getAWTStyle(Flag... i_flags) {
int style = 0;
for (Flag flag : i_flags) {
@@ -40,6 +63,14 @@
return style;
}
+ /**
+ * Returns an array containing the flags that represent the given
+ * parameters.
+ *
+ * @param i_bold whether the flags should include {@link #BOLD}
+ * @param i_italic whether the flags should include {@link #ITALIC}
+ * @return the flag array
+ */
public static Flag[] getFlags(boolean i_bold, boolean i_italic) {
if (i_bold && i_italic)
return new Flag[] { BOLD, ITALIC };
@@ -51,9 +82,17 @@
}
}
- public void initialize();
+ /**
+ * Creates an instance of {@link IDraw3DText} for the given string.
+ *
+ * @param i_string the string to render
+ * @return an instance of {@link IDraw3DText} that renders the given string
+ * @throws IllegalStateException if this font is disposed
+ */
+ public IDraw3DText createText(String i_string);
- public IDraw3DGlyphVector createGlyphVector(String i_string);
-
+ /**
+ * Disposes all resources associated with this font.
+ */
public void dispose();
}
Deleted: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DGlyphVector.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DGlyphVector.java 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DGlyphVector.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * 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;
-
-/**
- * IDraw3DText
- * There should really be more documentation here.
- *
- * @author Kristian Duske
- * @version $Revision$
- * @since 30.07.2010
- */
-public interface IDraw3DGlyphVector {
- public void render();
-
- public void dispose();
-}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DText.java (from rev 513, branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DGlyphVector.java)
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DText.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Represents a renderable chunk of text. Such a text chunk can be rendered
+ * repeatedly until it is disposed.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 30.07.2010
+ */
+public interface IDraw3DText {
+ /**
+ * Disposes all resources associated with this text.
+ */
+ public void dispose();
+
+ /**
+ * Renders this text.
+ *
+ * @throws IllegalStateException if this text chunk is disposed
+ */
+ public void render();
+}
Modified: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglAWTGlyphCallback.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglAWTGlyphCallback.java 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglAWTGlyphCallback.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -14,6 +14,18 @@
import org.lwjgl.util.glu.GLUtessellatorCallbackAdapter;
+/**
+ * This instance of {@link GLUtessellatorCallbackAdapter} collects vertex data
+ * that occurs during the tesselation of a string. After each character, the
+ * vertex data, which consists of triangle strips, triangle fans and triangle
+ * sets, can be collected by calling {@link #createVectorChar(float, float)}. To
+ * reset the internal state of this callback object, the {@link #reset()}
+ * function must be called.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 17.08.2010
+ */
public class LwjglAWTGlyphCallback extends GLUtessellatorCallbackAdapter {
private float[][] m_fans = new float[3][];
@@ -24,11 +36,11 @@
private int m_numStrips = 0;
- private int m_numTris = 0;
+ private int m_numSets = 0;
private float[][] m_strips = new float[3][];
- private float[][] m_tris = new float[3][];
+ private float[][] m_sets = new float[3][];
private int m_type;
@@ -58,6 +70,28 @@
}
/**
+ * Creates an instance of {@link VectorChar} that represents the current
+ * character data.
+ *
+ * @param i_advX the value by which the X position must be advanced after
+ * this character was rendered
+ * @param i_advY the value by which the Y position must be advanced after
+ * this character was rendered
+ * @return the {@link VectorChar} instance that represents the current
+ * character data
+ */
+ public VectorChar createVectorChar(float i_advX, float i_advY) {
+ VectorChar result = new VectorChar(i_advX, i_advY);
+ if (m_numFans > 0)
+ result.setTriangleFans(m_fans, m_numFans);
+ if (m_numStrips > 0)
+ result.setTriangleStrips(m_strips, m_numStrips);
+ if (m_numSets > 0)
+ result.setTriangleSets(m_sets, m_numSets);
+ return result;
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#end()
@@ -80,11 +114,11 @@
m_strips[m_numStrips++] = strip;
break;
case GL_TRIANGLES:
- if (m_numTris == m_tris.length)
- m_tris = resize(m_tris);
+ if (m_numSets == m_sets.length)
+ m_sets = resize(m_sets);
float[] tris = new float[m_index];
System.arraycopy(m_vertices, 0, tris, 0, tris.length);
- m_tris[m_numTris++] = tris;
+ m_sets[m_numSets++] = tris;
break;
default:
throw new IllegalStateException(
@@ -103,10 +137,13 @@
+ i_errnum);
}
+ /**
+ * Resets the internal state of this callback object.
+ */
public void reset() {
m_numFans = 0;
m_numStrips = 0;
- m_numTris = 0;
+ m_numSets = 0;
}
private float[][] resize(float[][] i_array) {
@@ -115,17 +152,6 @@
return resized;
}
- public VectorChar createVectorChar(float i_advX, float i_advY) {
- VectorChar result = new VectorChar(i_advX, i_advY);
- if (m_numFans > 0)
- result.setTriangleFans(m_fans, m_numFans);
- if (m_numStrips > 0)
- result.setTriangleStrips(m_strips, m_numStrips);
- if (m_numTris > 0)
- result.setTriangles(m_tris, m_numTris);
- return result;
- }
-
/**
* {@inheritDoc}
*
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 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureFont.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -10,29 +10,25 @@
******************************************************************************/
package org.eclipse.draw3d.font;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-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.awt.image.DataBufferByte;
-import java.awt.image.Raster;
/**
- * LwjglTextureFont There should really be more documentation here.
+ * A font that renders text using textures created by rendering AWT font onto an
+ * image.
*
* @author Kristian Duske
* @version $Revision$
- * @since 04.08.2010
+ * @since 17.08.2010
*/
-public class LwjglTextureFont extends AWTBasedFont {
+public class LwjglTextureFont extends AwtBasedTextureFont {
- private boolean m_disposed = false;
-
+ /**
+ * Creates a new instance.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_flags the flags
+ */
public LwjglTextureFont(String i_name, int i_size, Flag[] i_flags) {
super(i_name, i_size, i_flags);
}
@@ -40,69 +36,11 @@
/**
* {@inheritDoc}
*
- * @see org.eclipse.draw3d.font.AWTBasedFont#doCreateGlyphVector(String)
+ * @see org.eclipse.draw3d.font.AwtBasedTextureFont#doCreateText(java.awt.image.BufferedImage)
*/
@Override
- protected IDraw3DGlyphVector doCreateGlyphVector(String i_string) {
- FontRenderContext ctx = new FontRenderContext(null, true, true);
- 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);
-
- Graphics2D g = img.createGraphics();
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
- RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
- RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- g.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
- g.setColor(Color.WHITE);
- g.fillRect(0, 0, bounds.width, bounds.height);
-
- g.translate(0, lineMetrics.getAscent() - 1);
- g.setColor(Color.BLACK);
- g.setFont(getAwtFont());
-
- for (int i = 0; i < glyphs.getNumGlyphs(); i++) {
- Shape outline = glyphs.getGlyphOutline(i);
- g.fill(outline);
- }
-
- Raster data = img.getData();
- DataBufferByte dataBuffer = (DataBufferByte) data.getDataBuffer();
-
- return null;
+ protected IDraw3DText doCreateText(BufferedImage i_image) {
+ return new LwjglTextureText(i_image);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.IDraw3DFont#dispose()
- */
- public void dispose() {
- if (m_disposed)
- throw new IllegalStateException(this + " is already disposed");
-
- m_disposed = true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.IDraw3DFont#initialize()
- */
- public void initialize() {
- // nothing to initialize
- }
-
}
Deleted: 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 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureGlyphVector.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * 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");
- }
-
-}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureText.java (from rev 515, 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/LwjglTextureText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureText.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * 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.Raster;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+
+import org.eclipse.draw3d.util.BufferUtils;
+import org.eclipse.draw3d.util.Draw3DCache;
+
+/**
+ * Renders a
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 16.08.2010
+ */
+public class LwjglTextureText implements IDraw3DText {
+
+ private enum State {
+ DISPOSED, INITIALIZED, UNINITIALIZED
+ }
+
+ private int m_height;
+
+ private BufferedImage m_image;
+
+ private State m_state = State.UNINITIALIZED;
+
+ private int m_textureId = 0;
+
+ private int m_width;
+
+ /**
+ * Creates a new instance that renders a texture created from the given
+ * image.
+ *
+ * @param i_image the image to render
+ * @throws NullPointerException if the given image is <code>null</code>
+ */
+ public LwjglTextureText(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.IDraw3DText#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() {
+ Raster data = m_image.getData();
+ m_width = data.getWidth();
+ m_height = data.getHeight();
+ ByteBuffer buf = BufferUtils.createByteBuffer(m_width * m_height * 2);
+
+ int[] pixel = new int[4];
+ for (int y = m_height - 1; y >= 0; y--) {
+ for (int x = 0; x < m_width; x++) {
+ data.getPixel(x, y, pixel);
+ int r = pixel[0];
+ int g = pixel[1];
+ int b = pixel[2];
+ int a = pixel[3];
+ int l = (int) (0.3f * r + 0.59f * g + 0.11f * b);
+ buf.put((byte) (l & 0xFF));
+ buf.put((byte) (a & 0xFF));
+ }
+ }
+
+ buf.rewind();
+
+ IntBuffer idBuf = Draw3DCache.getIntBuffer(1);
+ glPushAttrib(GL_TEXTURE_BIT);
+ try {
+ glGenTextures(idBuf);
+ m_textureId = idBuf.get(0);
+
+ glBindTexture(GL_TEXTURE_2D, m_textureId);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, m_width,
+ m_height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buf);
+
+ // GLU.gluBuild2DMipmaps(m_textureId, 2, m_width,
+ // m_height,
+ // GL_LUMINANCE_ALPHA, GL11.GL_UNSIGNED_BYTE,
+ // buffer);
+ } finally {
+ Draw3DCache.returnIntBuffer(idBuf);
+ glPopAttrib();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DText#render()
+ */
+ public void render() {
+ if (m_state == State.DISPOSED)
+ throw new IllegalStateException(this + " is disposed");
+ else if (m_state == State.UNINITIALIZED)
+ initialize();
+
+ glBindTexture(GL_TEXTURE_2D, m_textureId);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0);
+ glVertex2f(0, m_height);
+ glTexCoord2f(1, 0);
+ glVertex2f(m_width, m_height);
+ glTexCoord2f(1, 1);
+ glVertex2f(m_width, 0);
+ glTexCoord2f(0, 1);
+ glVertex2f(0, 0);
+ glEnd();
+ }
+}
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 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorFont.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -14,6 +14,7 @@
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphMetrics;
import java.awt.font.GlyphVector;
+import java.awt.font.LineMetrics;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;
@@ -21,13 +22,13 @@
import org.lwjgl.util.glu.GLUtessellator;
/**
- * LwjglVectorFont There should really be more documentation here.
+ * A font that uses vector font data to render text directly.
*
* @author Kristian Duske
* @version $Revision$
* @since 30.07.2010
*/
-public class LwjglVectorFont extends AWTBasedFont {
+public class LwjglVectorFont extends AwtBasedFont {
private LwjglAWTGlyphCallback m_callback;
@@ -47,6 +48,19 @@
*/
private float[][] m_vBuf = new float[8][2];
+ /**
+ * Creates a new instance. The given precision factor must be between 0 and
+ * 1 (inclusive) and indicates how precisely the font data should be
+ * tesselated. A value of 1 means high precision and produces more vertices
+ * than a value of 0, which means lowest precision.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_precision the precision factor
+ * @param i_flags the flags
+ * @see AwtBasedFont#AwtBasedFont(String, int,
+ * org.eclipse.draw3d.font.IDraw3DFont.Flag...)
+ */
public LwjglVectorFont(String i_name, int i_size, float i_precision,
Flag... i_flags) {
super(i_name, i_size, i_flags);
@@ -56,6 +70,29 @@
"precision must be between 0 and 1, inclusive");
m_precision = i_precision;
+
+ m_tesselator = GLU.gluNewTess();
+ m_callback = new LwjglAWTGlyphCallback();
+
+ // bug in LWJGL, must set edge flag callback to null before setting
+ // begin callback
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_EDGE_FLAG, null);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_EDGE_FLAG_DATA, null);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN, m_callback);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN_DATA, null);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_VERTEX, m_callback);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_VERTEX_DATA, null);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE, m_callback);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE_DATA, null);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_END, m_callback);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_END_DATA, null);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_ERROR, m_callback);
+ m_tesselator.gluTessCallback(GLU.GLU_TESS_ERROR_DATA, null);
+
+ m_tesselator.gluTessProperty(GLU.GLU_TESS_TOLERANCE, 0);
+ m_tesselator.gluTessProperty(GLU.GLU_TESS_BOUNDARY_ONLY, 0);
+
+ m_tesselator.gluTessNormal(0, 0, -1);
}
private VectorChar createVectorChar(GlyphVector i_glyphs, int i_index,
@@ -135,55 +172,26 @@
/**
* {@inheritDoc}
*
- * @see org.eclipse.draw3d.font.AWTBasedFont#doCreateGlyphVector(String)
+ * @see org.eclipse.draw3d.font.AwtBasedFont#doCreateText(String)
*/
@Override
- protected IDraw3DGlyphVector doCreateGlyphVector(String i_string) {
+ protected IDraw3DText doCreateText(String i_string) {
FontRenderContext ctx = new FontRenderContext(null, true, false);
+ LineMetrics lineMetrics = getAwtFont().getLineMetrics(i_string, ctx);
GlyphVector glyphs = getAwtFont().createGlyphVector(ctx, i_string);
AffineTransform at = new AffineTransform();
- at.translate(0, getAwtFont().getSize());
+ at.translate(0, lineMetrics.getAscent() - 1);
- double flatness = 1.9d * (1 - m_precision) + 0.1d;
+ double flatness = 1.9d * m_precision + 0.1d;
VectorChar[] stringChars = new VectorChar[glyphs.getNumGlyphs()];
for (int i = 0; i < glyphs.getNumGlyphs(); i++)
stringChars[i] = createVectorChar(glyphs, i, at, flatness);
- return new LwjglVectorGlyphVector(stringChars);
+ return new LwjglVectorText(stringChars);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.IDraw3DFont#initialize()
- */
- public void initialize() {
- m_tesselator = GLU.gluNewTess();
- m_callback = new LwjglAWTGlyphCallback();
-
- // bug in LWJGL, must set edge flag callback to null before setting
- // begin callback
- m_tesselator.gluTessCallback(GLU.GLU_TESS_EDGE_FLAG, null);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_EDGE_FLAG_DATA, null);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN, m_callback);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN_DATA, null);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_VERTEX, m_callback);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_VERTEX_DATA, null);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE, m_callback);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE_DATA, null);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_END, m_callback);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_END_DATA, null);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_ERROR, m_callback);
- m_tesselator.gluTessCallback(GLU.GLU_TESS_ERROR_DATA, null);
-
- m_tesselator.gluTessProperty(GLU.GLU_TESS_TOLERANCE, 0);
- m_tesselator.gluTessProperty(GLU.GLU_TESS_BOUNDARY_ONLY, 0);
-
- m_tesselator.gluTessNormal(0, 0, -1);
- }
-
private float[][] resizeVertexBuffer(float[][] i_v) {
float[][] r = new float[2 * i_v.length][];
System.arraycopy(i_v, 0, r, 0, i_v.length);
Deleted: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorGlyphVector.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorGlyphVector.java 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorGlyphVector.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -1,169 +0,0 @@
-/*******************************************************************************
- * 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 static org.lwjgl.opengl.GL14.*;
-import static org.lwjgl.opengl.GL15.*;
-
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-
-import org.eclipse.draw3d.util.BufferUtils;
-import org.eclipse.draw3d.util.Draw3DCache;
-
-/**
- * VectorText There should really be more documentation here.
- *
- * @author Kristian Duske
- * @version $Revision$
- * @since 30.07.2010
- */
-public class LwjglVectorGlyphVector implements IDraw3DGlyphVector {
-
- private boolean m_disposed = false;
-
- private IntBuffer m_fanIdx;
-
- private IntBuffer m_fanCnt;
-
- private IntBuffer m_stripCnt;
-
- private IntBuffer m_triCnt;
-
- private IntBuffer m_stripIdx;
-
- private IntBuffer m_triIdx;
-
- private int m_bufferId;
-
- public LwjglVectorGlyphVector(VectorChar[] i_chars) {
- if (i_chars == null)
- throw new NullPointerException("i_chars must not be null");
-
- // create vertex buffer
- int numFans = 0;
- int numStrips = 0;
- int numTris = 0;
- int numVertices = 0;
- for (int i = 0; i < i_chars.length; i++) {
- numFans += i_chars[i].getNumFans();
- numStrips += i_chars[i].getNumStrips();
- numTris += i_chars[i].getNumTris();
- numVertices += i_chars[i].getNumVertices();
- }
-
- if (numFans > 0) {
- m_fanIdx = BufferUtils.createIntBuffer(numFans);
- m_fanCnt = BufferUtils.createIntBuffer(numFans);
- }
- if (numStrips > 0) {
- m_stripIdx = BufferUtils.createIntBuffer(numStrips);
- m_stripCnt = BufferUtils.createIntBuffer(numStrips);
- }
- if (numTris > 0) {
- m_triIdx = BufferUtils.createIntBuffer(numTris);
- m_triCnt = BufferUtils.createIntBuffer(numTris);
- }
-
- float x = 0;
- float y = 0;
-
- int i = 0;
- FloatBuffer buf = BufferUtils.createFloatBuffer(2 * numVertices);
- for (int j = 0; j < i_chars.length; j++) {
- i = i_chars[j].compileFans(buf, i, m_fanIdx, m_fanCnt, x, y);
- i = i_chars[j].compileStrips(buf, i, m_stripIdx, m_stripCnt, x, y);
- i = i_chars[j].compileTriangles(buf, i, m_triIdx, m_triCnt, x, y);
- x += i_chars[j].getAdvanceX();
- y += i_chars[j].getAdvanceY();
- }
-
- // upload vertex buffer
- IntBuffer idBuffer = Draw3DCache.getIntBuffer(1);
- try {
- idBuffer.rewind();
- glGenBuffers(idBuffer);
-
- m_bufferId = idBuffer.get(0);
- buf.rewind();
-
- glBindBuffer(GL_ARRAY_BUFFER, m_bufferId);
- glBufferData(GL_ARRAY_BUFFER, buf, GL_STREAM_READ);
- } finally {
- Draw3DCache.returnIntBuffer(idBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.IDraw3DGlyphVector#render()
- */
- public void render() {
- if (m_disposed)
- throw new IllegalStateException(this + " is disposed");
-
- // TODO: move this to initialization if possible
- if (m_fanIdx != null) {
- m_fanIdx.rewind();
- m_fanCnt.rewind();
- }
-
- if (m_stripIdx != null) {
- m_stripIdx.rewind();
- m_stripCnt.rewind();
- }
-
- if (m_triIdx != null) {
- m_triIdx.rewind();
- m_triCnt.rewind();
- }
-
- glBindBuffer(GL_ARRAY_BUFFER, m_bufferId);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, 0);
- try {
- if (m_fanIdx != null)
- glMultiDrawArrays(GL_TRIANGLE_FAN, m_fanIdx, m_fanCnt);
- if (m_stripIdx != null)
- glMultiDrawArrays(GL_TRIANGLE_STRIP, m_stripIdx, m_stripCnt);
- if (m_triIdx != null)
- glMultiDrawArrays(GL_TRIANGLES, m_triIdx, m_triCnt);
- } finally {
- glDisableClientState(GL_VERTEX_ARRAY);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.IDraw3DGlyphVector#dispose()
- */
- public void dispose() {
- if (m_disposed)
- throw new IllegalStateException(this + " is disposed");
-
- if (m_bufferId != 0) {
- IntBuffer idBuffer = Draw3DCache.getIntBuffer(1);
- try {
- BufferUtils.put(idBuffer, m_bufferId);
- glDeleteBuffers(idBuffer);
- m_bufferId = 0;
- } finally {
- Draw3DCache.returnIntBuffer(idBuffer);
- }
- }
-
- m_disposed = true;
- }
-}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java (from rev 513, branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorGlyphVector.java)
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * 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 static org.lwjgl.opengl.GL14.*;
+import static org.lwjgl.opengl.GL15.*;
+
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+
+import org.eclipse.draw3d.util.BufferUtils;
+import org.eclipse.draw3d.util.Draw3DCache;
+
+/**
+ * Renders a string using OpenGL vertex and index buffers.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 30.07.2010
+ */
+public class LwjglVectorText implements IDraw3DText {
+
+ private int m_bufferId;
+
+ private boolean m_disposed = false;
+
+ private IntBuffer m_fanCnt;
+
+ private IntBuffer m_fanIdx;
+
+ private IntBuffer m_stripCnt;
+
+ private IntBuffer m_stripIdx;
+
+ private IntBuffer m_triCnt;
+
+ private IntBuffer m_triIdx;
+
+ /**
+ * Creates a new instance that renders the given characters.
+ *
+ * @param i_chars the characters to render
+ * @throws NullPointerException if the given character array is
+ * <code>null</code>
+ */
+ public LwjglVectorText(VectorChar[] i_chars) {
+ if (i_chars == null)
+ throw new NullPointerException("i_chars must not be null");
+
+ // create vertex buffer
+ int numFans = 0;
+ int numStrips = 0;
+ int numTris = 0;
+ int numVertices = 0;
+ for (int i = 0; i < i_chars.length; i++) {
+ numFans += i_chars[i].getNumFans();
+ numStrips += i_chars[i].getNumStrips();
+ numTris += i_chars[i].getNumSets();
+ numVertices += i_chars[i].getNumVertices();
+ }
+
+ if (numFans > 0) {
+ m_fanIdx = BufferUtils.createIntBuffer(numFans);
+ m_fanCnt = BufferUtils.createIntBuffer(numFans);
+ }
+ if (numStrips > 0) {
+ m_stripIdx = BufferUtils.createIntBuffer(numStrips);
+ m_stripCnt = BufferUtils.createIntBuffer(numStrips);
+ }
+ if (numTris > 0) {
+ m_triIdx = BufferUtils.createIntBuffer(numTris);
+ m_triCnt = BufferUtils.createIntBuffer(numTris);
+ }
+
+ float x = 0;
+ float y = 0;
+
+ int i = 0;
+ FloatBuffer buf = BufferUtils.createFloatBuffer(2 * numVertices);
+ for (int j = 0; j < i_chars.length; j++) {
+ i = i_chars[j].compileFans(buf, i, m_fanIdx, m_fanCnt, x, y);
+ i = i_chars[j].compileStrips(buf, i, m_stripIdx, m_stripCnt, x, y);
+ i = i_chars[j].compileSets(buf, i, m_triIdx, m_triCnt, x, y);
+ x += i_chars[j].getAdvanceX();
+ y += i_chars[j].getAdvanceY();
+ }
+
+ // upload vertex buffer
+ IntBuffer idBuffer = Draw3DCache.getIntBuffer(1);
+ try {
+ idBuffer.rewind();
+ glGenBuffers(idBuffer);
+
+ m_bufferId = idBuffer.get(0);
+ buf.rewind();
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_bufferId);
+ glBufferData(GL_ARRAY_BUFFER, buf, GL_STREAM_READ);
+ } finally {
+ Draw3DCache.returnIntBuffer(idBuffer);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DText#dispose()
+ */
+ public void dispose() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ if (m_bufferId != 0) {
+ IntBuffer idBuffer = Draw3DCache.getIntBuffer(1);
+ try {
+ BufferUtils.put(idBuffer, m_bufferId);
+ glDeleteBuffers(idBuffer);
+ m_bufferId = 0;
+ } finally {
+ Draw3DCache.returnIntBuffer(idBuffer);
+ }
+ }
+
+ m_disposed = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.IDraw3DText#render()
+ */
+ public void render() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ // TODO: move this to initialization if possible
+ if (m_fanIdx != null) {
+ m_fanIdx.rewind();
+ m_fanCnt.rewind();
+ }
+
+ if (m_stripIdx != null) {
+ m_stripIdx.rewind();
+ m_stripCnt.rewind();
+ }
+
+ if (m_triIdx != null) {
+ m_triIdx.rewind();
+ m_triCnt.rewind();
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_bufferId);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2, GL_FLOAT, 0, 0);
+ try {
+ if (m_fanIdx != null)
+ glMultiDrawArrays(GL_TRIANGLE_FAN, m_fanIdx, m_fanCnt);
+ if (m_stripIdx != null)
+ glMultiDrawArrays(GL_TRIANGLE_STRIP, m_stripIdx, m_stripCnt);
+ if (m_triIdx != null)
+ glMultiDrawArrays(GL_TRIANGLES, m_triIdx, m_triCnt);
+ } finally {
+ glDisableClientState(GL_VERTEX_ARRAY);
+ }
+ }
+}
Deleted: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/TextureChar.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/TextureChar.java 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/TextureChar.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * 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;
-
-/**
- * TextureChar
- * There should really be more documentation here.
- *
- * @author Kristian Duske
- * @version $Revision$
- * @since 04.08.2010
- */
-public class TextureChar {
-
-}
Modified: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/VectorChar.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/VectorChar.java 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/VectorChar.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -13,6 +13,13 @@
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
+/**
+ * Stores vector data for a single character.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 17.08.2010
+ */
public class VectorChar {
private float m_advX;
@@ -25,14 +32,34 @@
private float[][] m_strips;
- private float[][] m_tris;
+ private float[][] m_sets;
+ /**
+ * Creates a new vector char with the given advance values.
+ *
+ * @param i_advX the value by which to advance the current X position after
+ * this char was rendered
+ * @param i_advY the value by which to advance the current Y position after
+ * this char was rendered
+ */
public VectorChar(float i_advX, float i_advY) {
m_advX = i_advX;
m_advY = i_advY;
}
- public int compileFans(FloatBuffer i_buffer, int i_index,
+ /**
+ * Compiles the triangle fans stored in this character into the given
+ * buffers.
+ *
+ * @param i_vertices the vertex buffer
+ * @param i_index the current index into the vertex buffer
+ * @param i_indices the index buffer
+ * @param i_counts the vertex count buffer
+ * @param i_x the X translation
+ * @param i_y the Y translation
+ * @return the new index into the vertex buffer
+ */
+ public int compileFans(FloatBuffer i_vertices, int i_index,
IntBuffer i_indices, IntBuffer i_counts, float i_x, float i_y) {
if (m_fans == null || m_fans.length == 0)
return i_index;
@@ -41,8 +68,8 @@
for (int i = 0; i < m_fans.length; i++) {
int count = m_fans[i].length / 2;
for (int j = 0; j < count; j++) {
- i_buffer.put(m_fans[i][2 * j] + i_x);
- i_buffer.put(m_fans[i][2 * j + 1] + i_y);
+ i_vertices.put(m_fans[i][2 * j] + i_x);
+ i_vertices.put(m_fans[i][2 * j + 1] + i_y);
}
i_indices.put(index);
i_counts.put(count);
@@ -51,7 +78,19 @@
return index;
}
- public int compileStrips(FloatBuffer i_buffer, int i_index,
+ /**
+ * Compiles the triangle strips stored in this character into the given
+ * buffers.
+ *
+ * @param i_vertices the vertex buffer
+ * @param i_index the current index into the vertex buffer
+ * @param i_indices the index buffer
+ * @param i_counts the vertex count buffer
+ * @param i_x the X translation
+ * @param i_y the Y translation
+ * @return the new index into the vertex buffer
+ */
+ public int compileStrips(FloatBuffer i_vertices, int i_index,
IntBuffer i_indices, IntBuffer i_counts, float i_x, float i_y) {
if (m_strips == null || m_strips.length == 0)
return i_index;
@@ -60,8 +99,8 @@
for (int i = 0; i < m_strips.length; i++) {
int count = m_strips[i].length / 2;
for (int j = 0; j < count; j++) {
- i_buffer.put(m_strips[i][2 * j] + i_x);
- i_buffer.put(m_strips[i][2 * j + 1] + i_y);
+ i_vertices.put(m_strips[i][2 * j] + i_x);
+ i_vertices.put(m_strips[i][2 * j + 1] + i_y);
}
i_indices.put(index);
i_counts.put(count);
@@ -70,17 +109,29 @@
return index;
}
- public int compileTriangles(FloatBuffer i_buffer, int i_index,
+ /**
+ * Compiles the triangle sets stored in this character into the given
+ * buffers.
+ *
+ * @param i_vertices the vertex buffer
+ * @param i_index the current index into the vertex buffer
+ * @param i_indices the index buffer
+ * @param i_counts the vertex count buffer
+ * @param i_x the X translation
+ * @param i_y the Y translation
+ * @return the new index into the vertex buffer
+ */
+ public int compileSets(FloatBuffer i_vertices, int i_index,
IntBuffer i_indices, IntBuffer i_counts, float i_x, float i_y) {
- if (m_tris == null || m_tris.length == 0)
+ if (m_sets == null || m_sets.length == 0)
return i_index;
int index = i_index;
- for (int i = 0; i < m_tris.length; i++) {
- int count = m_tris[i].length / 2;
+ for (int i = 0; i < m_sets.length; i++) {
+ int count = m_sets[i].length / 2;
for (int j = 0; j < count; j++) {
- i_buffer.put(m_tris[i][2 * j] + i_x);
- i_buffer.put(m_tris[i][2 * j + 1] + i_y);
+ i_vertices.put(m_sets[i][2 * j] + i_x);
+ i_vertices.put(m_sets[i][2 * j + 1] + i_y);
}
i_indices.put(index);
i_counts.put(count);
@@ -89,30 +140,71 @@
return index;
}
+ /**
+ * Returns the value by which to advance the current X position after this
+ * character is rendered.
+ *
+ * @return the X advance
+ */
public float getAdvanceX() {
return m_advX;
}
+ /**
+ * Returns the value by which to advance the current Y position after this
+ * character is rendered.
+ *
+ * @return the Y advance
+ */
public float getAdvanceY() {
return m_advY;
}
+ /**
+ * Returns the number of triangle fans stored in this char.
+ *
+ * @return the number of triangle fans
+ */
public int getNumFans() {
return m_fans == null ? 0 : m_fans.length;
}
+ /**
+ * Returns the number of triangle strips stored in this char.
+ *
+ * @return the number of triangle strips
+ */
public int getNumStrips() {
return m_strips == null ? 0 : m_strips.length;
}
- public int getNumTris() {
- return m_tris == null ? 0 : m_tris.length;
+ /**
+ * Returns the number of triangle sets stored in this char.
+ *
+ * @return the number of triangle sets
+ */
+ public int getNumSets() {
+ return m_sets == null ? 0 : m_sets.length;
}
+ /**
+ * Returns the total number of vertices in this char.
+ *
+ * @return the total number of vertices
+ */
public int getNumVertices() {
return m_numVertices;
}
+ /**
+ * Sets the triangle fans of this char. The given two dimensional array
+ * stores the individual fans in the first dimension and the vector data for
+ * each fan in the second dimension. The first dimension may be larger than
+ * the actual number of fans, which is indicated by the second parameter
+ *
+ * @param i_data the triangle fans
+ * @param i_num the actual number of triangle fans
+ */
public void setTriangleFans(float[][] i_data, int i_num) {
m_fans = new float[i_num][];
for (int i = 0; i < i_num; i++) {
@@ -121,14 +213,33 @@
}
}
- public void setTriangles(float[][] i_data, int i_num) {
- m_tris = new float[i_num][];
+ /**
+ * Sets the triangle sets of this char. The given two dimensional array
+ * stores the individual sets in the first dimension and the vector data for
+ * each set in the second dimension. The first dimension may be larger than
+ * the actual number of sets, which is indicated by the second parameter
+ *
+ * @param i_data the triangle sets
+ * @param i_num the actual number of triangle sets
+ */
+ public void setTriangleSets(float[][] i_data, int i_num) {
+ m_sets = new float[i_num][];
for (int i = 0; i < i_num; i++) {
- m_tris[i] = i_data[i];
- m_numVertices += m_tris[i].length / 2;
+ m_sets[i] = i_data[i];
+ m_numVertices += m_sets[i].length / 2;
}
}
+ /**
+ * Sets the triangle strips of this char. The given two dimensional array
+ * stores the individual strips in the first dimension and the vector data
+ * for each strip in the second dimension. The first dimension may be larger
+ * than the actual number of strips, which is indicated by the second
+ * parameter
+ *
+ * @param i_data the triangle strips
+ * @param i_num the actual number of triangle strips
+ */
public void setTriangleStrips(float[][] i_data, int i_num) {
m_strips = new float[i_num][];
for (int i = 0; i < i_num; i++) {
Modified: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/viewer/Draw3DFontViewer.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/viewer/Draw3DFontViewer.java 2010-08-16 15:48:47 UTC (rev 515)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/viewer/Draw3DFontViewer.java 2010-08-17 10:26:41 UTC (rev 516)
@@ -6,7 +6,7 @@
import java.awt.GraphicsEnvironment;
import org.eclipse.draw3d.font.IDraw3DFont;
-import org.eclipse.draw3d.font.IDraw3DGlyphVector;
+import org.eclipse.draw3d.font.IDraw3DText;
import org.eclipse.draw3d.font.LwjglTextureFont;
import org.eclipse.draw3d.font.LwjglVectorFont;
import org.eclipse.draw3d.font.IDraw3DFont.Flag;
@@ -70,6 +70,10 @@
private Label m_precLabel;
+ private Button m_typeVector;
+
+ private Button m_typeTexture;
+
/**
* The constructor.
*/
@@ -166,18 +170,19 @@
Flag[] flags =
Flag.getFlags(m_bold.getSelection(),
m_italic.getSelection());
- float p = m_precision.getSelection() / 100f;
- IDraw3DFont font =
- new LwjglVectorFont(name, size, p, flags);
- font.initialize();
- IDraw3DGlyphVector glyphs =
- font.createGlyphVector("The quick brown fox jumps over the lazy dog.");
+ IDraw3DFont font = null;
+ if (m_typeVector.getSelection()) {
+ float p = m_precision.getSelection() / 100f;
+ font = new LwjglVectorFont(name, size, p, flags);
+ } else {
+ font = new LwjglTextureFont(name, size, flags);
+ }
+
+ IDraw3DText glyphs =
+ font.createText("The quick brown fox jumps over the lazy dog.");
glyphs.render();
glyphs.dispose();
font.dispose();
-
- IDraw3DFont tFont = new LwjglTextureFont(name, size, flags);
- tFont.createGlyphVector("The quick brown fox jumps over the lazy dog.");
}
m_canvas.swapBuffers();
@@ -272,7 +277,33 @@
});
m_precLabel = new Label(container, SWT.NONE);
- m_precLabel.setLayoutData(new RowData(100, 24));
+ m_precLabel.setLayoutData(new RowData(80, 24));
+
+ m_typeVector = new Button(container, SWT.RADIO);
+ m_typeVector.setText("Vector");
+ m_typeVector.setSelection(true);
+ m_typeVector.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent i_e) {
+ m_canvas.redraw();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent i_e) {
+ widgetSelected(i_e);
+ }
+ });
+
+ m_typeTexture = new Button(container, SWT.RADIO);
+ m_typeTexture.setText("Texture");
+ m_typeTexture.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent i_e) {
+ m_canvas.redraw();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent i_e) {
+ widgetSelected(i_e);
+ }
+ });
+
}
private Composite createContainer(Composite i_parent) {