⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glf.java

📁 NeHe用java与OpenGL结合教程源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        if (font.symbols[s.charAt(0)] != null)
            minxx = font.symbols[s.charAt(0)].leftx;
        else
            minxx = 0f;

        for (i = 0; i < s.length(); i++) {
            char charI = s.charAt(i);
            if ((font.symbols[charI] == null) || (charI == ' '))
                cw += SpaceSize;
            else {
                sdb = -font.symbols[charI].leftx;
                sda = font.symbols[charI].rightx;

                cw += sda + sdb + SymbolDist;

                /* Update top/bottom bounds */
                if (font.symbols[charI].bottomy > bottom)
                    bottom = font.symbols[charI].bottomy;

                if (font.symbols[charI].topy < top)
                    top = font.symbols[charI].topy;
            }
        }

        cw += minxx;

        if ((maxx != null) && (maxy != null)) {
            maxx[0] = cw;
            maxy[0] = bottom;
        }

        if ((minx != null) && (miny != null)) {
            minx[0] = minxx;
            miny[0] = top;
        }
    }

    public void glfGetStringBounds(String s, float[] minx, float[] miny, float[] maxx, float[] maxy) {
        glfGetStringBoundsF(curfont, s, minx, miny, maxx, maxy);
    }

    public void glfSetSymbolSpace(float sp) {
        SymbolDist = sp;
    }

    public float glfGetSymbolSpace() {
        return SymbolDist;
    }

    public void glfSetSpaceSize(float sp) {
        SpaceSize = sp;
    }

    public float glfGetSpaceSize() {
        return SpaceSize;
    }

    public void glfSetSymbolDepth(float dpth) {
        SymbolDepth = dpth;
    }

    public float glfGetSymbolDepth() {
        return SymbolDepth;
    }

    public int glfSetCurrentFont(int Font_Descriptor) {
        if ((Font_Descriptor < 0) || (fonts[Font_Descriptor] == null)) return GLF_ERROR;

        curfont = Font_Descriptor;
        return GLF_OK;
    }

    public int glfGetCurrentFont() {
        return curfont;
    }

    public void glfSetAnchorPoint(int anchp) {
        if ((anchp >= GLF_LEFT_UP) && (anchp <= GLF_RIGHT_DOWN))
            ap = anchp;
    }

    public void glfSetContourColor(float r, float g, float b, float a) {
        contouring_color[0] = r;
        contouring_color[1] = g;
        contouring_color[2] = b;
        contouring_color[3] = a;
    }

    public void glfEnable(int what) {
        switch (what) {
            case GLF_CONSOLE_MESSAGES:
                console_msg = GLF_YES;
                break;
            case GLF_TEXTURING:
                texturing = GLF_YES;
                break;
            case GLF_CONSOLE_CURSOR:
                conCursor = GLF_YES;
                break;
            case GLF_CONTOURING:
                contouring = GLF_YES;
                break;
        }
    }

    public void glfDisable(int what) {
        switch (what) {
            case GLF_CONSOLE_MESSAGES:
                console_msg = GLF_NO;
                break;
            case GLF_TEXTURING:
                texturing = GLF_NO;
                break;
            case GLF_CONSOLE_CURSOR:
                conCursor = GLF_NO;
                break;
            case GLF_CONTOURING:
                contouring = GLF_NO;
                break;
        }
    }

