somethings weird with font

v5stable
Ondřej Hruška 11 years ago
parent dacb43df3a
commit ebac276ed2
  1. 2
      src/mightypork/gamecore/gui/screens/Screen.java
  2. 20
      src/mightypork/gamecore/loading/AsyncResourceLoader.java
  3. 9
      src/mightypork/gamecore/loading/BaseDeferredResource.java
  4. 18
      src/mightypork/gamecore/render/Render.java
  5. 21
      src/mightypork/gamecore/render/fonts/DeferredFont.java
  6. 6
      src/mightypork/gamecore/render/fonts/FontRenderer.java
  7. 16
      src/mightypork/gamecore/render/fonts/GLFont.java
  8. 19
      src/mightypork/gamecore/render/fonts/NullFont.java
  9. 15
      src/mightypork/gamecore/render/fonts/SlickFont.java
  10. 8
      src/mightypork/gamecore/render/textures/DeferredTexture.java
  11. 2
      src/mightypork/rogue/screens/LayerFps.java

@ -120,7 +120,9 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
}
Render.pushState();
renderScreen();
Render.popState();
}

@ -57,16 +57,18 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
// textures & fonts needs to be loaded in main thread
if (resource.getClass().isAnnotationPresent(MustLoadInMainThread.class)) {
Log.f3("<LOADER> Delegating to main thread:\n " + Log.str(resource));
// just ignore
app.getEventBus().send(new MainLoopTaskRequest(new Runnable() {
@Override
public void run()
{
resource.load();
}
}));
// Log.f3("<LOADER> Delegating to main thread:\n " + Log.str(resource));
//
// app.getEventBus().send(new MainLoopTaskRequest(new Runnable() {
//
// @Override
// public void run()
// {
// resource.load();
// }
// }));
return;
}

@ -33,10 +33,12 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
@Override
public synchronized final void load()
{
if(loadFailed) return;
if (loadAttempted) {
Log.w("<RES> Already loaded @ load():\n " + this);
(new IllegalStateException()).printStackTrace();
//return;
return;
}
loadAttempted = true;
@ -80,8 +82,9 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
if (isLoaded()) {
return true;
} else {
Log.w("<RES> First use, not loaded yet - loading directly\n " + this);
(new IllegalStateException()).printStackTrace();
if(loadFailed) return false;
Log.f3("<RES> (!) First use, not loaded yet - loading directly\n " + this);
load();
}

@ -183,7 +183,15 @@ public class Render {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
// GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
// GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
// GL11.glPushMatrix();
}
@ -200,9 +208,16 @@ public class Render {
// Log.f3("pop : "+pushed);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPopMatrix();
GL11.glPopClientAttrib();
GL11.glPopAttrib();
// GL11.glPopMatrix();
// GL11.glPopClientAttrib();
// GL11.glPopAttrib();
}
@ -508,8 +523,7 @@ public class Render {
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
}

@ -1,6 +1,8 @@
package mightypork.gamecore.render.fonts;
import static org.lwjgl.opengl.GL11.*;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException;
@ -40,7 +42,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
private final double size;
private final FontStyle style;
private final String extraChars;
private final FilterMode filter;
private FilterMode filter;
/**
@ -90,7 +92,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
protected synchronized final void loadResource(String path) throws FontFormatException, IOException
{
final Font awtFont = getAwtFont(path, (float) size, style.numval);
font = new SlickFont(awtFont, filter, extraChars);
}
@ -185,5 +187,20 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
// this will have to suffice
font = null;
}
@Override
public void setFiltering(FilterMode filter)
{
this.filter = filter;
if(isLoaded()) font.setFiltering(filter);
}
@Override
public FilterMode getFiltering()
{
return filter;
}
}

@ -123,15 +123,15 @@ public class FontRenderer {
*/
public void draw(String text, Coord pos, double height, RGB color)
{
Render.pushState();
//Render.pushState();
GL11.glEnable(GL11.GL_TEXTURE_2D);
//GL11.glEnable(GL11.GL_TEXTURE_2D);
Render.translate(pos.round());
Render.scaleXY(getScale(height));
font.draw(text, color);
Render.popState();
//Render.popState();
}

@ -1,6 +1,7 @@
package mightypork.gamecore.render.fonts;
import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Coord;
@ -47,5 +48,20 @@ public interface GLFont {
* @return specified font size
*/
int getSize();
/**
* Set used filtering
*
* @param filter font filtering mode
*/
void setFiltering(FilterMode filter);
/**
* Get used filter mode
*
* @return filter mode
*/
FilterMode getFiltering();
}

@ -1,6 +1,8 @@
package mightypork.gamecore.render.fonts;
import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Coord;
@ -15,7 +17,7 @@ public class NullFont implements GLFont {
@Override
public void draw(String str, RGB color)
{
// nope
Log.w("Drawing with null font.");
}
@ -43,8 +45,21 @@ public class NullFont implements GLFont {
@Override
public int getSize()
{
// TODO Auto-generated method stub
return 0;
}
@Override
public void setFiltering(FilterMode filter)
{
// nope
}
@Override
public FilterMode getFiltering()
{
return null;
}
}

@ -41,11 +41,8 @@ public class SlickFont implements GLFont {
}
/**
* Set used filtering
*
* @param filter font filtering mode
*/
@Override
public void setFiltering(FilterMode filter)
{
this.filter = filter;
@ -125,5 +122,13 @@ public class SlickFont implements GLFont {
{
return fsize;
}
@Override
public FilterMode getFiltering()
{
return filter;
}
}

@ -21,8 +21,8 @@ import org.newdawn.slick.opengl.Texture;
public class DeferredTexture extends BaseDeferredResource implements FilteredTexture {
private Texture backingTexture;
private FilterMode filter_min = FilterMode.LINEAR;
private FilterMode filter_mag = FilterMode.LINEAR;
private FilterMode filter_min = FilterMode.NEAREST;
private FilterMode filter_mag = FilterMode.NEAREST;
private WrapMode wrap = WrapMode.CLAMP;
@ -81,8 +81,6 @@ public class DeferredTexture extends BaseDeferredResource implements FilteredTex
{
if (!ensureLoaded()) return;
bindRaw();
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrap.num);
@ -91,6 +89,8 @@ public class DeferredTexture extends BaseDeferredResource implements FilteredTex
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter_min.num);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter_mag.num);
bindRaw();
}

@ -2,6 +2,7 @@ package mightypork.rogue.screens;
import static mightypork.gamecore.gui.constraints.Constraints.*;
import static org.lwjgl.opengl.GL11.*;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.constraints.RectConstraint;
import mightypork.gamecore.gui.screens.Screen;
@ -31,6 +32,7 @@ public class LayerFps extends ScreenLayer {
};
final GLFont font = Res.getFont("default");
final RectConstraint constraint = _round(_move(_grow_down(_right_top(this), 32), -8, 8));
tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, text);

Loading…
Cancel
Save