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. 22
      src/mightypork/gamecore/loading/AsyncResourceLoader.java
  3. 9
      src/mightypork/gamecore/loading/BaseDeferredResource.java
  4. 16
      src/mightypork/gamecore/render/Render.java
  5. 19
      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(); Render.pushState();
renderScreen(); renderScreen();
Render.popState(); Render.popState();
} }

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

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

@ -183,7 +183,15 @@ public class Render {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS); GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix(); 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); // Log.f3("pop : "+pushed);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPopMatrix(); GL11.glPopMatrix();
GL11.glPopClientAttrib(); GL11.glPopClientAttrib();
GL11.glPopAttrib(); GL11.glPopAttrib();
// GL11.glPopMatrix();
// GL11.glPopClientAttrib();
// GL11.glPopAttrib();
} }
@ -509,7 +524,6 @@ public class Render {
glEnable(GL_BLEND); 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; package mightypork.gamecore.render.fonts;
import static org.lwjgl.opengl.GL11.*;
import java.awt.Font; import java.awt.Font;
import java.awt.FontFormatException; import java.awt.FontFormatException;
import java.io.IOException; import java.io.IOException;
@ -40,7 +42,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
private final double size; private final double size;
private final FontStyle style; private final FontStyle style;
private final String extraChars; private final String extraChars;
private final FilterMode filter; private FilterMode filter;
/** /**
@ -186,4 +188,19 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
font = null; 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) 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.translate(pos.round());
Render.scaleXY(getScale(height)); Render.scaleXY(getScale(height));
font.draw(text, color); font.draw(text, color);
Render.popState(); //Render.popState();
} }

@ -1,6 +1,7 @@
package mightypork.gamecore.render.fonts; package mightypork.gamecore.render.fonts;
import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
import mightypork.utils.math.coord.Coord; import mightypork.utils.math.coord.Coord;
@ -48,4 +49,19 @@ public interface GLFont {
*/ */
int getSize(); 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; 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.color.RGB;
import mightypork.utils.math.coord.Coord; import mightypork.utils.math.coord.Coord;
@ -15,7 +17,7 @@ public class NullFont implements GLFont {
@Override @Override
public void draw(String str, RGB color) public void draw(String str, RGB color)
{ {
// nope Log.w("Drawing with null font.");
} }
@ -43,8 +45,21 @@ public class NullFont implements GLFont {
@Override @Override
public int getSize() public int getSize()
{ {
// TODO Auto-generated method stub
return 0; 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 @Override
*
* @param filter font filtering mode
*/
public void setFiltering(FilterMode filter) public void setFiltering(FilterMode filter)
{ {
this.filter = filter; this.filter = filter;
@ -126,4 +123,12 @@ public class SlickFont implements GLFont {
return fsize; 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 { public class DeferredTexture extends BaseDeferredResource implements FilteredTexture {
private Texture backingTexture; private Texture backingTexture;
private FilterMode filter_min = FilterMode.LINEAR; private FilterMode filter_min = FilterMode.NEAREST;
private FilterMode filter_mag = FilterMode.LINEAR; private FilterMode filter_mag = FilterMode.NEAREST;
private WrapMode wrap = WrapMode.CLAMP; private WrapMode wrap = WrapMode.CLAMP;
@ -81,8 +81,6 @@ public class DeferredTexture extends BaseDeferredResource implements FilteredTex
{ {
if (!ensureLoaded()) return; if (!ensureLoaded()) return;
bindRaw();
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); 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); 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_MIN_FILTER, filter_min.num);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter_mag.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 mightypork.gamecore.gui.constraints.Constraints.*;
import static org.lwjgl.opengl.GL11.*;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.constraints.RectConstraint; import mightypork.gamecore.gui.constraints.RectConstraint;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;
@ -31,6 +32,7 @@ public class LayerFps extends ScreenLayer {
}; };
final GLFont font = Res.getFont("default"); final GLFont font = Res.getFont("default");
final RectConstraint constraint = _round(_move(_grow_down(_right_top(this), 32), -8, 8)); final RectConstraint constraint = _round(_move(_grow_down(_right_top(this), 32), -8, 8));
tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, text); tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, text);

Loading…
Cancel
Save