/* ---------------- Console functions ---------------------- */

    public void glfSetConsoleParam(int width, int height) {
        conWidth = width;
        conHeight = height;
        conData = new StringBuffer[height];
        glfConsoleClear();
    }

    public int glfSetConsoleFont(int Font_Descriptor) {
        if ((Font_Descriptor < 0) || (fonts[Font_Descriptor] == null)) return GLF_ERROR;

        conFont = Font_Descriptor;
        return GLF_OK;
    }

    public void glfConsoleClear() {
        Arrays.fill(conData, null);
        conx = 0;
        cony = 0;
    }

    public void glfPrint(String s, int lenght) {
        for (int i = 0; i < lenght; i++) {
            char charI = s.charAt(i);
            if (charI > 31) {
                conData[cony].append(charI);
                conx++;
            } else if (s.charAt(i) == '\n') conx = conWidth;
            if (conx >= conWidth) {
                conx = 0;
                cony++;
                if (cony >= conHeight) {
                    /* Shift all console contents up */
                    System.arraycopy(conData, 1, conData, 0, conHeight - 1);
                    /* Fill bottom line by spaces */
                    conData[conHeight - 1] = new StringBuffer();
                    cony = conHeight - 1;
                }
            }
        }
    }

    public void glfPrintString(String s) {
        glfPrint(s, s.length());
    }

    public void glfPrintChar(char s) {
        glfPrint(Character.toString(s), 1);
    }

    public void glfConsoleDraw(GL gl) {
        boolean drawCursor = false;

        for (int i = 0; i < conHeight; i++) {
            StringBuffer s = conData[i];
            if ((conCursor == GLF_YES) && (i == cony)) {
                conCursorCount--;
                if (conCursorCount < 0) {
                    conCursorCount = conCursorBlink;
                    if (conCursorMode == GLF_YES)
                        conCursorMode = GLF_NO;
                    else
                        conCursorMode = GLF_YES;
                }

                if (conCursorMode == GLF_YES) {
                    drawCursor = s.length() < conWidth;
                }
            }
            glfDrawSolidStringF(gl, conFont, new String(s));
            if (drawCursor)
                glfDrawSolidSymbolF(gl, conFont, '_');
            gl.glTranslatef(0, -2, 0);
        }
    }

    public void glfSetCursorBlinkRate(int Rate) {
        if (Rate > 0) {
            conCursorBlink = Rate;
            conCursorCount = Rate;
            conCursorMode = GLF_YES;
        }
    }

/* Set string centering for vector fonts */
    public void glfStringCentering(boolean center) {
        m_string_center = center;
    }

/* String direction for vector font (GLF_LEFT, GLF_RIGHT, GLF_UP, GLF_DOWN) */
/* GLF_LEFT by default */
    public void glfStringDirection(int direction) {
        if (direction == GLF_LEFT || direction == GLF_RIGHT ||
                direction == GLF_UP || direction == GLF_DOWN)
            m_direction = direction;
    }

/* Get current text direction */
    public int glfGetStringDirection() {
        return m_direction;
    }


/* Get string centering for vector fonts */
    public boolean glfGetStringCentering() {
        return m_string_center;
    }

/* Set rotate angle for vector fonts */
    public void glfSetRotateAngle(float angle) {
        RotateAngle = angle;
    }


/*
   ---------------------------------------------------------------------------------
   ------------------------ Work with bitmapped fonts ------------------------------
   ---------------------------------------------------------------------------------
*/


