2012-11-24 2 views
0

나는 png 글꼴을 가지고 있으며 각 문자의 행/열을 올바르게 얻을 수있어 그 정보가 무엇이 문제인지를 알 수 있습니다. 각 문자는 8 x 8입니다. 여기에 제가 지금까지 가지고있는 코드가 있습니다. 누군가 나에게 도움이나 심지어 약간의 충고를 줄 수 있다면 크게 감사하겠습니다. 여기lwjgl을 사용한 텍스트 렌더링

private double xsize, ysize, x, y, rotate, xh, yh; 
private int lxpos, lypos; 
private Texture texture; 
String text; 

public TextRenderer(int fontsize, int xlocation, int ylocation, 
     int rotates, String path, String Text) { 

    text = Text; 

    rotate = rotates; 
    setXsize(fontsize); 
    ysize = fontsize; 
    x = xlocation; 
    y = ylocation; 
    setXh(getXsize()/2); 
    yh = ysize/2; 

    try { 
     texture = TextureLoader.getTexture(".PNG", new FileInputStream(
       new File(path))); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    texture.bind(); 
    update(); 
} 

public void update() { 

    char[] c = text.toCharArray(); 

    int letter; 
    // 16 collumns 16 rows 
    for (int i = 0; i < c.length; i++) { 
     letter = c[i]; 
     System.out.println(c[i]); 
     lypos = letter % 16; 
     lypos++; 
     System.out.println("Collumn :" + lypos); 
     lxpos = letter/16; 
     System.out.println("Row :" + lxpos); 

     GL11.glEnable(GL11.GL_TEXTURE_2D); 
     GL11.glPushMatrix(); 
     GL11.glTranslated(x, y, 0); 
     GL11.glTranslatef(10.0f, 10.5f, -0.0f); // back to previous position 
     GL11.glRotated(rotate, 0.0f, 0.0f, -1.0f); // rotate 
     GL11.glTranslatef(-10.0f, -10.5f, 0.0f); // to the origin 
     GL11.glTranslated(-x, -y, 0); 
     // above is for movement/rotation of text 

     // 128 px total 

     lxpos = lxpos * 8; 
     lxpos = lxpos * 8; 

     int startx = lxpos * 8; 
     int starty = lypos * 8; 
     double endx = startx + 8; 
     double endy = starty + 8; 
     GL11.glBegin(GL11.GL_QUADS); 
     GL11.glTexCoord2d(startx, starty); 
     GL11.glVertex2d(x - getXh(), y - yh); 
     GL11.glTexCoord2d(startx, endy); 
     GL11.glVertex2d(x - getXh(), y + yh); 
     GL11.glTexCoord2d(endx, endy); 
     GL11.glVertex2d(x + getXh(), y + yh); 

     GL11.glTexCoord2d(endx, starty); 
     GL11.glVertex2d(x + getXh(), y - yh); 
     GL11.glEnd(); 
     GL11.glPopMatrix(); 
     GL11.glDisable(GL11.GL_TEXTURE_2D); 
+2

귀하의 궁금한 점은 무엇입니까? – Qualphey

답변

0

내가 무슨 짓을 :

public class Fsc { 

public static Fsc cA = new Fsc((XCOORDINSHEET), (XCOORDINSHEET), (WIDTHOFCHAR), (HEIGHTOFCHAR)); 
etc... 

public int ix, iy, width, height; 

public Fsc(int ixa, int iya, int widtha, int heighta) { 

ix = ixa; 

iy = iya; 

width = widtha; 

height = heighta; 

} 

public void render(int xa, int ya, float scale) { 

int x2 = ix + width; 

int y2 = iy + height; 

glBegin(GL_QUADS); 

glTexCoord2f(ix, iy); 

glVertex2f(xa, ya); 

glTexCoord2f(x2, iy); 

glVertex2f(xa + width * scale, ya); 

glTexCoord2f(x2, y2); 

glVertex2f(xa + width * scale, ya + height * scale); 

glTexCoord2f(ix, y2); 

glVertex2f(xa, ya + height * scale); 

glEnd(); 

} 

} 

public class Fontsheet { 

public int sheet; 

public Fontsheet(String location) { 

sheet = ImagingTools.glLoadTextureLinear(location); 

} 

public void render(int x, int y, float scale, String text) { 

glEnable(GL_TEXTURE_RECTANGLE_ARB); 

glBindTexture(GL_TEXTURE_RECTANGLE_ARB, sheet); 

float lwidth = 0; 

int x2 = x; 

for(int i = 0; i < text.length(); i++) { 

char c = text.charAt(i); 

x2 += lwidth; 

switch(c) { 

case 'A': 

Fsc.cA.render(x2, y2, scale);lwidth = Fsc.cA.width * scale; 

break; 

case 'B': etc... 

} 

} 

glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); 

glDisable(GL_TEXTURE_RECTANGLE_ARB); 

} 

} 

죄송 그렇지 포맷하는 위해. 나는 그것을 적극적으로 사용하기 때문에 그것이 효과가 있다는 사실을 안다. 그것을 복사 할 때 약간의 코드를 잊어 버린 것 같습니다. 그것이 당신을 위해 작동하지 않으면, 그냥 말해. 호프가 도움이되기를 바랍니다.