[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[gef3d-commits] r501 - in branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl: . font
|
- From: genie@xxxxxxxxxxx
- Date: Wed, 7 Jul 2010 12:38:31 -0400 (EDT)
- Delivered-to: gef3d-commits@eclipse.org
Author: kduske
Date: 2010-07-07 12:38:31 -0400 (Wed, 07 Jul 2010)
New Revision: 501
Modified:
branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/Graphics3DLwjgl.java
branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/TextRenderImage.java
branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFont.java
branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFontChar.java
branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglVectorFont.java
Log:
NEW - bug 318148: Problems with LOD of fonts
https://bugs.eclipse.org/bugs/show_bug.cgi?id=318148
Modified: branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/Graphics3DLwjgl.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/Graphics3DLwjgl.java 2010-06-29 16:15:29 UTC (rev 500)
+++ branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/Graphics3DLwjgl.java 2010-07-07 16:38:31 UTC (rev 501)
@@ -98,7 +98,7 @@
* @todo We have to find a better mechanism for ensuring 2D content to be
* placed on top of surface plane
*/
- private static final float OFFSET_2DCONTENT_SURFACE = -0.2f;
+ public static final float OFFSET_2DCONTENT_SURFACE = -0.2f;
private static class PolygonTesselator implements GLUtessellatorCallback {
Modified: branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/TextRenderImage.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/TextRenderImage.java 2010-06-29 16:15:29 UTC (rev 500)
+++ branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/TextRenderImage.java 2010-07-07 16:38:31 UTC (rev 501)
@@ -62,7 +62,7 @@
* If distance of text to camera is less this value, the text is rendered
* using vector fonts.
*/
- private static final float LOD_VF = 0.12f; // 1100f;
+ private static final float LOD_VF = 0.01f; // 1100f;
private static final float LOD_B = 0.1f;
@@ -72,7 +72,7 @@
private Vector3f m_absPos = new Vector3fImpl();
- private float[] m_color = new float[4];
+ private float[] m_c = new float[4];
private Vector3f m_normal = new Vector3fImpl(IVector3f.Z_AXIS_NEG);
@@ -95,7 +95,7 @@
TextRenderRule textRule = i_primitive.getRenderRule().asText();
ColorConverter.toFloatArray(textRule.getTextColor(),
- textRule.getAlpha(), m_color);
+ textRule.getAlpha(), m_c);
Dimension extent = i_primitive.getExtent();
// m_absPos.set(extent.width / 2f, extent.height / 2f, 0);
@@ -191,24 +191,34 @@
*/
private void renderLOD(float l) {
if (l <= LOD_VF) {
- GL11.glColor4f(m_color[0], m_color[1], m_color[2], m_color[3]);
+ // GL11.glColor4f(m_c[0], m_c[1], m_c[2], m_c[3]);
+ GL11.glColor4f(1, 0, 0, 1);
m_vectorFont.render(m_text);
} else if (l <= LOD_VF + LOD_B) {
float f = (l - LOD_VF) / LOD_B;
- GL11.glColor4f(m_color[0], m_color[1], m_color[2], (1 - f)
- * m_color[3]);
- m_vectorFont.render(m_text);
+ // GL11.glColor4f(m_c[0], m_c[1], m_c[2], f * m_c[3]);
+ GL11.glColor4f(0, 1, 0, 1); // f);
+ m_textureFont.renderString(m_text, 0, 0, false);
- GL11.glColor4f(m_color[0], m_color[1], m_color[2], f * m_color[3]);
+ GL11.glMatrixMode(GL11.GL_MODELVIEW);
+ GL11.glPushMatrix();
+ try {
+ GL11.glTranslatef(0, 0,
+ Graphics3DLwjgl.OFFSET_2DCONTENT_SURFACE);
+ // GL11.glColor4f(m_c[0], m_c[1], m_c[2], (1 - f) * m_c[3]);
+ GL11.glColor4f(1, 0, 0, 1); //1 - f);
+ m_vectorFont.render(m_text);
+ } finally {
+ GL11.glPopMatrix();
+ }
+ } else if (l <= LOD_TF - LOD_B) {
+ GL11.glColor4f(0, 1, 0, 1);
m_textureFont.renderString(m_text, 0, 0, false);
- } else if (l <= LOD_TF - LOD_B) {
- GL11.glColor4f(m_color[0], m_color[1], m_color[2], m_color[3]);
- m_vectorFont.render(m_text);
} else {
float f = (LOD_TF - l) / LOD_B;
- GL11.glColor4f(m_color[0], m_color[1], m_color[2], f * m_color[3]);
- m_vectorFont.render(m_text);
+ GL11.glColor4f(0, 1, 0, f);
+ m_textureFont.renderString(m_text, 0, 0, false);
}
}
}
Modified: branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFont.java 2010-06-29 16:15:29 UTC (rev 500)
+++ branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFont.java 2010-07-07 16:38:31 UTC (rev 501)
@@ -64,14 +64,14 @@
private final String m_description;
+ private DisplayListManager m_displayListManager;
+
private boolean m_disposed = false;
private final char m_endChar;
private FontMetrics m_fontMetrics;
- private DisplayListManager m_displayListManager;
-
/**
* The height of the character texture.
*/
@@ -79,7 +79,7 @@
private final char m_startChar;
- private int m_tabWidth;
+ private int m_tabAdvance;
private int m_textureId = -1;
@@ -130,7 +130,7 @@
gc.setFont(i_font);
m_fontMetrics = gc.getFontMetrics();
- m_tabWidth = gc.textExtent("\t").x;
+ m_tabAdvance = gc.getAdvanceWidth('\t');
int height = m_fontMetrics.getHeight();
// calculate the area needed to render all available characters
@@ -140,8 +140,10 @@
char c = (char) (m_startChar + i);
String s = Character.toString(c);
Point cExtent = gc.stringExtent(s);
+ int advance = gc.getAdvanceWidth(c);
- m_chars[i] = new LwjglFontChar(c, cExtent.x, height);
+ m_chars[i] =
+ new LwjglFontChar(c, cExtent.x, height, advance);
area += (cExtent.x + 1) * (height + 1);
}
@@ -314,7 +316,7 @@
}
/**
- * Measues the extent of the given string.
+ * Measures the extent of the given string.
*
* @param i_string the string to measure
* @param i_expand specifies whether newline and tab character should be
@@ -340,7 +342,7 @@
switch (c) {
case '\t':
if (i_expand)
- extent.x += m_tabWidth;
+ extent.x += m_tabAdvance;
break;
case '\n':
@@ -351,7 +353,7 @@
int index = c - m_startChar;
if (index >= 0 && index < m_chars.length) {
LwjglFontChar fontChar = m_chars[index];
- extent.x += fontChar.getWidth();
+ extent.x += fontChar.getAdvance();
}
break;
}
@@ -361,19 +363,6 @@
}
/**
- * Returns the texture ID of this font.
- *
- * @return the texture ID
- */
- public int getTextureId() {
-
- if (m_disposed)
- throw new IllegalStateException("font is disposed");
-
- return m_textureId;
- }
-
- /**
* Returns the font metrics of this font.
*
* @return the font metrics
@@ -413,6 +402,19 @@
}
/**
+ * Returns the texture ID of this font.
+ *
+ * @return the texture ID
+ */
+ public int getTextureId() {
+
+ if (m_disposed)
+ throw new IllegalStateException("font is disposed");
+
+ return m_textureId;
+ }
+
+ /**
* Render the given string at the given coordinates. The characters are not
* rendered directly, but their vertex and texture coordinates are put into
* the given buffers.
@@ -451,7 +453,7 @@
switch (c) {
case '\t':
if (i_expand)
- x += m_tabWidth;
+ x += m_tabAdvance;
break;
case '\n':
@@ -465,7 +467,7 @@
fontChar.render(i_transformation, x, y, i_vertexBuffer,
i_coordBuffer);
- x += fontChar.getWidth();
+ x += fontChar.getAdvance();
}
break;
}
@@ -518,7 +520,7 @@
switch (c) {
case '\t':
if (i_expand)
- GL11.glTranslatef(m_tabWidth, 0, 0);
+ GL11.glTranslatef(m_tabAdvance, 0, 0);
break;
case '\n':
@@ -533,7 +535,7 @@
if (index >= 0 && index < m_chars.length) {
LwjglFontChar fontChar = m_chars[index];
m_displayListManager.executeDisplayList(fontChar);
- GL11.glTranslatef(fontChar.getWidth(), 0, 0);
+ GL11.glTranslatef(fontChar.getAdvance(), 0, 0);
}
break;
}
Modified: branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFontChar.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFontChar.java 2010-06-29 16:15:29 UTC (rev 500)
+++ branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglFontChar.java 2010-07-07 16:38:31 UTC (rev 501)
@@ -61,17 +61,23 @@
private final int m_width;
/**
+ * The advance width of this character.
+ */
+ private int m_advance;
+
+ /**
* Creates a new character with the given width and height.
*
* @param i_char the character
* @param i_width the width of this character
* @param i_height the height of the font this character belongs to
+ * @param i_advance the advance width of this character
*/
- public LwjglFontChar(char i_char, int i_width, int i_height) {
-
+ public LwjglFontChar(char i_char, int i_width, int i_height, int i_advance) {
m_char = i_char;
m_width = i_width;
m_height = i_height;
+ m_advance = i_advance;
}
/**
@@ -80,7 +86,6 @@
* @return the width of this character
*/
public int getWidth() {
-
return m_width;
}
@@ -97,7 +102,6 @@
*/
public void render(IMatrix4f i_transformation, float i_x, float i_y,
FloatBuffer i_vertexBuffer, FloatBuffer i_coordBuffer) {
-
if (i_transformation == null
|| IMatrix4f.IDENTITY.equals(i_transformation)) {
i_vertexBuffer.put(i_x);
@@ -159,7 +163,6 @@
* Renders this character directly in immediate mode.
*/
public void render() {
-
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(m_s1, m_t1);
@@ -175,6 +178,15 @@
}
/**
+ * Returns the advance width of this character.
+ *
+ * @return the advance the advance width of this character
+ */
+ public int getAdvance() {
+ return m_advance;
+ }
+
+ /**
* Sets the texture coordinates of this character.
*
* @param i_s1 the S coordinate of the upper left corner
@@ -183,7 +195,6 @@
* @param i_t2 the T coordinate of the lower right corner
*/
public void setTextureCoords(float i_s1, float i_t1, float i_s2, float i_t2) {
-
m_s1 = i_s1;
m_t1 = i_t1;
m_s2 = i_s2;
@@ -197,7 +208,6 @@
*/
@Override
public String toString() {
-
return Character.toString(m_char);
}
}
Modified: branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglVectorFont.java
===================================================================
--- branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglVectorFont.java 2010-06-29 16:15:29 UTC (rev 500)
+++ branches/better_lod/org.eclipse.draw3d.lwjgl/src/java/org/eclipse/draw3d/graphics3d/lwjgl/font/LwjglVectorFont.java 2010-07-07 16:38:31 UTC (rev 501)
@@ -430,8 +430,8 @@
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
try {
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
- // TODO possible creates marginally more lists than need (e.g.
- // for space char)
+ // TODO possibly creates more lists than needed (e.g. for space
+ // char)
m_listBaseId = GL11.glGenLists(charCount);
for (int i = 0; i < charCount; i++) {
int listId = m_listBaseId + i;