///* Some color conversions */
//    static void bwtorgba(unsigned char *b,unsigned char *l,int n)
//    {
//        while (n--) {
//            l[0] = *b;
//            l[1] = *b;
//            l[2] = *b;
//            l[3] = 0xff;
//            l += 4;
//            b++;
//        }
//    }
//
//    static void latorgba(unsigned char *b, unsigned char *a,unsigned char *l,int n)
//    {
//        while (n--) {
//            l[0] = *b;
//            l[1] = *b;
//            l[2] = *b;
//            l[3] = *a;
//            l += 4;
//            b++;
//            a++;
//        }
//    }
//
//    static void rgbtorgba(unsigned char *r,unsigned char *g,unsigned char *b,unsigned char *l,int n)
//    {
//        while (n--) {
//            l[0] = r[0];
//            l[1] = g[0];
//            l[2] = b[0];
//            l[3] = 0xff;
//            l += 4;
//            r++;
//            g++;
//            b++;
//        }
//    }
//
//    static void rgbatorgba(unsigned char *r,unsigned char *g,unsigned char *b,unsigned char *a,unsigned char *l,int n)
//    {
//        while (n--) {
//            l[0] = r[0];
//            l[1] = g[0];
//            l[2] = b[0];
//            l[3] = a[0];
//            l += 4;
//            r++;
//            g++;
//            b++;
//            a++;
//        }
//    }
//
//    private class ImageRec {
//        int imagic;
//        int type;
//        int dim;
//        int xsize, ysize, zsize;
//        int min, max;
//        int wasteBytes;
//        String name;
//        long colorMap;
//        int[] tmp;
//        int[] tmpR;
//        int[] tmpG;
//        int[] tmpB;
//        long rleEnd;
//        int[] rowStart;
//        int[] rowSize;
//    }
//
//    static void ConvertShort(unsigned short *array, long length)
//    {
//        unsigned b1, b2;
//        unsigned char *ptr;
//
//        ptr = (unsigned char *)array;
//        while (length--) {
//            b1 = *ptr++;
//            b2 = *ptr++;
//            *array++ = (b1 << 8) | (b2);
//        }
//    }
//
//    static void ConvertLong(unsigned *array, long length)
//    {
//        unsigned b1, b2, b3, b4;
//        unsigned char *ptr;
//
//        ptr = (unsigned char *)array;
//        while (length--) {
//            b1 = *ptr++;
//            b2 = *ptr++;
//            b3 = *ptr++;
//            b4 = *ptr++;
//            *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4);
//        }
//    }
//
///* Open RGB Image */
//    static ImageRec *ImageOpen(FILE *f)
//    {
//        union
//        {
//            int testWord;
//            char testByte[
//            4];
//        }
//        endianTest;
//
//        ImageRec * image;
//        int swapFlag;
//        int x;
//
//        endianTest.testWord = 1;
//        if (endianTest.testByte[0] == 1)
//            swapFlag = 1;
//        else
//            swapFlag = 0;
//
//        image = (ImageRec *)
//        malloc(sizeof(ImageRec));
//        if (image == null) {
//            fprintf(stderr, "Out of memory!\n");
//            exit(1);
//        }
//
//        image.file = f;
//
//        fread(image, 1, 12, image.file);
//
//        if (swapFlag) ConvertShort(      & image.imagic, 6);
//
//        image.tmp = (unsigned char *)malloc(image.xsize * 256);
//        image.tmpR = (unsigned char *)malloc(image.xsize * 256);
//        image.tmpG = (unsigned char *)malloc(image.xsize * 256);
//        image.tmpB = (unsigned char *)malloc(image.xsize * 256);
//        if (image.tmp == null || image.tmpR == null || image.tmpG == null ||
//                image.tmpB == null) {
//            fprintf(stderr, "Out of memory!\n");
//            exit(1);
//        }
//
//        if ((image.type & 0xFF00) == 0x0100) {
//            x = image.ysize * image.zsize * sizeof(unsigned);
//            image.rowStart = (unsigned *)
//            malloc(x);
//            image.rowSize = (int *)malloc(x);
//            if (image.rowStart == null || image.rowSize == null) {
//                fprintf(stderr, "Out of memory!\n");
//                exit(1);
//            }
//            image.rleEnd = 512 + (2 * x);
//            fseek(image.file, 512 + SEEK_SET_POS, SEEK_SET);
//            fread(image.rowStart, 1, x, image.file);
//            fread(image.rowSize, 1, x, image.file);
//            if (swapFlag) {
//                ConvertLong(image.rowStart, x / (int) sizeof(unsigned));
//                ConvertLong((unsigned *)
//                image.rowSize, x / (int) sizeof(int));
//            }
//        } else {
//            image.rowStart = null;
//            image.rowSize = null;
//        }
//        return image;
//    }
//
///* Close Image and free data */
//    static void ImageClose(ImageRec image)
//    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -