📄 glf.java
字号:
distance -= SpaceSize;
} else if (i < s.length() - 1) {
if (s.charAt(i + 1) == ' ') {
if (m_direction == GLF_LEFT || m_direction == GLF_UP)
distance += SymbolDist;
else
distance -= SymbolDist;
} else {
if (fonts[curfont].symbols[s.charAt(i + 1)] == null) continue;
if (m_direction == GLF_LEFT || m_direction == GLF_RIGHT) {
sda = Math.abs(fonts[curfont].symbols[s.charAt(i)].rightx);
sdb = Math.abs(fonts[curfont].symbols[s.charAt(i + 1)].leftx);
if (m_direction == GLF_LEFT)
distance += sda + sdb + SymbolDist;
else
distance -= sda + sdb + SymbolDist;
} else {
sda = Math.abs(fonts[curfont].symbols[s.charAt(i)].topy);
sdb = Math.abs(fonts[curfont].symbols[s.charAt(i)].bottomy);
if (m_direction == GLF_DOWN)
distance -= sda + sdb + SymbolDist;
else
distance += sda + sdb + SymbolDist;
}
}
}
}
}
gl.glPushMatrix();
/* Rotate if needed */
if (RotateAngle != 0.0f) gl.glRotatef(RotateAngle, 0, 0, 1);
/* Correct string position */
if (m_string_center) {
switch (m_direction) {
case GLF_LEFT:
gl.glTranslatef(-distance / 2, 0, 0);
break;
case GLF_RIGHT:
gl.glTranslatef(distance / 2, 0, 0);
break;
case GLF_UP:
gl.glTranslatef(0, distance / 2, 0);
break;
case GLF_DOWN:
gl.glTranslatef(0, -distance / 2, 0);
break;
}
} else if (s.charAt(0) != ' ') {
switch (m_direction) {
case GLF_LEFT:
gl.glTranslatef(-(1 - Math.abs(fonts[curfont].symbols[s.charAt(0)].leftx)), 0, 0);
break;
case GLF_RIGHT:
gl.glTranslatef((1 - Math.abs(fonts[curfont].symbols[s.charAt(0)].rightx)), 0, 0);
break;
case GLF_UP:
gl.glTranslatef(0, (1 - Math.abs(fonts[curfont].symbols[s.charAt(0)].topy)), 0);
break;
case GLF_DOWN:
gl.glTranslatef(0, -(1 - Math.abs(fonts[curfont].symbols[s.charAt(0)].bottomy)), 0);
break;
}
}
/* Start to draw our string */
for (i = 0; i < s.length(); i++) {
if (s.charAt(i) != ' ') funct.drawCharacter(gl, s.charAt(i));
if ((fonts[curfont].symbols[s.charAt(i)] == null) || (s.charAt(i) == ' ')) {
switch (m_direction) {
case GLF_LEFT:
gl.glTranslatef(SpaceSize, 0, 0);
break;
case GLF_RIGHT:
gl.glTranslatef(-SpaceSize, 0, 0);
break;
case GLF_UP:
gl.glTranslatef(0, SpaceSize, 0);
break;
case GLF_DOWN:
gl.glTranslatef(0, -SpaceSize, 0);
break;
}
} else {
if (i < (s.length() - 1)) {
if (s.charAt(i + 1) == ' ') {
switch (m_direction) {
case GLF_LEFT:
gl.glTranslatef(SymbolDist, 0, 0);
break;
case GLF_RIGHT:
gl.glTranslatef(-SymbolDist, 0, 0);
break;
case GLF_UP:
gl.glTranslatef(0, SymbolDist, 0);
break;
case GLF_DOWN:
gl.glTranslatef(0, -SymbolDist, 0);
break;
}
} else {
if (fonts[curfont].symbols[s.charAt(i + 1)] == null) continue;
if (m_direction == GLF_LEFT || m_direction == GLF_RIGHT) {
if (m_direction == GLF_LEFT) {
sda = Math.abs(fonts[curfont].symbols[s.charAt(i)].rightx);
sdb = Math.abs(fonts[curfont].symbols[s.charAt(i + 1)].leftx);
} else {
sda = Math.abs(fonts[curfont].symbols[s.charAt(i + 1)].rightx);
sdb = Math.abs(fonts[curfont].symbols[s.charAt(i)].leftx);
}
if (m_direction == GLF_LEFT)
gl.glTranslatef(sda + sdb + SymbolDist, 0, 0);
else
gl.glTranslatef(-(sda + sdb + SymbolDist), 0, 0);
} else {
if (m_direction == GLF_DOWN) {
sda = Math.abs(fonts[curfont].symbols[s.charAt(i)].topy);
sdb = Math.abs(fonts[curfont].symbols[s.charAt(i + 1)].bottomy);
} else {
sda = Math.abs(fonts[curfont].symbols[s.charAt(i + 1)].topy);
sdb = Math.abs(fonts[curfont].symbols[s.charAt(i)].bottomy);
}
if (m_direction == GLF_DOWN)
gl.glTranslatef(0, -(sda + sdb + SymbolDist), 0);
else
gl.glTranslatef(0, sda + sdb + SymbolDist, 0);
}
}
}
}
}
gl.glPopMatrix();
}
public void glfDrawWiredString(GL gl, String s) {
DrawString(gl, s, drawWiredSymbol);
}
/* Draw wired string by font_descriptor */
public void glfDrawWiredStringF(GL gl, int font_descriptor, String s) {
int temp;
temp = curfont;
curfont = font_descriptor;
DrawString(gl, s, drawWiredSymbol);
curfont = temp;
}
public void glfDrawSolidSymbol(GL gl, char s) {
int b; /* Face pointer */
int i, j;
float x, y;
float[] temp_color = new float[4];
if ((curfont < 0) || (fonts[curfont] == null)) return;
if (fonts[curfont].symbols[s] == null) return;
b = 0;
gl.glBegin(GL.GL_TRIANGLES);
for (i = 0; i < fonts[curfont].symbols[s].facets; i++) {
for (j = 0; j < 3; j++) {
x = fonts[curfont].symbols[s].vdata[fonts[curfont].symbols[s].fdata[b] * 2];
y = fonts[curfont].symbols[s].vdata[fonts[curfont].symbols[s].fdata[b] * 2 + 1];
if (texturing == GLF_YES) gl.glTexCoord2f((x + 1) / 2, (y + 1) / 2);
gl.glVertex2f(x, y);
b++;
}
}
gl.glEnd();
/* Draw contour, if enabled */
if (contouring == GLF_YES) {
gl.glGetFloatv(GL.GL_CURRENT_COLOR, temp_color, 0);
gl.glColor4fv(contouring_color, 0);
glfDrawWiredSymbol(gl, s);
gl.glColor4fv(temp_color, 0);
}
}
/* Draw solid symbol by font_descriptor */
public void glfDrawSolidSymbolF(GL gl, int font_descriptor, char s) {
int temp;
temp = curfont;
curfont = font_descriptor;
glfDrawSolidSymbol(gl, s);
curfont = temp;
}
public void glfDrawSolidString(GL gl, String s) {
DrawString(gl, s, drawSolidSymbol);
}
/* Draw solid string by font_descriptor */
public void glfDrawSolidStringF(GL gl, int font_descriptor, String s) {
int temp;
temp = curfont;
curfont = font_descriptor;
DrawString(gl, s, drawSolidSymbol);
curfont = temp;
}
/* ------------ 3D Wired text drawing ---------------------- */
public void glfDraw3DWiredSymbol(GL gl, char s) {
int i, cur_line;
int tvp; /* temp vertex pointer */
float x, y;
if ((curfont < 0) || (fonts[curfont] == null)) return;
if (fonts[curfont].symbols[(int) s] == null) return;
/* Draw front symbol */
gl.glBegin(GL.GL_LINE_LOOP);
tvp = 0;
cur_line = 0;
for (i = 0; i < fonts[curfont].symbols[s].vertexs; i++) {
x = fonts[curfont].symbols[s].vdata[tvp++];
y = fonts[curfont].symbols[s].vdata[tvp++];
gl.glVertex3f(x, y, 1);
if (fonts[curfont].symbols[s].ldata[cur_line] == i) {
gl.glEnd();
cur_line++;
if (cur_line < fonts[curfont].symbols[s].lines)
gl.glBegin(GL.GL_LINE_LOOP);
else
break; /* No more lines */
}
}
/* Draw back symbol */
gl.glBegin(GL.GL_LINE_LOOP);
tvp = 0;
cur_line = 0;
for (i = 0; i < fonts[curfont].symbols[s].vertexs; i++) {
x = fonts[curfont].symbols[s].vdata[tvp++];
y = fonts[curfont].symbols[s].vdata[tvp++];
gl.glVertex3f(x, y, 1 + SymbolDepth);
if (fonts[curfont].symbols[s].ldata[cur_line] == i) {
gl.glEnd();
cur_line++;
if (cur_line < fonts[curfont].symbols[s].lines)
gl.glBegin(GL.GL_LINE_LOOP);
else
break; /* No more lines */
}
}
/* Draw lines between back and front symbols */
gl.glBegin(GL.GL_LINES);
tvp = 0;
for (i = 0; i < fonts[curfont].symbols[s].vertexs; i++) {
x = fonts[curfont].symbols[s].vdata[tvp++];
y = fonts[curfont].symbols[s].vdata[tvp++];
gl.glVertex3f(x, y, 1);
gl.glVertex3f(x, y, 1 + SymbolDepth);
}
gl.glEnd();
}
/* Draw 3D wired symbol by font_descriptor */
public void glfDraw3DWiredSymbolF(GL gl, int font_descriptor, char s) {
int temp;
temp = curfont;
curfont = font_descriptor;
glfDraw3DWiredSymbol(gl, s);
curfont = temp;
}
public void glfDraw3DWiredString(GL gl, String s) {
DrawString(gl, s, draw3DWiredSymbol);
}
/* Draw 3D wired string by font_descriptor */
public void glfDraw3DWiredStringF(GL gl, int font_descriptor, String s) {
int temp;
temp = curfont;
curfont = font_descriptor;
DrawString(gl, s, draw3DWiredSymbol);
curfont = temp;
}
/* ------------ 3D Solid text drawing ---------------------- */
public void glfDraw3DSolidSymbol(GL gl, char s) {
int i, j, cur_line;
boolean flag;
float x, y;
float bx = 0f;
float by = 0f;
int b; /* Face pointer */
int tvp; /* temp vertex pointer */
float[] temp_color = new float[4];
byte[] light_temp = new byte[1];
if ((curfont < 0) || (fonts[curfont] == null)) return;
if (fonts[curfont].symbols[(int) s] == null) return;
b = 0;
gl.glBegin(GL.GL_TRIANGLES);
gl.glNormal3f(0, 0, 1);
for (i = 0; i < fonts[curfont].symbols[s].facets; i++) {
b += 2;
for (j = 0; j < 3; j++) {
x = fonts[curfont].symbols[s].vdata[fonts[curfont].symbols[s].fdata[b] * 2];
y = fonts[curfont].symbols[s].vdata[fonts[curfont].symbols[s].fdata[b] * 2 + 1];
gl.glVertex3f(x, y, 1 + SymbolDepth);
b--;
}
b += 4;
}
gl.glEnd();
b = 0;
gl.glBegin(GL.GL_TRIANGLES);
gl.glNormal3f(0, 0, -1);
for (i = 0; i < fonts[curfont].symbols[s].facets; i++) {
for (j = 0; j < 3; j++) {
x = fonts[curfont].symbols[s].vdata[fonts[curfont].symbols[s].fdata[b] * 2];
y = fonts[curfont].symbols[s].vdata[fonts[curfont].symbols[s].fdata[b] * 2 + 1];
gl.glVertex3f(x, y, 1);
b++;
}
}
gl.glEnd();
flag = false;
gl.glBegin(GL.GL_QUAD_STRIP);
tvp = 0;
cur_line = 0;
for (i = 0; i < fonts[curfont].symbols[s].vertexs; i++) {
x = fonts[curfont].symbols[s].vdata[tvp++];
y = fonts[curfont].symbols[s].vdata[tvp++];
if (!flag) {
bx = x;
by = y;
flag = true;
}
gl.glNormal3f(x, y, 0);
gl.glVertex3f(x, y, 1);
gl.glVertex3f(x, y, 1 + SymbolDepth);
if (fonts[curfont].symbols[s].ldata[cur_line] == i) {
gl.glVertex3f(bx, by, 1);
gl.glVertex3f(bx, by, 1 + SymbolDepth);
flag = false;
gl.glEnd();
cur_line++;
if (cur_line < fonts[curfont].symbols[s].lines)
gl.glBegin(GL.GL_QUAD_STRIP);
else
break; /* No more lines */
}
}
/* Draw contour, if enabled */
if (contouring == GLF_YES) {
gl.glGetBooleanv(GL.GL_LIGHTING, light_temp, 0);
gl.glDisable(GL.GL_LIGHTING);
gl.glGetFloatv(GL.GL_CURRENT_COLOR, temp_color, 0);
gl.glColor4fv(contouring_color, 0);
glfDraw3DWiredSymbol(gl, s);
gl.glColor4fv(temp_color, 0);
if (light_temp[0] != 0) gl.glEnable(GL.GL_LIGHTING);
}
}
/* Draw 3D solid symbol by font_descriptor */
public void glfDraw3DSolidSymbolF(GL gl, int font_descriptor, char s) {
int temp;
temp = curfont;
curfont = font_descriptor;
glfDraw3DSolidSymbol(gl, s);
curfont = temp;
}
public void glfDraw3DSolidString(GL gl, String s) {
DrawString(gl, s, draw3DSolidSymbol);
}
/* Draw 3D solid string by font_descriptor */
public void glfDraw3DSolidStringF(GL gl, int font_descriptor, String s) {
int temp;
temp = curfont;
curfont = font_descriptor;
DrawString(gl, s, draw3DSolidSymbol);
curfont = temp;
}
/* Get the size a string will have on screen */
public void glfGetStringBoundsF(int fd, String s, float[] minx, float[] miny, float[] maxx, float[] maxy) {
GLFFont font;
int i;
float sda, sdb, cw = 0, minxx = 10;
float top = 10, bottom = -10;
if (fd < 0 || fd > (MAX_FONTS - 1)) return;
font = fonts[fd];
if (font == null) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -