glf.java
来自「NeHe用java与OpenGL结合教程源码」· Java 代码 · 共 1,668 行 · 第 1/4 页
JAVA
1,668 行
// image.tmp = null;
// image.tmpR = null;
// image.tmpG = null;
// image.tmpB = null;
// image.rowSize = null;
// image.rowStart = null;
// }
//
///* Pixels row decoding (if used RLE encoding) */
// static void ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z)
// {
// unsigned char *iPtr, *oPtr, pixel;
// int count;
//
// if ((image.type & 0xFF00) == 0x0100) {
// fseek(image.file, (long) image.rowStart[y + z * image.ysize] + SEEK_SET_POS, SEEK_SET);
// fread(image.tmp, 1, (unsigned int)image.rowSize[y + z * image.ysize], image.file);
//
// iPtr = image.tmp;
// oPtr = buf;
// for (; ;) {
// pixel = *iPtr++;
// count = (int) (pixel & 0x7F);
// if (!count) return;
// if (pixel & 0x80) while (count--) *oPtr++ = *iPtr++;
// else
// {
// pixel = *iPtr++;
// while (count--) *oPtr++ = pixel;
// }
// }
// } else {
// fseek(image.file, 512 + (y * image.xsize) + (z * image.xsize * image.ysize) + SEEK_SET_POS, SEEK_SET);
// fread(buf, 1, image.xsize, image.file);
// }
// }
//
///* Read SGI (RGB) Image from file */
// static int[] read_texture(LittleEndianDataInputStream in, int width, int height, int components)
// {
// unsigned * base, *lptr;
// unsigned char *rbuf, *gbuf, *bbuf, *abuf;
// ImageRec * image;
// int y;
//
// image = ImageOpen(f);
//
// if (!image) return null;
// ( * width) = image.xsize;
// ( * height) = image.ysize;
// ( * components) = image.zsize;
//
// base = (unsigned *)
// malloc(image.xsize * image.ysize * sizeof(unsigned));
// rbuf = (unsigned char *)malloc(image.xsize * sizeof(unsigned char));
// gbuf = (unsigned char *)malloc(image.xsize * sizeof(unsigned char));
// bbuf = (unsigned char *)malloc(image.xsize * sizeof(unsigned char));
// abuf = (unsigned char *)malloc(image.xsize * sizeof(unsigned char));
//
// if (!base || !rbuf || !gbuf || !bbuf) return null;
// lptr = base;
// for (y = 0; y < image.ysize; y++) {
// if (image.zsize >= 4) {
// ImageGetRow(image, rbuf, y, 0);
// ImageGetRow(image, gbuf, y, 1);
// ImageGetRow(image, bbuf, y, 2);
// ImageGetRow(image, abuf, y, 3);
// rgbatorgba(rbuf, gbuf, bbuf, abuf, (unsigned char *)lptr, image.xsize);
// lptr += image.xsize;
// } else if (image.zsize == 3) {
// ImageGetRow(image, rbuf, y, 0);
// ImageGetRow(image, gbuf, y, 1);
// ImageGetRow(image, bbuf, y, 2);
// rgbtorgba(rbuf, gbuf, bbuf, (unsigned char *)lptr, image.xsize);
// lptr += image.xsize;
// } else if (image.zsize == 2) {
// ImageGetRow(image, rbuf, y, 0);
// ImageGetRow(image, abuf, y, 1);
// latorgba(rbuf, abuf, (unsigned char *)lptr, image.xsize);
// lptr += image.xsize;
// } else {
// ImageGetRow(image, rbuf, y, 0);
// bwtorgba(rbuf, (unsigned char *)lptr, image.xsize);
// lptr += image.xsize;
// }
// }
// ImageClose(image);
// free(rbuf);
// free(gbuf);
// free(bbuf);
// free(abuf);
//
// return (unsigned *)
// base;
// }
//
///* Font texture conversion to mask texture */
// int[] texture_to_mask(int[] tex, int width, int height)
// {
// int nSize, i;
// int[] ret;
//
// nSize = width * height;
// ret = new int[nSize];
// for (i = 0; i < nSize; i++)
// ret[i] = tex[i] & 0x00ffffff ? 0 : 0x00ffffff;
//
// return ret;
// }
//
///* Load BMF file format, function return bitmap font descriptor */
// int glfLoadBFont(GL gl, String fontf) {
// byte[] Header = new byte[3];
// byte[] FontName = new byte[96];
// int LEndian;
// float tx, ty, tw, th;
// int temp, tp;
// int[] texture; /* Texture image */
// int[] mask; /* Mask texture */
// int twidth, theight, tcomp; /* Image parameters */
// float[] temp_width;
//
// LittleEndianDataInputStream in = null;
//
// /* Get header */
// in.readFully(Header);
// Header[3] = 0;
// if (Arrays.equals(Header, new byte[]{'B','M','F'}))
// return GLF_ERROR; /* Not BMF format */
//
// /* Get font name */
// in.readFully(FontName);
//
// /* Allocate space for temp widths */
//
// temp_width = new float[256];
//
// /* Read all 256 symbols information */
// for (int i = 0; i < 256; i++) {
// tx = in.readFloat();
// ty = in.readFloat();
// tw = in.readFloat();
// th = in.readFloat();
//
// Symbols[i].x = tx;
// Symbols[i].y = ty;
// Symbols[i].width = tw;
// Symbols[i].height = th;
// temp_width[i] = tw;
// }
//
// /* Read texture image from file and build texture */
// texture = read_texture(fontf, & twidth, &theight, &tcomp);
// /* Generate mask texture */
// mask = texture_to_mask(texture, twidth, theight);
//
// /* Find unused font descriptor */
// boolean flag = false;
// for (int i = 0; i < MAX_FONTS; i++)
// if (bmf_in_use[i] == false) {
// /* Initialize this font */
// bmf_in_use[i] = true;
// bmf_curfont = i;
// flag = true;
// break;
// }
// if (!flag) /* Not enought space for new texture */ {
// return GLF_ERROR;
// }
//
// m_widths[bmf_curfont].width = temp_width;
//
// /* Generating textures for font and mask */
// int[] gltexture = new int[1];
// gl.glGenTextures(1, gltexture);
// bmf_texture[bmf_curfont] = gltexture[0];
// gl.glGenTextures(1, gltexture);
// bmf_mask[bmf_curfont] = gltexture[0];
//
// gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
//
// /* Build font texture */
// gl.glBindTexture(GL.GL_TEXTURE_2D, bmf_texture[bmf_curfont]);
// gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, twidth, theight, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, texture);
//
// /* Linear filtering for better quality */
// gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
// gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
//
// /* Build mask texture */
// gl.glBindTexture(GL.GL_TEXTURE_2D, bmf_mask[bmf_curfont]);
// gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, twidth, theight, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, mask);
// gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
// gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
//
// /* Now build list for each symbol */
// list_base[bmf_curfont] = gl.glGenLists(256);
// for (int i = 0; i < 256; i++) {
// gl.glNewList(list_base[bmf_curfont] + i, GL.GL_COMPILE);
//
// gl.glBegin(GL.GL_QUADS);
// gl.glTexCoord2f(Symbols[i].x, Symbols[i].y);
// gl.glVertex2f(0, 0);
// gl.glTexCoord2f(Symbols[i].x + Symbols[i].width, Symbols[i].y);
// gl.glVertex2f(Symbols[i].width, 0);
// gl.glTexCoord2f(Symbols[i].x + Symbols[i].width, Symbols[i].y + Symbols[i].height);
// gl.glVertex2f(Symbols[i].width, Symbols[i].height);
// gl.glTexCoord2f(Symbols[i].x, Symbols[i].y + Symbols[i].height);
// gl.glVertex2f(0, Symbols[i].height);
// gl.glEnd();
// gl.glTranslatef(Symbols[i].width + sym_space, 0, 0);
//
// gl.glEndList();
// if (Symbols[i].height > m_max_height[bmf_curfont]) m_max_height[bmf_curfont] = Symbols[i].height;
// }
// return bmf_curfont;
// }
//
///* Unloads bitmap font by descriptor */
// int glfUnloadBFontD(GL gl, int bmf_descriptor) {
// if ((bmf_descriptor < 0) || (bmf_in_use[bmf_descriptor] == false)) return GLF_ERROR;
//
// bmf_in_use[bmf_descriptor] = false;
//
// int[] texture = new int[1];
// texture[0] = bmf_texture[bmf_descriptor];
// gl.glDeleteTextures(1, texture );
// texture[0] = bmf_mask[bmf_descriptor];
// gl.glDeleteTextures(1, texture);
//
// if (bmf_descriptor == bmf_curfont) bmf_curfont = -1;
//
// return GLF_OK;
// }
//
///* Unloads current bitmap font */
// int glfUnloadBFont(GL gl) {
// return glfUnloadBFontD(gl, bmf_curfont);
// }
//
//
///* Start bitmap drawing function */
// int glfBeginBFont(GL gl, int Font_Descriptor) {
// int ret = glfSetCurrentBFont(Font_Descriptor);
// if (ret != GLF_OK) return ret;
//
// /* Enable 2D Texturing */
// byte[] texturing = new byte[1];
// gl.glGetBooleanv(GL.GL_TEXTURE_2D, texturing);
// bmf_texturing = texturing[0] != 0;
// gl.glEnable(GL.GL_TEXTURE_2D);
//
// gl.glBindTexture(GL.GL_TEXTURE_2D, bmf_texture[bmf_curfont]);
//
// return GLF_OK;
// }
//
///* Stop bitmap drawing function */
// void glfEndBFont(GL gl) {
// /* Return previuos state of texturing */
// if (bmf_texturing)
// gl.glEnable(GL.GL_TEXTURE_2D);
// else
// gl.glDisable(GL.GL_TEXTURE_2D);
// }
//
///* Select current BMF font */
// int glfSetCurrentBFont(int Font_Descriptor) {
// if ((Font_Descriptor < 0) || (bmf_in_use[Font_Descriptor] == false)) return GLF_ERROR;
//
// bmf_curfont = Font_Descriptor;
// return GLF_OK;
// }
//
///* Get current BMF font */
// int glfGetCurrentBFont() {
// return bmf_curfont;
// }
//
///* Draw one bitmapped symbol by current font */
// void glfDrawBSymbol(GL gl, char s) {
// if ((bmf_curfont < 0) || (bmf_in_use[bmf_curfont] == false)) return;
//
// gl.glCallList(list_base[bmf_curfont] + s);
// }
//
///* Draw bitmapped string */
// void glfDrawBString(GL gl, String s)
// {
// float temp_trans;
// int i;
//
// temp_trans = 0;
//
// if ((bmf_curfont < 0) || (bmf_in_use[bmf_curfont] == false)) return;
//
// /* Calculate length of all string */
// for (i = 0; i < s.length(); i++)
// temp_trans += m_widths[bmf_curfont].width[s.charAt(i)] + sym_space;
//
// gl.glListBase(list_base[bmf_curfont]);
// if (m_bitmap_string_center == true) {
// gl.glPushMatrix();
// gl.glTranslatef(-temp_trans / 2, 0, 0);
// }
// gl.glCallLists(s.length(), GL.GL_UNSIGNED_BYTE, s.toCharArray());
// if (m_bitmap_string_center == true) gl.glPopMatrix();
// }
//
// void glfDrawBMaskSymbol(GL gl, char s) {
// if ((bmf_curfont < 0) || (bmf_in_use[bmf_curfont] == false)) return;
//
// gl.glPushMatrix();
// gl.glPushAttrib(GL.GL_CURRENT_BIT);
//
// /* Draw the text as a mask in black */
// gl.glColor3i(0xff, 0xff, 0xff);
// gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_ZERO);
// gl.glBindTexture(GL.GL_TEXTURE_2D, bmf_mask[bmf_curfont]);
//
// gl.glCallList(list_base[bmf_curfont] + s);
//
// gl.glPopAttrib();
// gl.glPopMatrix();
//
// gl.glBindTexture(GL.GL_TEXTURE_2D, bmf_texture[bmf_curfont]);
//
// /* Now draw the text over only the black bits in the requested color */
// gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
//
// gl.glCallList(list_base[bmf_curfont] + s);
// }
//
// void glfDrawBMaskString(GL gl, String s)
// {
// float temp_trans;
// int i;
//
// temp_trans = 0;
//
// if ((bmf_curfont < 0) || (bmf_in_use[bmf_curfont] == false)) return;
//
// /* Calculate length of all string */
// for (i = 0; i < s.length(); i++)
// temp_trans += m_widths[bmf_curfont].width[s.charAt(i)] + sym_space;
//
// gl.glPushMatrix();
// gl.glPushAttrib(GL.GL_CURRENT_BIT);
//
// /* Draw the text as a mask in black */
// gl.glColor3i(0xff, 0xff, 0xff);
// gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_ZERO);
// gl.glBindTexture(GL.GL_TEXTURE_2D, bmf_mask[bmf_curfont]);
//
// gl.glListBase(list_base[bmf_curfont]);
// if (m_bitmap_string_center == true) {
// gl.glPushMatrix();
// gl.glTranslatef(-temp_trans / 2, 0, 0);
// }
// gl.glCallLists(s.length(), GL.GL_UNSIGNED_BYTE, s.toCharArray());
// if (m_bitmap_string_center == true) gl.glPopMatrix();
//
// gl.glPopAttrib();
// gl.glPopMatrix();
//
// gl.glBindTexture(GL.GL_TEXTURE_2D, bmf_texture[bmf_curfont]);
//
// /* Now draw the text over only the black bits in the requested color */
// gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
// gl.glListBase(list_base[bmf_curfont]);
// if (m_bitmap_string_center == true) {
// gl.glPushMatrix();
// gl.glTranslatef(-temp_trans / 2, 0, 0);
// }
// gl.glCallLists(s.length(), GL.GL_UNSIGNED_BYTE, s.toCharArray());
// if (m_bitmap_string_center == true) gl.glPopMatrix();
// }
//
///* Set string centering for bitmap fonts */
// void glfBitmapStringCentering(boolean center) {
// m_bitmap_string_center = center;
// }
//
///* Set string centering for bitmap fonts */
// boolean glfBitmapGetStringCentering() {
// return m_bitmap_string_center;
// }
//
///* Set rotate angle for bitmap fonts */
// void glfSetBRotateAngle(float angle) {
// RotateAngleB = angle;
// }
/* One symbol of font */
private static class Symbol {
int vertexs; /* Number of vertexs */
int facets; /* Number of facets */
int lines; /* Number of lines in symbol */
float[] vdata; /* Pointer to Vertex data */
int[] fdata; /* Pointer to Facets data */
int[] ldata; /* Pointer to Line data */
float leftx; /* Smaller x coordinate */
float rightx; /* Right x coordinate */
float topy; /* Top y coordinate */
float bottomy; /* Bottom y coordinate */
};
/* Font structure */
private static class GLFFont {
String font_name;
int sym_total; /* Total symbols in font */
Symbol[] symbols = new Symbol[MAX_FONTS]; /* Pointers to symbols */
};
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?