[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[gef3d-commits] r519 - in branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font: . lwjgl multi simple viewer
|
- From: genie@xxxxxxxxxxx
- Date: Wed, 18 Aug 2010 07:53:03 -0400 (EDT)
- Delivered-to: gef3d-commits@eclipse.org
Author: kduske
Date: 2010-08-18 07:53:03 -0400 (Wed, 18 Aug 2010)
New Revision: 519
Added:
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglGlyphCallback.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglMultiFontManager.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureFontManager.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorFontManager.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/VectorChar.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFontManager.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFontManager.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/AwtBasedFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/AwtBasedTextureFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/EmptyText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/FontManagerBase.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DFont.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DFontManager.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DText.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/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/IDraw3DFont.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/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/LwjglTextureText.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/LwjglVectorText.java
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/VectorChar.java
Modified:
branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/viewer/Draw3DFontViewer.java
Log:
Cleanup, javadoc, and implemented LOD-aware fonts.
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-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AwtBasedFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,73 +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;
-import java.awt.font.FontRenderContext;
-
-/**
- * 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;
-
- FontRenderContext ctx = new FontRenderContext(null, true, true);
- return doCreateText(i_string, ctx);
- }
-
- /**
- * 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
- * @param i_context the font rendering context
- * @return the {@link IDraw3DText} instance
- */
- protected abstract IDraw3DText doCreateText(String i_string,
- FontRenderContext i_context);
-
- /**
- * Returns the AWT font which this font is based on.
- *
- * @return the AWT font
- */
- protected Font getAwtFont() {
- return m_font;
- }
-}
Deleted: 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/AwtBasedTextureFont.java 2010-08-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/AwtBasedTextureFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,111 +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 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,
- * FontRenderContext)
- */
- @Override
- protected IDraw3DText doCreateText(String i_string,
- FontRenderContext i_context) {
- GlyphVector glyphs =
- getAwtFont().createGlyphVector(i_context, i_string);
- LineMetrics lineMetrics =
- getAwtFont().getLineMetrics(i_string, i_context);
- Rectangle bounds = glyphs.getPixelBounds(i_context, 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, bounds.height - lineMetrics.getDescent() - 0.5f);
-
- for (int i = 0; i < glyphs.getNumGlyphs(); i++) {
- Shape outline = glyphs.getGlyphOutline(i);
- g.fill(outline);
- }
-
- return doCreateText(img);
- }
-}
Deleted: 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 2010-08-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/EmptyText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,45 +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;
-
-/**
- * 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
- }
-}
Deleted: 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-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,98 +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;
-
-/**
- * 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 {
- /**
- * 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) {
- switch (flag) {
- case BOLD:
- style |= Font.BOLD;
- break;
- case ITALIC:
- style |= Font.ITALIC;
- break;
- default:
- throw new IllegalArgumentException("unknown flag: " + flag);
- }
- }
- 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 };
- else if (i_bold)
- return new Flag[] { BOLD };
- else if (i_italic)
- return new Flag[] { ITALIC };
- return new Flag[0];
- }
- }
-
- /**
- * 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);
-
- /**
- * Disposes all resources associated with this font.
- */
- public void dispose();
-}
Deleted: 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/IDraw3DText.java 2010-08-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/IDraw3DText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,33 +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;
-
-/**
- * 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();
-}
Deleted: 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-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglAWTGlyphCallback.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,168 +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 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][];
-
- private int m_index;
-
- private int m_numFans = 0;
-
- private int m_numStrips = 0;
-
- private int m_numSets = 0;
-
- private float[][] m_strips = new float[3][];
-
- private float[][] m_sets = new float[3][];
-
- private int m_type;
-
- private float[] m_vertices = new float[16];
-
- /**
- * {@inheritDoc}
- *
- * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#begin(int)
- */
- @Override
- public void begin(int i_type) {
- m_type = i_type;
- m_index = 0;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#combine(double[],
- * java.lang.Object[], float[], java.lang.Object[])
- */
- @Override
- public void combine(double[] i_coords, Object[] i_data, float[] i_weight,
- Object[] i_outData) {
- i_outData[0] = new float[] { (float) i_coords[0], (float) i_coords[1] };
- }
-
- /**
- * Creates an instance of {@link VectorChar} that represents the current
- * character data.
- *
- * @return the {@link VectorChar} instance that represents the current
- * character data
- */
- public VectorChar createVectorChar() {
- VectorChar result = new VectorChar();
- 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()
- */
- @Override
- public void end() {
- switch (m_type) {
- case GL_TRIANGLE_FAN:
- if (m_numFans == m_fans.length)
- m_fans = resize(m_fans);
- float[] fan = new float[m_index];
- System.arraycopy(m_vertices, 0, fan, 0, fan.length);
- m_fans[m_numFans++] = fan;
- break;
- case GL_TRIANGLE_STRIP:
- if (m_numStrips == m_strips.length)
- m_strips = resize(m_strips);
- float[] strip = new float[m_index];
- System.arraycopy(m_vertices, 0, strip, 0, strip.length);
- m_strips[m_numStrips++] = strip;
- break;
- case GL_TRIANGLES:
- 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_sets[m_numSets++] = tris;
- break;
- default:
- throw new IllegalStateException(
- "unknown tesselation primitive type: " + m_type);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#error(int)
- */
- @Override
- public void error(int i_errnum) {
- throw new RuntimeException("caught error during polygon tesselation: "
- + i_errnum);
- }
-
- /**
- * Resets the internal state of this callback object.
- */
- public void reset() {
- m_numFans = 0;
- m_numStrips = 0;
- m_numSets = 0;
- }
-
- private float[][] resize(float[][] i_array) {
- float[][] resized = new float[2 * i_array.length][];
- System.arraycopy(i_array, 0, resized, 0, i_array.length);
- return resized;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#vertex(java.lang.Object)
- */
- @Override
- public void vertex(Object i_vertexData) {
- if (m_index == m_vertices.length) {
- float[] temp = m_vertices;
- m_vertices = new float[temp.length * 2];
- System.arraycopy(temp, 0, m_vertices, 0, temp.length);
- }
-
- float[] vertex = (float[]) i_vertexData;
- m_vertices[m_index++] = vertex[0];
- m_vertices[m_index++] = vertex[1];
- }
-}
\ No newline at end of file
Deleted: 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-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,46 +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.image.BufferedImage;
-
-/**
- * A font that renders text using textures created by rendering AWT font onto an
- * image.
- *
- * @author Kristian Duske
- * @version $Revision$
- * @since 17.08.2010
- */
-public class LwjglTextureFont extends AwtBasedTextureFont {
-
- /**
- * 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);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.AwtBasedTextureFont#doCreateText(java.awt.image.BufferedImage)
- */
- @Override
- protected IDraw3DText doCreateText(BufferedImage i_image) {
- return new LwjglTextureText(i_image);
- }
-
-}
Deleted: 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/LwjglTextureText.java 2010-08-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglTextureText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,156 +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.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();
- }
-
- m_image = null;
- }
-
- /**
- * {@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();
- }
-}
Deleted: 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-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,200 +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.Rectangle;
-import java.awt.Shape;
-import java.awt.font.FontRenderContext;
-import java.awt.font.GlyphVector;
-import java.awt.font.LineMetrics;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.PathIterator;
-
-import org.lwjgl.util.glu.GLU;
-import org.lwjgl.util.glu.GLUtessellator;
-
-/**
- * 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 {
-
- private LwjglAWTGlyphCallback m_callback;
-
- /**
- * Buffer for a single vertex during character tesselation.
- */
- private double[] m_cBuf = new double[3];
-
- private boolean m_disposed = false;
-
- private float m_precision;
-
- private GLUtessellator m_tesselator;
-
- /**
- * Vertex buffer for GLU tesselator.
- */
- 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);
-
- if (i_precision < 0 || i_precision > 1)
- throw new IllegalArgumentException(
- "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,
- AffineTransform i_at, double i_flatness) {
- Shape outline = i_glyphs.getGlyphOutline(i_index);
- PathIterator path = outline.getPathIterator(i_at, i_flatness);
-
- if (!path.isDone()) {
- if (path.getWindingRule() == PathIterator.WIND_EVEN_ODD)
- m_tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE,
- GLU.GLU_TESS_WINDING_ODD);
- else if (path.getWindingRule() == PathIterator.WIND_NON_ZERO)
- m_tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE,
- GLU.GLU_TESS_WINDING_NONZERO);
-
- int vi = 0;
- m_tesselator.gluTessBeginPolygon(null);
- while (!path.isDone()) {
- int segmentType = path.currentSegment(m_cBuf);
-
- switch (segmentType) {
- case PathIterator.SEG_MOVETO:
- m_tesselator.gluTessBeginContour();
-
- if (vi == m_vBuf.length)
- m_vBuf = resizeVertexBuffer(m_vBuf);
- m_vBuf[vi][0] = (float) m_cBuf[0];
- m_vBuf[vi][1] = (float) m_cBuf[1];
- m_tesselator.gluTessVertex(m_cBuf, 0, m_vBuf[vi++]);
- break;
- case PathIterator.SEG_CLOSE:
- m_tesselator.gluTessEndContour();
- break;
- case PathIterator.SEG_LINETO:
- if (vi == m_vBuf.length)
- m_vBuf = resizeVertexBuffer(m_vBuf);
- m_vBuf[vi][0] = (float) m_cBuf[0];
- m_vBuf[vi][1] = (float) m_cBuf[1];
- m_tesselator.gluTessVertex(m_cBuf, 0, m_vBuf[vi++]);
- break;
- }
- path.next();
- }
- m_tesselator.gluTessEndPolygon();
- }
- VectorChar vectorChar = m_callback.createVectorChar();
-
- m_callback.reset();
- return vectorChar;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.IDraw3DFont#dispose()
- */
- public void dispose() {
- if (m_disposed)
- throw new IllegalStateException(this + " is disposed");
-
- m_callback = null;
- m_tesselator.gluDeleteTess();
- m_tesselator = null;
-
- m_cBuf = null;
- m_vBuf = null;
-
- m_disposed = true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.font.AwtBasedFont#doCreateText(String,
- * FontRenderContext)
- */
- @Override
- protected IDraw3DText doCreateText(String i_string,
- FontRenderContext i_context) {
- GlyphVector glyphs =
- getAwtFont().createGlyphVector(i_context, i_string);
- LineMetrics lineMetrics =
- getAwtFont().getLineMetrics(i_string, i_context);
- Rectangle bounds = glyphs.getPixelBounds(i_context, 0, 0);
-
- AffineTransform at = new AffineTransform();
- at.translate(0, bounds.height - lineMetrics.getDescent() - 0.5f);
-
- 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 LwjglVectorText(stringChars);
- }
-
- private float[][] resizeVertexBuffer(float[][] i_v) {
- float[][] r = new float[2 * i_v.length][];
- System.arraycopy(i_v, 0, r, 0, i_v.length);
- for (int i = i_v.length; i < r.length; i++)
- r[i] = new float[2];
- return r;
- }
-}
Deleted: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java 2010-08-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,171 +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;
-
-/**
- * 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);
- }
-
- 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);
- i = i_chars[j].compileStrips(buf, i, m_stripIdx, m_stripCnt);
- i = i_chars[j].compileSets(buf, i, m_triIdx, m_triCnt);
- }
-
- // 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/VectorChar.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/VectorChar.java 2010-08-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/VectorChar.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -1,207 +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.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_fans;
-
- private int m_numVertices = 0;
-
- private float[][] m_strips;
-
- private float[][] m_sets;
-
- /**
- * 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
- * @return the new index into the vertex buffer
- */
- public int compileFans(FloatBuffer i_vertices, int i_index,
- IntBuffer i_indices, IntBuffer i_counts) {
- if (m_fans == null || m_fans.length == 0)
- return i_index;
-
- int index = i_index;
- for (int i = 0; i < m_fans.length; i++) {
- int count = m_fans[i].length / 2;
- for (int j = 0; j < count; j++) {
- i_vertices.put(m_fans[i][2 * j]);
- i_vertices.put(m_fans[i][2 * j + 1]);
- }
- i_indices.put(index);
- i_counts.put(count);
- index += count;
- }
- return 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
- * @return the new index into the vertex buffer
- */
- public int compileStrips(FloatBuffer i_vertices, int i_index,
- IntBuffer i_indices, IntBuffer i_counts) {
- if (m_strips == null || m_strips.length == 0)
- return i_index;
-
- int index = i_index;
- for (int i = 0; i < m_strips.length; i++) {
- int count = m_strips[i].length / 2;
- for (int j = 0; j < count; j++) {
- i_vertices.put(m_strips[i][2 * j]);
- i_vertices.put(m_strips[i][2 * j + 1]);
- }
- i_indices.put(index);
- i_counts.put(count);
- index += count;
- }
- return 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
- * @return the new index into the vertex buffer
- */
- public int compileSets(FloatBuffer i_vertices, int i_index,
- IntBuffer i_indices, IntBuffer i_counts) {
- if (m_sets == null || m_sets.length == 0)
- return i_index;
-
- int index = i_index;
- for (int i = 0; i < m_sets.length; i++) {
- int count = m_sets[i].length / 2;
- for (int j = 0; j < count; j++) {
- i_vertices.put(m_sets[i][2 * j]);
- i_vertices.put(m_sets[i][2 * j + 1]);
- }
- i_indices.put(index);
- i_counts.put(count);
- index += count;
- }
- return index;
- }
-
- /**
- * 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;
- }
-
- /**
- * 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++) {
- m_fans[i] = i_data[i];
- m_numVertices += m_fans[i].length / 2;
- }
- }
-
- /**
- * 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_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++) {
- m_strips[i] = i_data[i];
- m_numVertices += m_strips[i].length / 2;
- }
- }
-}
\ No newline at end of file
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglGlyphCallback.java (from rev 518, 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/lwjgl/LwjglGlyphCallback.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglGlyphCallback.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+import static org.lwjgl.opengl.GL11.*;
+
+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 LwjglGlyphCallback extends GLUtessellatorCallbackAdapter {
+
+ private float[][] m_fans = new float[3][];
+
+ private int m_index;
+
+ private int m_numFans = 0;
+
+ private int m_numStrips = 0;
+
+ private int m_numSets = 0;
+
+ private float[][] m_strips = new float[3][];
+
+ private float[][] m_sets = new float[3][];
+
+ private int m_type;
+
+ private float[] m_vertices = new float[16];
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#begin(int)
+ */
+ @Override
+ public void begin(int i_type) {
+ m_type = i_type;
+ m_index = 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#combine(double[],
+ * java.lang.Object[], float[], java.lang.Object[])
+ */
+ @Override
+ public void combine(double[] i_coords, Object[] i_data, float[] i_weight,
+ Object[] i_outData) {
+ i_outData[0] = new float[] { (float) i_coords[0], (float) i_coords[1] };
+ }
+
+ /**
+ * Creates an instance of {@link VectorChar} that represents the current
+ * character data.
+ *
+ * @return the {@link VectorChar} instance that represents the current
+ * character data
+ */
+ public VectorChar createVectorChar() {
+ VectorChar result = new VectorChar();
+ 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()
+ */
+ @Override
+ public void end() {
+ switch (m_type) {
+ case GL_TRIANGLE_FAN:
+ if (m_numFans == m_fans.length)
+ m_fans = resize(m_fans);
+ float[] fan = new float[m_index];
+ System.arraycopy(m_vertices, 0, fan, 0, fan.length);
+ m_fans[m_numFans++] = fan;
+ break;
+ case GL_TRIANGLE_STRIP:
+ if (m_numStrips == m_strips.length)
+ m_strips = resize(m_strips);
+ float[] strip = new float[m_index];
+ System.arraycopy(m_vertices, 0, strip, 0, strip.length);
+ m_strips[m_numStrips++] = strip;
+ break;
+ case GL_TRIANGLES:
+ 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_sets[m_numSets++] = tris;
+ break;
+ default:
+ throw new IllegalStateException(
+ "unknown tesselation primitive type: " + m_type);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#error(int)
+ */
+ @Override
+ public void error(int i_errnum) {
+ throw new RuntimeException("caught error during polygon tesselation: "
+ + i_errnum);
+ }
+
+ /**
+ * Resets the internal state of this callback object.
+ */
+ public void reset() {
+ m_numFans = 0;
+ m_numStrips = 0;
+ m_numSets = 0;
+ }
+
+ private float[][] resize(float[][] i_array) {
+ float[][] resized = new float[2 * i_array.length][];
+ System.arraycopy(i_array, 0, resized, 0, i_array.length);
+ return resized;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.lwjgl.util.glu.GLUtessellatorCallbackAdapter#vertex(java.lang.Object)
+ */
+ @Override
+ public void vertex(Object i_vertexData) {
+ if (m_index == m_vertices.length) {
+ float[] temp = m_vertices;
+ m_vertices = new float[temp.length * 2];
+ System.arraycopy(temp, 0, m_vertices, 0, temp.length);
+ }
+
+ float[] vertex = (float[]) i_vertexData;
+ m_vertices[m_index++] = vertex[0];
+ m_vertices[m_index++] = vertex[1];
+ }
+}
\ No newline at end of file
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglMultiFontManager.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglMultiFontManager.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglMultiFontManager.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -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.lwjgl;
+
+import org.eclipse.draw3d.font.multi.MultiFontManager;
+import org.eclipse.draw3d.font.simple.IDraw3DFontManager;
+
+/**
+ * Manages LWJGL multi fonts.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public class LwjglMultiFontManager extends MultiFontManager {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.MultiFontManager#createTextureFontManager()
+ */
+ @Override
+ protected IDraw3DFontManager createTextureFontManager() {
+ return new LwjglTextureFontManager();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.MultiFontManager#createVectorFontManager()
+ */
+ @Override
+ protected IDraw3DFontManager createVectorFontManager() {
+ return new LwjglVectorFontManager();
+ }
+
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureFont.java (from rev 517, 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/lwjgl/LwjglTextureFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+import java.awt.image.BufferedImage;
+
+import org.eclipse.draw3d.font.simple.AwtBasedTextureFont;
+import org.eclipse.draw3d.font.simple.IDraw3DText;
+
+/**
+ * A font that renders text using textures created by rendering AWT font onto an
+ * image.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 17.08.2010
+ */
+public class LwjglTextureFont extends AwtBasedTextureFont {
+
+ /**
+ * 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.AwtBasedTextureFont#doCreateText(java.awt.image.BufferedImage)
+ */
+ @Override
+ protected IDraw3DText doCreateText(BufferedImage i_image) {
+ return new LwjglTextureText(i_image);
+ }
+
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureFontManager.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureFontManager.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureFontManager.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+import java.util.Arrays;
+
+import org.eclipse.draw3d.font.simple.FontManagerBase;
+import org.eclipse.draw3d.font.simple.IDraw3DFont;
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * Manages LWJGL texture fonts.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public class LwjglTextureFontManager extends FontManagerBase {
+
+ private static class Key {
+ private String m_name;
+
+ private int m_size;
+
+ private Flag[] m_flags;
+
+ private int m_hashCode;
+
+ public Key(String i_name, int i_size, Flag... i_flags) {
+ m_name = i_name.trim().toLowerCase();
+ m_size = i_size;
+ m_flags = i_flags;
+
+ m_hashCode = 17;
+ m_hashCode = 37 * m_hashCode + m_name.hashCode();
+ m_hashCode = 37 * m_hashCode + m_size;
+ m_hashCode = 37 * m_hashCode + Arrays.hashCode(m_flags);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return m_hashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object i_obj) {
+ if (i_obj == null)
+ return false;
+ if (!(i_obj instanceof Key))
+ return false;
+
+ Key key = (Key) i_obj;
+ if (!m_name.equals(key.m_name))
+ return false;
+ if (m_size != key.m_size)
+ return false;
+ if (!Arrays.equals(m_flags, key.m_flags))
+ return false;
+
+ return true;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.FontManagerBase#createFont(java.lang.String,
+ * int, float, org.eclipse.draw3d.font.simple.IDraw3DFont.Flag[])
+ */
+ @Override
+ protected IDraw3DFont createFont(String i_name, int i_size,
+ float i_precision, Flag... i_flags) {
+ return new LwjglTextureFont(i_name, i_size, i_flags);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.FontManagerBase#getKey(java.lang.String,
+ * int, float, org.eclipse.draw3d.font.simple.IDraw3DFont.Flag[])
+ */
+ @Override
+ protected Object getKey(String i_name, int i_size, float i_precision,
+ Flag... i_flags) {
+ return new Key(i_name, i_size, i_flags);
+ }
+
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureText.java (from rev 517, 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/lwjgl/LwjglTextureText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglTextureText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+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.font.simple.IDraw3DText;
+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.simple.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();
+ }
+
+ m_image = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.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();
+ }
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorFont.java (from rev 518, 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/lwjgl/LwjglVectorFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+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.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+
+import org.eclipse.draw3d.font.simple.AwtBasedFont;
+import org.eclipse.draw3d.font.simple.IDraw3DText;
+import org.lwjgl.util.glu.GLU;
+import org.lwjgl.util.glu.GLUtessellator;
+
+/**
+ * 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 {
+
+ private LwjglGlyphCallback m_callback;
+
+ /**
+ * Buffer for a single vertex during character tesselation.
+ */
+ private double[] m_cBuf = new double[3];
+
+ private boolean m_disposed = false;
+
+ private float m_precision;
+
+ private GLUtessellator m_tesselator;
+
+ /**
+ * Vertex buffer for GLU tesselator.
+ */
+ 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.simple.IDraw3DFont.Flag...)
+ */
+ public LwjglVectorFont(String i_name, int i_size, float i_precision,
+ Flag... i_flags) {
+ super(i_name, i_size, i_flags);
+
+ if (i_precision < 0 || i_precision > 1)
+ throw new IllegalArgumentException(
+ "precision must be between 0 and 1, inclusive");
+
+ m_precision = i_precision;
+
+ m_tesselator = GLU.gluNewTess();
+ m_callback = new LwjglGlyphCallback();
+
+ // 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,
+ AffineTransform i_at, double i_flatness) {
+ Shape outline = i_glyphs.getGlyphOutline(i_index);
+ PathIterator path = outline.getPathIterator(i_at, i_flatness);
+
+ if (!path.isDone()) {
+ if (path.getWindingRule() == PathIterator.WIND_EVEN_ODD)
+ m_tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE,
+ GLU.GLU_TESS_WINDING_ODD);
+ else if (path.getWindingRule() == PathIterator.WIND_NON_ZERO)
+ m_tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE,
+ GLU.GLU_TESS_WINDING_NONZERO);
+
+ int vi = 0;
+ m_tesselator.gluTessBeginPolygon(null);
+ while (!path.isDone()) {
+ int segmentType = path.currentSegment(m_cBuf);
+
+ switch (segmentType) {
+ case PathIterator.SEG_MOVETO:
+ m_tesselator.gluTessBeginContour();
+
+ if (vi == m_vBuf.length)
+ m_vBuf = resizeVertexBuffer(m_vBuf);
+ m_vBuf[vi][0] = (float) m_cBuf[0];
+ m_vBuf[vi][1] = (float) m_cBuf[1];
+ m_tesselator.gluTessVertex(m_cBuf, 0, m_vBuf[vi++]);
+ break;
+ case PathIterator.SEG_CLOSE:
+ m_tesselator.gluTessEndContour();
+ break;
+ case PathIterator.SEG_LINETO:
+ if (vi == m_vBuf.length)
+ m_vBuf = resizeVertexBuffer(m_vBuf);
+ m_vBuf[vi][0] = (float) m_cBuf[0];
+ m_vBuf[vi][1] = (float) m_cBuf[1];
+ m_tesselator.gluTessVertex(m_cBuf, 0, m_vBuf[vi++]);
+ break;
+ }
+ path.next();
+ }
+ m_tesselator.gluTessEndPolygon();
+ }
+ VectorChar vectorChar = m_callback.createVectorChar();
+
+ m_callback.reset();
+ return vectorChar;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.IDraw3DFont#dispose()
+ */
+ public void dispose() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ m_callback = null;
+ m_tesselator.gluDeleteTess();
+ m_tesselator = null;
+
+ m_cBuf = null;
+ m_vBuf = null;
+
+ m_disposed = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.AwtBasedFont#doCreateText(String,
+ * FontRenderContext)
+ */
+ @Override
+ protected IDraw3DText doCreateText(String i_string,
+ FontRenderContext i_context) {
+ GlyphVector glyphs =
+ getAwtFont().createGlyphVector(i_context, i_string);
+ LineMetrics lineMetrics =
+ getAwtFont().getLineMetrics(i_string, i_context);
+ Rectangle bounds = glyphs.getPixelBounds(i_context, 0, 0);
+
+ AffineTransform at = new AffineTransform();
+ at.translate(0, bounds.height - lineMetrics.getDescent() - 0.5f);
+
+ 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 LwjglVectorText(stringChars);
+ }
+
+ private float[][] resizeVertexBuffer(float[][] i_v) {
+ float[][] r = new float[2 * i_v.length][];
+ System.arraycopy(i_v, 0, r, 0, i_v.length);
+ for (int i = i_v.length; i < r.length; i++)
+ r[i] = new float[2];
+ return r;
+ }
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorFontManager.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorFontManager.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorFontManager.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+import java.util.Arrays;
+
+import org.eclipse.draw3d.font.simple.FontManagerBase;
+import org.eclipse.draw3d.font.simple.IDraw3DFont;
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * Manages LWJGL vector fonts.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public class LwjglVectorFontManager extends FontManagerBase {
+
+ private static class Key {
+ private Flag[] m_flags;
+
+ private int m_hashCode;
+
+ private String m_name;
+
+ private float m_precision;
+
+ private int m_size;
+
+ public Key(String i_name, int i_size, float i_precision,
+ Flag... i_flags) {
+ m_name = i_name.trim().toLowerCase();
+ m_size = i_size;
+ m_precision = i_precision;
+ m_flags = i_flags;
+
+ m_hashCode = 17;
+ m_hashCode = 37 * m_hashCode + m_name.hashCode();
+ m_hashCode = 37 * m_hashCode + m_size;
+ m_hashCode = 37 * m_hashCode + new Float(m_precision).hashCode();
+ m_hashCode = 37 * m_hashCode + Arrays.hashCode(m_flags);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object i_obj) {
+ if (i_obj == null)
+ return false;
+ if (!(i_obj instanceof Key))
+ return false;
+
+ Key key = (Key) i_obj;
+ if (!m_name.equals(key.m_name))
+ return false;
+ if (m_size != key.m_size)
+ return false;
+ if (m_precision != key.m_precision)
+ return false;
+ if (!Arrays.equals(m_flags, key.m_flags))
+ return false;
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return m_hashCode;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.FontManagerBase#createFont(java.lang.String,
+ * int, float, org.eclipse.draw3d.font.simple.IDraw3DFont.Flag[])
+ */
+ @Override
+ protected IDraw3DFont createFont(String i_name, int i_size,
+ float i_precision, Flag... i_flags) {
+ return new LwjglVectorFont(i_name, i_size, i_precision, i_flags);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.FontManagerBase#getKey(java.lang.String,
+ * int, float, org.eclipse.draw3d.font.simple.IDraw3DFont.Flag[])
+ */
+ @Override
+ protected Object getKey(String i_name, int i_size, float i_precision,
+ Flag... i_flags) {
+ return new Key(i_name, i_size, i_precision, i_flags);
+ }
+
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorText.java (from rev 518, branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/LwjglVectorText.java)
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/LwjglVectorText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+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.font.simple.IDraw3DText;
+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);
+ }
+
+ 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);
+ i = i_chars[j].compileStrips(buf, i, m_stripIdx, m_stripCnt);
+ i = i_chars[j].compileSets(buf, i, m_triIdx, m_triCnt);
+ }
+
+ // 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.simple.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.simple.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);
+ }
+ }
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/VectorChar.java (from rev 518, 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/lwjgl/VectorChar.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/lwjgl/VectorChar.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * 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.lwjgl;
+
+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_fans;
+
+ private int m_numVertices = 0;
+
+ private float[][] m_strips;
+
+ private float[][] m_sets;
+
+ /**
+ * 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
+ * @return the new index into the vertex buffer
+ */
+ public int compileFans(FloatBuffer i_vertices, int i_index,
+ IntBuffer i_indices, IntBuffer i_counts) {
+ if (m_fans == null || m_fans.length == 0)
+ return i_index;
+
+ int index = i_index;
+ for (int i = 0; i < m_fans.length; i++) {
+ int count = m_fans[i].length / 2;
+ for (int j = 0; j < count; j++) {
+ i_vertices.put(m_fans[i][2 * j]);
+ i_vertices.put(m_fans[i][2 * j + 1]);
+ }
+ i_indices.put(index);
+ i_counts.put(count);
+ index += count;
+ }
+ return 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
+ * @return the new index into the vertex buffer
+ */
+ public int compileStrips(FloatBuffer i_vertices, int i_index,
+ IntBuffer i_indices, IntBuffer i_counts) {
+ if (m_strips == null || m_strips.length == 0)
+ return i_index;
+
+ int index = i_index;
+ for (int i = 0; i < m_strips.length; i++) {
+ int count = m_strips[i].length / 2;
+ for (int j = 0; j < count; j++) {
+ i_vertices.put(m_strips[i][2 * j]);
+ i_vertices.put(m_strips[i][2 * j + 1]);
+ }
+ i_indices.put(index);
+ i_counts.put(count);
+ index += count;
+ }
+ return 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
+ * @return the new index into the vertex buffer
+ */
+ public int compileSets(FloatBuffer i_vertices, int i_index,
+ IntBuffer i_indices, IntBuffer i_counts) {
+ if (m_sets == null || m_sets.length == 0)
+ return i_index;
+
+ int index = i_index;
+ for (int i = 0; i < m_sets.length; i++) {
+ int count = m_sets[i].length / 2;
+ for (int j = 0; j < count; j++) {
+ i_vertices.put(m_sets[i][2 * j]);
+ i_vertices.put(m_sets[i][2 * j + 1]);
+ }
+ i_indices.put(index);
+ i_counts.put(count);
+ index += count;
+ }
+ return index;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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++) {
+ m_fans[i] = i_data[i];
+ m_numVertices += m_fans[i].length / 2;
+ }
+ }
+
+ /**
+ * 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_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++) {
+ m_strips[i] = i_data[i];
+ m_numVertices += m_strips[i].length / 2;
+ }
+ }
+}
\ No newline at end of file
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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.multi;
+
+import org.eclipse.draw3d.font.simple.IDraw3DText;
+
+/**
+ * A font that creates {@link IDraw3DMultiText} instances instead of
+ * {@link IDraw3DText} instances.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public interface IDraw3DMultiFont {
+
+ /**
+ * Creates an instance of {@link IDraw3DMultiText} for the given string.
+ *
+ * @param i_string the string to render
+ * @return an instance of {@link IDraw3DMultiText} that renders the given
+ * string
+ * @throws IllegalStateException if this font is disposed
+ */
+ public IDraw3DMultiText createText(String i_string);
+
+ /**
+ * Disposes all resources associated with this font.
+ */
+ public void dispose();
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFontManager.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFontManager.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiFontManager.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.multi;
+
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * Manages {@link IDraw3DMultiFont} instances.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public interface IDraw3DMultiFontManager {
+ /**
+ * Disposes all resources associated with this font manager.
+ */
+ public void dispose();
+
+ /**
+ * Returns an {@link IDraw3DMultiFont} instance with the given parameters.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_flags the font flags
+ * @return the {@link IDraw3DMultiFont} instance
+ * @throws NullPointerException if the given name or the given flag array is
+ * <code>null</code>
+ * @throws IllegalArgumentException if the given font size is not positive
+ * @throws IllegalStateException if this font manager is disposed
+ */
+ public IDraw3DMultiFont getFont(String i_name, int i_size, Flag... i_flags);
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiText.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/IDraw3DMultiText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.multi;
+
+/**
+ * Renderable text that uses a level of detail value to adapt its complexity.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public interface IDraw3DMultiText {
+ /**
+ * Disposes all resources associated with this text.
+ */
+ public void dispose();
+
+ /**
+ * Renders this text and adapts the visual complexity to the given LOD
+ * value. A low value indicates that little detail should be used while a
+ * high value indicates that lots of detail should be used.
+ *
+ * @param i_lod the LOD value, which must be between 0 and 1 inclusive
+ * @throws IllegalArgumentException if the given LOD value is not between 0
+ * and 1 inclusive
+ * @throws IllegalStateException if this text is disposed
+ */
+ public void render(float i_lod);
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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.multi;
+
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * An implementation of {@link IDraw3DMultiFont} that creates instances of
+ * {@link MultiText}.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public class MultiFont implements IDraw3DMultiFont {
+
+ private boolean m_disposed = false;
+
+ private Flag[] m_flags;
+
+ private MultiFontManager m_fontManager;
+
+ private String m_name;
+
+ private int m_size;
+
+ /**
+ * Creates a new instance with the given parameters.
+ *
+ * @param i_fontManager the multi font manager to use
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_flags the font flags
+ * @throws NullPointerException if the given font manager, the given name or
+ * the given flag array is <code>null</code>
+ * @throws IllegalArgumentException if the given size is not positive
+ */
+ public MultiFont(MultiFontManager i_fontManager, String i_name, int i_size,
+ Flag[] i_flags) {
+ if (i_fontManager == null)
+ throw new NullPointerException("i_fontManager must not be null");
+ if (i_name == null)
+ throw new NullPointerException("i_name must not be null");
+ if (i_flags == null)
+ throw new NullPointerException("i_flags must not be null");
+ if (i_size <= 0)
+ throw new IllegalArgumentException("font size must be positive");
+
+ m_fontManager = i_fontManager;
+ m_name = i_name;
+ m_size = i_size;
+ m_flags = i_flags;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.IDraw3DMultiFont#createText(java.lang.String)
+ */
+ public IDraw3DMultiText createText(String i_string) {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ return new MultiText(i_string, m_fontManager, m_name, m_size, m_flags);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.IDraw3DMultiFont#dispose()
+ */
+ public void dispose() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ m_fontManager = null;
+ m_name = null;
+ m_flags = null;
+
+ m_disposed = true;
+ }
+
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFontManager.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFontManager.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiFontManager.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * 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.multi;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.draw3d.font.simple.IDraw3DFont;
+import org.eclipse.draw3d.font.simple.IDraw3DFontManager;
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * An implementation of {@link IDraw3DMultiFontManager} that manages instances
+ * of {@link MultiFont}.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public abstract class MultiFontManager implements IDraw3DMultiFontManager {
+
+ private static class Key {
+ private Flag[] m_flags;
+
+ private int m_hashCode;
+
+ private String m_name;
+
+ private int m_size;
+
+ public Key(String i_name, int i_size, Flag... i_flags) {
+ m_name = i_name.trim().toLowerCase();
+ m_size = i_size;
+ m_flags = i_flags;
+
+ m_hashCode = 17;
+ m_hashCode = 37 * m_hashCode + m_name.hashCode();
+ m_hashCode = 37 * m_hashCode + m_size;
+ m_hashCode = 37 * m_hashCode + Arrays.hashCode(m_flags);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object i_obj) {
+ if (i_obj == null)
+ return false;
+ if (!(i_obj instanceof Key))
+ return false;
+
+ Key key = (Key) i_obj;
+ if (!m_name.equals(key.m_name))
+ return false;
+ if (m_size != key.m_size)
+ return false;
+ if (!Arrays.equals(m_flags, key.m_flags))
+ return false;
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return m_hashCode;
+ }
+ }
+
+ private boolean m_disposed = false;
+
+ private Map<Object, IDraw3DMultiFont> m_fonts =
+ new HashMap<Object, IDraw3DMultiFont>();
+
+ private IDraw3DFontManager m_textureFontManager =
+ createTextureFontManager();
+
+ private IDraw3DFontManager m_vectorFontManager = createVectorFontManager();
+
+ /**
+ * Creates a new font manager for texture fonts.
+ *
+ * @return the newly created font manager
+ */
+ protected abstract IDraw3DFontManager createTextureFontManager();
+
+ /**
+ * Creates a new font manager for vertex fonts.
+ *
+ * @return the newly created font manager
+ */
+ protected abstract IDraw3DFontManager createVectorFontManager();
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.IDraw3DMultiFontManager#dispose()
+ */
+ public void dispose() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ m_disposed = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.IDraw3DMultiFontManager#getFont(java.lang.String,
+ * int, org.eclipse.draw3d.font.simple.IDraw3DFont.Flag[])
+ */
+ public IDraw3DMultiFont getFont(String i_name, int i_size, Flag... i_flags) {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+ if (i_name == null)
+ throw new NullPointerException("i_name must not be null");
+ if (i_flags == null)
+ throw new NullPointerException("i_flags must not be null");
+ if (i_size <= 0)
+ throw new IllegalArgumentException("font size must be positive");
+
+ Key key = new Key(i_name, i_size, i_flags);
+ IDraw3DMultiFont font = m_fonts.get(key);
+ if (font == null) {
+ font = new MultiFont(this, i_name, i_size, i_flags);
+ m_fonts.put(key, font);
+ }
+
+ return font;
+ }
+
+ /**
+ * Returns a texture font with the given parameters.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_flags the font flags
+ * @return the texture font
+ */
+ IDraw3DFont getTextureFont(String i_name, int i_size, Flag... i_flags) {
+ return m_textureFontManager.getFont(i_name, i_size, 1, i_flags);
+ }
+
+ /**
+ * Returns a vector font with the given parameters.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_precision the vector data precision value
+ * @param i_flags the font flags
+ * @return the vector font
+ */
+ IDraw3DFont getVectorFont(String i_name, int i_size, float i_precision,
+ Flag... i_flags) {
+ return m_vectorFontManager.getFont(i_name, i_size, i_precision, i_flags);
+ }
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiText.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/multi/MultiText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * 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.multi;
+
+import java.util.logging.Logger;
+
+import org.eclipse.draw3d.font.simple.IDraw3DFont;
+import org.eclipse.draw3d.font.simple.IDraw3DText;
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * A renderable text that encapsulates several fonts for the different degrees
+ * of the LOD. The LOD value is quantized to steps of 0.1. If the result is less
+ * or equal to the {@link #TEXTURE_FONT_TH} threshold, a texture font is used,
+ * otherwise, a vector font is used. The precision parameter for the vector font
+ * is used by scaling the LOD value (which is between {@link #TEXTURE_FONT_TH}
+ * and 1) to 0 to 1 range.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public class MultiText implements IDraw3DMultiText {
+
+ private static final float TEXTURE_FONT_TH = 0.09f;
+
+ private IDraw3DText[] m_cache = new IDraw3DText[11];
+
+ private boolean m_disposed = false;
+
+ private Flag[] m_fontFlags;
+
+ private MultiFontManager m_fontManager;
+
+ private String m_fontName;
+
+ private int m_fontSize;
+
+ private String m_string;
+
+ /**
+ * Creates a new instance with the given parameters that renders the given
+ * string.f
+ *
+ * @param i_string the string to render
+ * @param i_fontManager the font manager
+ * @param i_fontName the font name
+ * @param i_fontSize the font size
+ * @param i_fontFlags the font flags
+ * @throws NullPointerException if the given string, font manager, font name
+ * or flag array is <code>null</code>
+ * @throws IllegalArgumentException if the given font size is not positive
+ */
+ public MultiText(String i_string, MultiFontManager i_fontManager,
+ String i_fontName, int i_fontSize, Flag... i_fontFlags) {
+ if (i_string == null)
+ throw new NullPointerException("i_string must not be null");
+ if (i_fontManager == null)
+ throw new NullPointerException("i_fontManager must not be null");
+ if (i_fontName == null)
+ throw new NullPointerException("i_fontName must not be null");
+ if (i_fontFlags == null)
+ throw new NullPointerException("i_fontFlags must not be null");
+ if (i_fontSize <= 0)
+ throw new IllegalArgumentException("font size must be positive");
+
+ m_string = i_string;
+ m_fontManager = i_fontManager;
+ m_fontName = i_fontName;
+ m_fontSize = i_fontSize;
+ m_fontFlags = i_fontFlags;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.IDraw3DMultiText#dispose()
+ */
+ public void dispose() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ for (IDraw3DText text : m_cache)
+ if (text != null)
+ text.dispose();
+
+ m_cache = null;
+ m_fontFlags = null;
+ m_fontName = null;
+ m_string = null;
+ m_fontManager = null;
+
+ m_disposed = true;
+ }
+
+ private int index(float i_scaledLod) {
+ return (int) i_scaledLod * 10;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.multi.IDraw3DMultiText#render(float)
+ */
+ public void render(float i_lod) {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ float sl = scaleLod(i_lod);
+ int i = index(sl);
+
+ IDraw3DText text = m_cache[i];
+ if (text == null) {
+ IDraw3DFont font = selectFont(sl);
+ text = font.createText(m_string);
+ m_cache[i] = text;
+ }
+
+ text.render();
+ }
+
+ private float scaleLod(float i_lod) {
+ return (float) Math.floor(i_lod * 10) / 10;
+ }
+
+ @SuppressWarnings("unused")
+ private static final Logger log =
+ Logger.getLogger(MultiText.class.getName());
+
+ private IDraw3DFont selectFont(float i_sl) {
+ if (i_sl <= TEXTURE_FONT_TH)
+ return m_fontManager.getTextureFont(m_fontName, m_fontSize,
+ m_fontFlags);
+
+ float p = 1 - (i_sl - TEXTURE_FONT_TH) / (1 - TEXTURE_FONT_TH);
+ return m_fontManager.getVectorFont(m_fontName, m_fontSize, p,
+ m_fontFlags);
+ }
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/AwtBasedFont.java (from rev 518, 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/simple/AwtBasedFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/AwtBasedFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.simple;
+
+import java.awt.Font;
+import java.awt.font.FontRenderContext;
+
+/**
+ * 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.simple.IDraw3DFont#createText(java.lang.String)
+ */
+ public IDraw3DText createText(String i_string) {
+ if (i_string == null || i_string.trim().length() == 0)
+ return EmptyText.INSTANCE;
+
+ FontRenderContext ctx = new FontRenderContext(null, true, true);
+ return doCreateText(i_string, ctx);
+ }
+
+ /**
+ * 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
+ * @param i_context the font rendering context
+ * @return the {@link IDraw3DText} instance
+ */
+ protected abstract IDraw3DText doCreateText(String i_string,
+ FontRenderContext i_context);
+
+ /**
+ * 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/simple/AwtBasedTextureFont.java (from rev 518, 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/simple/AwtBasedTextureFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/AwtBasedTextureFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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.simple;
+
+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.simple.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.simple.AwtBasedFont#doCreateText(String,
+ * FontRenderContext)
+ */
+ @Override
+ protected IDraw3DText doCreateText(String i_string,
+ FontRenderContext i_context) {
+ GlyphVector glyphs =
+ getAwtFont().createGlyphVector(i_context, i_string);
+ LineMetrics lineMetrics =
+ getAwtFont().getLineMetrics(i_string, i_context);
+ Rectangle bounds = glyphs.getPixelBounds(i_context, 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, bounds.height - lineMetrics.getDescent() - 0.5f);
+
+ for (int i = 0; i < glyphs.getNumGlyphs(); i++) {
+ Shape outline = glyphs.getGlyphOutline(i);
+ g.fill(outline);
+ }
+
+ return doCreateText(img);
+ }
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/EmptyText.java (from rev 517, 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/simple/EmptyText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/EmptyText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -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.simple;
+
+/**
+ * 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.simple.IDraw3DText#dispose()
+ */
+ public void dispose() {
+ // nothing to do
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.IDraw3DText#render()
+ */
+ public void render() {
+ // nothing to do
+ }
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/FontManagerBase.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/FontManagerBase.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/FontManagerBase.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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.simple;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * A base class for simple font managers.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public abstract class FontManagerBase implements IDraw3DFontManager {
+
+ private boolean m_disposed = false;
+
+ private Map<Object, IDraw3DFont> m_fonts =
+ new HashMap<Object, IDraw3DFont>();
+
+ /**
+ * Creates a new font with the given parameters.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_precision the precision
+ * @param i_flags the font flags
+ * @return the newly created font
+ */
+ protected abstract IDraw3DFont createFont(String i_name, int i_size,
+ float i_precision, Flag... i_flags);
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.IDraw3DFontManager#dispose()
+ */
+ public void dispose() {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ for (IDraw3DFont font : m_fonts.values())
+ font.dispose();
+
+ m_fonts = null;
+ m_disposed = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.font.simple.IDraw3DFontManager#getFont(java.lang.String,
+ * int, float, org.eclipse.draw3d.font.simple.IDraw3DFont.Flag[])
+ */
+ public IDraw3DFont getFont(String i_name, int i_size, float i_precision,
+ Flag... i_flags) {
+ if (m_disposed)
+ throw new IllegalStateException(this + " is disposed");
+
+ if (i_name == null)
+ throw new NullPointerException("i_name must not be null");
+ if (i_flags == null)
+ throw new NullPointerException("i_flags must not be null");
+ if (i_size <= 0)
+ throw new IllegalArgumentException(
+ "font size must be a positive integer");
+ if (i_precision < 0 || i_precision > 1)
+ throw new IllegalArgumentException(
+ "precision must be between 0 and 1");
+
+ Object key = getKey(i_name, i_size, i_precision, i_flags);
+ IDraw3DFont font = m_fonts.get(key);
+ if (font == null) {
+ font = createFont(i_name, i_size, i_precision, i_flags);
+ m_fonts.put(key, font);
+ }
+
+ return font;
+ }
+
+ /**
+ * Returns a key for a font with the given parameters.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_precision the precision value
+ * @param i_flags the font flags
+ * @return the font key
+ */
+ protected abstract Object getKey(String i_name, int i_size,
+ float i_precision, Flag... i_flags);
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DFont.java (from rev 517, 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/simple/IDraw3DFont.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DFont.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.simple;
+
+import java.awt.Font;
+
+/**
+ * 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 {
+ /**
+ * 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) {
+ switch (flag) {
+ case BOLD:
+ style |= Font.BOLD;
+ break;
+ case ITALIC:
+ style |= Font.ITALIC;
+ break;
+ default:
+ throw new IllegalArgumentException("unknown flag: " + flag);
+ }
+ }
+ 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 };
+ else if (i_bold)
+ return new Flag[] { BOLD };
+ else if (i_italic)
+ return new Flag[] { ITALIC };
+ return new Flag[0];
+ }
+ }
+
+ /**
+ * 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);
+
+ /**
+ * Disposes all resources associated with this font.
+ */
+ public void dispose();
+}
Added: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DFontManager.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DFontManager.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DFontManager.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.simple;
+
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
+
+/**
+ * Manages simple fonts.
+ *
+ * @author Kristian Duske
+ * @version $Revision$
+ * @since 18.08.2010
+ */
+public interface IDraw3DFontManager {
+ /**
+ * Disposes all resources associated with this font manager.
+ */
+ public void dispose();
+
+ /**
+ * Returns a font with the given parameters.
+ *
+ * @param i_name the font name
+ * @param i_size the font size
+ * @param i_precision the precision value
+ * @param i_flags the font flags
+ * @return the font
+ * @throws IllegalStateException if this font manager is disposed
+ */
+ public IDraw3DFont getFont(String i_name, int i_size, float i_precision,
+ Flag... i_flags);
+}
Copied: branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DText.java (from rev 517, 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/simple/IDraw3DText.java (rev 0)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/simple/IDraw3DText.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -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.simple;
+
+/**
+ * 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/viewer/Draw3DFontViewer.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/viewer/Draw3DFontViewer.java 2010-08-17 14:06:57 UTC (rev 518)
+++ branches/better_lod/org.eclipse.draw3d.font/src/org/eclipse/draw3d/font/viewer/Draw3DFontViewer.java 2010-08-18 11:53:03 UTC (rev 519)
@@ -5,11 +5,11 @@
import java.awt.GraphicsEnvironment;
-import org.eclipse.draw3d.font.IDraw3DFont;
-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;
+import org.eclipse.draw3d.font.lwjgl.LwjglMultiFontManager;
+import org.eclipse.draw3d.font.multi.IDraw3DMultiFont;
+import org.eclipse.draw3d.font.multi.IDraw3DMultiFontManager;
+import org.eclipse.draw3d.font.multi.IDraw3DMultiText;
+import org.eclipse.draw3d.font.simple.IDraw3DFont.Flag;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
@@ -66,7 +66,7 @@
private Button m_italic;
- private Scale m_precision;
+ private Scale m_lod;
private Label m_precLabel;
@@ -74,6 +74,8 @@
private Button m_typeTexture;
+ private IDraw3DMultiFontManager m_fontManager;
+
/**
* The constructor.
*/
@@ -108,6 +110,8 @@
* it.
*/
public void createPartControl(Composite i_parent) {
+ m_fontManager = new LwjglMultiFontManager();
+
Composite container = createContainer(i_parent);
createGLCanvas(container);
createFontSelector(container);
@@ -170,23 +174,14 @@
Flag[] flags =
Flag.getFlags(m_bold.getSelection(),
m_italic.getSelection());
- float p = m_precision.getSelection() / 100f;
- IDraw3DFont vectorFont =
- new LwjglVectorFont(name, size, p, flags);
- IDraw3DText vectorText =
- vectorFont.createText("The quick brown fox jumps over the lazy dog.");
- vectorText.render();
- vectorText.dispose();
- vectorFont.dispose();
+ float lod = m_lod.getSelection() / 100f;
- IDraw3DFont textureFont =
- new LwjglTextureFont(name, size, flags);
- IDraw3DText textureText =
- textureFont.createText("The quick brown fox jumps over the lazy dog.");
- // glTranslatef(0, 30, 0);
- textureText.render();
- textureText.dispose();
- textureFont.dispose();
+ IDraw3DMultiFont font =
+ m_fontManager.getFont(name, size, flags);
+ IDraw3DMultiText text =
+ font.createText("The quick brown fox jumps over the lazy dog.");
+ text.render(lod);
+ text.dispose();
}
m_canvas.swapBuffers();
@@ -263,15 +258,15 @@
}
});
- m_precision = new Scale(container, SWT.HORIZONTAL);
- m_precision.setMinimum(0);
- m_precision.setMaximum(100);
- m_precision.setIncrement(1);
- m_precision.setPageIncrement(10);
- m_precision.addSelectionListener(new SelectionListener() {
+ m_lod = new Scale(container, SWT.HORIZONTAL);
+ m_lod.setMinimum(0);
+ m_lod.setMaximum(100);
+ m_lod.setIncrement(1);
+ m_lod.setPageIncrement(10);
+ m_lod.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent i_e) {
m_precLabel.setText(String.format("%2.2f",
- m_precision.getSelection() / 100f));
+ m_lod.getSelection() / 100f));
m_canvas.redraw();
}