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

📄 image.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * Image.java * Copyright (C) 2003 * * $Id: Image.java,v 1.8 2004/11/10 20:35:36 cawe Exp $ *//* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */package jake2.render.fastjogl;import jake2.Defines;import jake2.client.VID;import jake2.client.particle_t;import jake2.game.cvar_t;import jake2.qcommon.*;import jake2.render.image_t;import jake2.util.Lib;import jake2.util.Vargs;import java.awt.Dimension;import java.nio.*;import java.util.Arrays;import net.java.games.jogl.GL;/** * Image *  * @author cwei */public abstract class Image extends Main {    image_t draw_chars;    image_t[] gltextures = new image_t[MAX_GLTEXTURES];    int numgltextures;    int base_textureid; // gltextures[i] = base_textureid+i    byte[] intensitytable = new byte[256];    byte[] gammatable = new byte[256];    cvar_t intensity;    int gl_solid_format = 3;    int gl_alpha_format = 4;    int gl_tex_solid_format = 3;    int gl_tex_alpha_format = 4;    int gl_filter_min = GL.GL_LINEAR_MIPMAP_NEAREST;    int gl_filter_max = GL.GL_LINEAR;    Image() {        // init the texture cache        for (int i = 0; i < gltextures.length; i++) {            gltextures[i] = new image_t(i);        }        numgltextures = 0;    }    void GL_SetTexturePalette(int[] palette) {        assert (palette != null && palette.length == 256) : "int palette[256] bug";        int i;        byte[] temptable = new byte[768];        if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f) {            for (i = 0; i < 256; i++) {                temptable[i * 3 + 0] = (byte) ((palette[i] >> 0) & 0xff);                temptable[i * 3 + 1] = (byte) ((palette[i] >> 8) & 0xff);                temptable[i * 3 + 2] = (byte) ((palette[i] >> 16) & 0xff);            }            gl.glColorTableEXT(GL.GL_SHARED_TEXTURE_PALETTE_EXT, GL.GL_RGB,                    256, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, temptable);        }    }    void GL_EnableMultitexture(boolean enable) {        if (enable) {            GL_SelectTexture(GL_TEXTURE1);            gl.glEnable(GL.GL_TEXTURE_2D);            GL_TexEnv(GL.GL_REPLACE);        } else {            GL_SelectTexture(GL_TEXTURE1);            gl.glDisable(GL.GL_TEXTURE_2D);            GL_TexEnv(GL.GL_REPLACE);        }        GL_SelectTexture(GL_TEXTURE0);        GL_TexEnv(GL.GL_REPLACE);    }    void GL_SelectTexture(int texture) {        int tmu;        tmu = (texture == GL_TEXTURE0) ? 0 : 1;        if (tmu == gl_state.currenttmu) {            return;        }        gl_state.currenttmu = tmu;        gl.glActiveTextureARB(texture);        gl.glClientActiveTextureARB(texture);    }    int[] lastmodes = { -1, -1 };    void GL_TexEnv(int mode) {        if (mode != lastmodes[gl_state.currenttmu]) {            gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, mode);            lastmodes[gl_state.currenttmu] = mode;        }    }    void GL_Bind(int texnum) {        if ((gl_nobind.value != 0) && (draw_chars != null)) {            // performance evaluation option            texnum = draw_chars.texnum;        }        if (gl_state.currenttextures[gl_state.currenttmu] == texnum)            return;        gl_state.currenttextures[gl_state.currenttmu] = texnum;        gl.glBindTexture(GL.GL_TEXTURE_2D, texnum);    }    void GL_MBind(int target, int texnum) {        GL_SelectTexture(target);        if (target == GL_TEXTURE0) {            if (gl_state.currenttextures[0] == texnum)                return;        } else {            if (gl_state.currenttextures[1] == texnum)                return;        }        GL_Bind(texnum);    }    // glmode_t    static class glmode_t {        String name;        int minimize, maximize;        glmode_t(String name, int minimize, int maximze) {            this.name = name;            this.minimize = minimize;            this.maximize = maximze;        }    }    static final glmode_t modes[] = {            new glmode_t("GL_NEAREST", GL.GL_NEAREST, GL.GL_NEAREST),            new glmode_t("GL_LINEAR", GL.GL_LINEAR, GL.GL_LINEAR),            new glmode_t("GL_NEAREST_MIPMAP_NEAREST",                    GL.GL_NEAREST_MIPMAP_NEAREST, GL.GL_NEAREST),            new glmode_t("GL_LINEAR_MIPMAP_NEAREST",                    GL.GL_LINEAR_MIPMAP_NEAREST, GL.GL_LINEAR),            new glmode_t("GL_NEAREST_MIPMAP_LINEAR",                    GL.GL_NEAREST_MIPMAP_LINEAR, GL.GL_NEAREST),            new glmode_t("GL_LINEAR_MIPMAP_LINEAR", GL.GL_LINEAR_MIPMAP_LINEAR,                    GL.GL_LINEAR) };    static final int NUM_GL_MODES = modes.length;    // gltmode_t    static class gltmode_t {        String name;        int mode;        gltmode_t(String name, int mode) {            this.name = name;            this.mode = mode;        }    }    static final gltmode_t[] gl_alpha_modes = { new gltmode_t("default", 4),            new gltmode_t("GL_RGBA", GL.GL_RGBA),            new gltmode_t("GL_RGBA8", GL.GL_RGBA8),            new gltmode_t("GL_RGB5_A1", GL.GL_RGB5_A1),            new gltmode_t("GL_RGBA4", GL.GL_RGBA4),            new gltmode_t("GL_RGBA2", GL.GL_RGBA2), };    static final int NUM_GL_ALPHA_MODES = gl_alpha_modes.length;    static final gltmode_t[] gl_solid_modes = { new gltmode_t("default", 3),            new gltmode_t("GL_RGB", GL.GL_RGB),            new gltmode_t("GL_RGB8", GL.GL_RGB8),            new gltmode_t("GL_RGB5", GL.GL_RGB5),            new gltmode_t("GL_RGB4", GL.GL_RGB4),            new gltmode_t("GL_R3_G3_B2", GL.GL_R3_G3_B2),            new gltmode_t("GL_RGB2", GL.GL_RGB2_EXT) };    static final int NUM_GL_SOLID_MODES = gl_solid_modes.length;    /*     * GL_TextureMode     */    void GL_TextureMode(String string) {        int i;        for (i = 0; i < NUM_GL_MODES; i++) {            if (modes[i].name.equalsIgnoreCase(string))                break;        }        if (i == NUM_GL_MODES) {            VID                    .Printf(Defines.PRINT_ALL, "bad filter name: [" + string                            + "]\n");            return;        }        gl_filter_min = modes[i].minimize;        gl_filter_max = modes[i].maximize;        image_t glt;        // change all the existing mipmap texture objects        for (i = 0; i < numgltextures; i++) {            glt = gltextures[i];            if (glt.type != it_pic && glt.type != it_sky) {                GL_Bind(glt.texnum);                gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,                        gl_filter_min);                gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,                        gl_filter_max);            }        }    }    /*     * GL_TextureAlphaMode     */    void GL_TextureAlphaMode(String string) {        int i;        for (i = 0; i < NUM_GL_ALPHA_MODES; i++) {            if (gl_alpha_modes[i].name.equalsIgnoreCase(string))                break;        }        if (i == NUM_GL_ALPHA_MODES) {            VID.Printf(Defines.PRINT_ALL, "bad alpha texture mode name: ["                    + string + "]\n");            return;        }        gl_tex_alpha_format = gl_alpha_modes[i].mode;    }    /*     * GL_TextureSolidMode     */    void GL_TextureSolidMode(String string) {        int i;        for (i = 0; i < NUM_GL_SOLID_MODES; i++) {            if (gl_solid_modes[i].name.equalsIgnoreCase(string))                break;        }        if (i == NUM_GL_SOLID_MODES) {            VID.Printf(Defines.PRINT_ALL, "bad solid texture mode name: ["                    + string + "]\n");            return;        }        gl_tex_solid_format = gl_solid_modes[i].mode;    }    /*     * GL_ImageList_f     */    void GL_ImageList_f() {        image_t image;        int texels;        final String[] palstrings = { "RGB", "PAL" };        VID.Printf(Defines.PRINT_ALL, "------------------\n");        texels = 0;        for (int i = 0; i < numgltextures; i++) {            image = gltextures[i];            if (image.texnum <= 0)                continue;            texels += image.upload_width * image.upload_height;            switch (image.type) {            case it_skin:                VID.Printf(Defines.PRINT_ALL, "M");                break;            case it_sprite:                VID.Printf(Defines.PRINT_ALL, "S");                break;            case it_wall:                VID.Printf(Defines.PRINT_ALL, "W");                break;            case it_pic:                VID.Printf(Defines.PRINT_ALL, "P");                break;            default:                VID.Printf(Defines.PRINT_ALL, " ");                break;            }            VID.Printf(Defines.PRINT_ALL, " %3i %3i %s: %s\n", new Vargs(4)                    .add(image.upload_width).add(image.upload_height).add(                            palstrings[(image.paletted) ? 1 : 0]).add(                            image.name));        }        VID.Printf(Defines.PRINT_ALL,                "Total texel count (not counting mipmaps): " + texels + '\n');    }    /*     * ==================================================     *      * scrap allocation     *      * Allocate all the little status bar objects into a single texture to     * crutch up inefficient hardware / drivers     *      * ==================================================     */    static final int MAX_SCRAPS = 1;    static final int BLOCK_WIDTH = 256;    static final int BLOCK_HEIGHT = 256;    int[][] scrap_allocated = new int[MAX_SCRAPS][BLOCK_WIDTH];    byte[][] scrap_texels = new byte[MAX_SCRAPS][BLOCK_WIDTH * BLOCK_HEIGHT];    boolean scrap_dirty;    static class pos_t {        int x, y;        pos_t(int x, int y) {            this.x = x;            this.y = y;        }    }    // returns a texture number and the position inside it    int Scrap_AllocBlock(int w, int h, pos_t pos) {        int i, j;        int best, best2;        int texnum;        for (texnum = 0; texnum < MAX_SCRAPS; texnum++) {            best = BLOCK_HEIGHT;            for (i = 0; i < BLOCK_WIDTH - w; i++) {                best2 = 0;                for (j = 0; j < w; j++) {                    if (scrap_allocated[texnum][i + j] >= best)                        break;                    if (scrap_allocated[texnum][i + j] > best2)                        best2 = scrap_allocated[texnum][i + j];                }                if (j == w) { // this is a valid spot                    pos.x = i;                    pos.y = best = best2;                }

⌨️ 快捷键说明

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