Example usage for org.lwjgl.opengl GL11 glShadeModel

List of usage examples for org.lwjgl.opengl GL11 glShadeModel

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glShadeModel.

Prototype

public static native void glShadeModel(@NativeType("GLenum") int mode);

Source Link

Document

Sets the current shade mode.

Usage

From source file:io.github.SolidStudiosTeam.Flicker.engine.GameLoop.java

License:Open Source License

@Override
public void initGL() {
    /* Enable 2D textures. */
    GL11.glEnable(GL11.GL_TEXTURE_2D);/*from w  w w.ja va 2 s . co  m*/

    /* Make all models smoothly textured. */
    GL11.glShadeModel(GL11.GL_SMOOTH);

    /* Set the background color to that signature blue. */
    GL11.glClearColor(0.9f, 1.0f, 1.0f, 0.0f);

    /* Set the clear depth to all-the-way */
    GL11.glClearDepth(1.0);

    /* Enable the depth system. */
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    /* Set the function for depth to GL_LEQUAL. */
    GL11.glDepthFunc(GL11.GL_LEQUAL);

    //  GL11.glEnable(GL11.GL_BLEND);
    //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    /* Enable face culling, basically don't render this face relative to the camera's position. */
    // GL11.glEnable(GL11.GL_CULL_FACE);

    /* Set OpenGL to cull the back face of our spatials. */
    // GL11.glCullFace(GL11.GL_BACK);

    /* Set the matrix mode to projection. */
    GL11.glMatrixMode(GL11.GL_PROJECTION);

    /* Reset the OpenGL configuration, loading our above prefrences. */
    GL11.glLoadIdentity();

    /* Set the perspective. */
    GLU.gluPerspective(45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 100.0f);

    /* Set the matrix mode to be model view. */
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    /* Set the perspective correction hint to finest quality. */
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}

From source file:ivorius.ivtoolkit.rendering.IvRenderHelper.java

License:Apache License

public static void renderLights(float ticks, int color, float alpha, int number) {
    float width = 2.5f;

    Tessellator tessellator = Tessellator.instance;

    float usedTicks = ticks / 200.0F;

    Random random = new Random(432L);
    GL11.glDisable(GL11.GL_TEXTURE_2D);/* w  ww  . j a v a 2  s  . co  m*/
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glEnable(GL11.GL_BLEND);
    OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glDepthMask(false);
    GL11.glPushMatrix();

    for (int var7 = 0; (float) var7 < number; ++var7) {
        float xLogFunc = (((float) var7 / number * 28493.0f + ticks) / 10.0f) % 20.0f;
        if (xLogFunc > 10.0f) {
            xLogFunc = 20.0f - xLogFunc;
        }

        float yLogFunc = 1.0f / (1.0f + (float) Math.pow(2.71828f, -0.8f * xLogFunc) * ((1.0f / 0.01f) - 1.0f));

        float lightAlpha = yLogFunc;

        if (lightAlpha > 0.01f) {
            GL11.glRotatef(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
            GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 0.0F, 1.0F);
            GL11.glRotatef(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
            GL11.glRotatef(random.nextFloat() * 360.0F + usedTicks * 90.0F, 0.0F, 0.0F, 1.0F);
            tessellator.startDrawing(6);
            float var8 = random.nextFloat() * 20.0F + 5.0F;
            float var9 = random.nextFloat() * 2.0F + 1.0F;
            tessellator.setColorRGBA_I(color, (int) (255.0F * alpha * lightAlpha));
            tessellator.addVertex(0.0D, 0.0D, 0.0D);
            tessellator.setColorRGBA_I(color, 0);
            tessellator.addVertex(-width * (double) var9, var8, (-0.5F * var9));
            tessellator.addVertex(width * (double) var9, var8, (-0.5F * var9));
            tessellator.addVertex(0.0D, var8, (1.0F * var9));
            tessellator.addVertex(-width * (double) var9, var8, (-0.5F * var9));
            tessellator.draw();
        }
    }

    GL11.glPopMatrix();
    GL11.glDepthMask(true);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
}

From source file:jake2.desktop.LWJGLAdapter.java

License:Open Source License

@Override
public void glShadeModel(int sm) {
    GL11.glShadeModel(sm);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public void setShadeModel(int model) {
    GL11.glShadeModel(shadeModelToGL[model]);
}

From source file:kuake2.render.lwjgl.Light.java

License:Open Source License

/**
 * R_RenderDlights/* w w  w .j  a  v  a  2 s  . c o m*/
 */
void R_RenderDlights() {
    if (gl_flashblend.value == 0)
        return;

    r_dlightframecount = r_framecount + 1; // because the count hasn't
    //  advanced yet for this frame
    GL11.glDepthMask(false);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);

    for (int i = 0; i < r_newrefdef.num_dlights; i++) {
        R_RenderDlight(r_newrefdef.dlights[i]);
    }

    GL11.glColor3f(1, 1, 1);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDepthMask(true);
}

From source file:kuake2.render.lwjgl.Mesh.java

License:Open Source License

/**
 * R_DrawAliasModel//  w  w w .j  a v  a 2  s  .  c  o  m
 */
void R_DrawAliasModel(entity_t e) {
    if ((e.flags & Defines.RF_WEAPONMODEL) == 0) {
        if (R_CullAliasModel(e))
            return;
    }

    if ((e.flags & Defines.RF_WEAPONMODEL) != 0) {
        if (r_lefthand.value == 2.0f)
            return;
    }

    qfiles.dmdl_t paliashdr = (qfiles.dmdl_t) currentmodel.extradata;

    //
    // get lighting information
    //
    // PMM - rewrote, reordered to handle new shells & mixing
    // PMM - 3.20 code .. replaced with original way of doing it to keep mod authors happy
    //
    int i;
    if ((currententity.flags & (Defines.RF_SHELL_HALF_DAM | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_RED
            | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE)) != 0) {
        Math3D.VectorClear(shadelight);
        if ((currententity.flags & Defines.RF_SHELL_HALF_DAM) != 0) {
            shadelight[0] = 0.56f;
            shadelight[1] = 0.59f;
            shadelight[2] = 0.45f;
        }
        if ((currententity.flags & Defines.RF_SHELL_DOUBLE) != 0) {
            shadelight[0] = 0.9f;
            shadelight[1] = 0.7f;
        }
        if ((currententity.flags & Defines.RF_SHELL_RED) != 0)
            shadelight[0] = 1.0f;
        if ((currententity.flags & Defines.RF_SHELL_GREEN) != 0)
            shadelight[1] = 1.0f;
        if ((currententity.flags & Defines.RF_SHELL_BLUE) != 0)
            shadelight[2] = 1.0f;
    } else if ((currententity.flags & Defines.RF_FULLBRIGHT) != 0) {
        for (i = 0; i < 3; i++)
            shadelight[i] = 1.0f;
    } else {
        R_LightPoint(currententity.origin, shadelight);

        // player lighting hack for communication back to server
        // big hack!
        if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0) {
            // pick the greatest component, which should be the same
            // as the mono value returned by software
            if (shadelight[0] > shadelight[1]) {
                if (shadelight[0] > shadelight[2])
                    r_lightlevel.value = 150 * shadelight[0];
                else
                    r_lightlevel.value = 150 * shadelight[2];
            } else {
                if (shadelight[1] > shadelight[2])
                    r_lightlevel.value = 150 * shadelight[1];
                else
                    r_lightlevel.value = 150 * shadelight[2];
            }
        }

        if (gl_monolightmap.string.charAt(0) != '0') {
            float s = shadelight[0];

            if (s < shadelight[1])
                s = shadelight[1];
            if (s < shadelight[2])
                s = shadelight[2];

            shadelight[0] = s;
            shadelight[1] = s;
            shadelight[2] = s;
        }
    }

    if ((currententity.flags & Defines.RF_MINLIGHT) != 0) {
        for (i = 0; i < 3; i++)
            if (shadelight[i] > 0.1f)
                break;
        if (i == 3) {
            shadelight[0] = 0.1f;
            shadelight[1] = 0.1f;
            shadelight[2] = 0.1f;
        }
    }

    if ((currententity.flags & Defines.RF_GLOW) != 0) { // bonus items will pulse with time
        float scale;
        float min;

        scale = (float) (0.1f * Math.sin(r_newrefdef.time * 7));
        for (i = 0; i < 3; i++) {
            min = shadelight[i] * 0.8f;
            shadelight[i] += scale;
            if (shadelight[i] < min)
                shadelight[i] = min;
        }
    }

    // =================
    // PGM   ir goggles color override
    if ((r_newrefdef.rdflags & Defines.RDF_IRGOGGLES) != 0
            && (currententity.flags & Defines.RF_IR_VISIBLE) != 0) {
        shadelight[0] = 1.0f;
        shadelight[1] = 0.0f;
        shadelight[2] = 0.0f;
    }
    // PGM
    // =================

    shadedots = r_avertexnormal_dots[((int) (currententity.angles[1] * (SHADEDOT_QUANT / 360.0)))
            & (SHADEDOT_QUANT - 1)];

    float an = (float) (currententity.angles[1] / 180 * Math.PI);
    shadevector[0] = (float) Math.cos(-an);
    shadevector[1] = (float) Math.sin(-an);
    shadevector[2] = 1;
    Math3D.VectorNormalize(shadevector);

    //
    // locate the proper data
    //

    c_alias_polys += paliashdr.num_tris;

    //
    // draw all the triangles
    //
    if ((currententity.flags & Defines.RF_DEPTHHACK) != 0) // hack the depth range to prevent view model from poking into walls
        GL11.glDepthRange(gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin));

    if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0 && (r_lefthand.value == 1.0f)) {
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glScalef(-1, 1, 1);
        MYgluPerspective(r_newrefdef.fov_y, (float) r_newrefdef.width / r_newrefdef.height, 4, 4096);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);

        GL11.glCullFace(GL11.GL_BACK);
    }

    GL11.glPushMatrix();
    e.angles[PITCH] = -e.angles[PITCH]; // sigh.
    R_RotateForEntity(e);
    e.angles[PITCH] = -e.angles[PITCH]; // sigh.

    image_t skin;
    // select skin
    if (currententity.skin != null)
        skin = currententity.skin; // custom player skin
    else {
        if (currententity.skinnum >= qfiles.MAX_MD2SKINS)
            skin = currentmodel.skins[0];
        else {
            skin = currentmodel.skins[currententity.skinnum];
            if (skin == null)
                skin = currentmodel.skins[0];
        }
    }
    if (skin == null)
        skin = r_notexture; // fallback...
    GL_Bind(skin.texnum);

    // draw it

    GL11.glShadeModel(GL11.GL_SMOOTH);

    GL_TexEnv(GL11.GL_MODULATE);
    if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) {
        GL11.glEnable(GL11.GL_BLEND);
    }

    if ((currententity.frame >= paliashdr.num_frames) || (currententity.frame < 0)) {
        VID.Printf(Defines.PRINT_ALL,
                "R_DrawAliasModel " + currentmodel.name + ": no such frame " + currententity.frame + '\n');
        currententity.frame = 0;
        currententity.oldframe = 0;
    }

    if ((currententity.oldframe >= paliashdr.num_frames) || (currententity.oldframe < 0)) {
        VID.Printf(Defines.PRINT_ALL, "R_DrawAliasModel " + currentmodel.name + ": no such oldframe "
                + currententity.oldframe + '\n');
        currententity.frame = 0;
        currententity.oldframe = 0;
    }

    if (r_lerpmodels.value == 0.0f)
        currententity.backlerp = 0;

    GL_DrawAliasFrameLerp(paliashdr, currententity.backlerp);

    GL_TexEnv(GL11.GL_REPLACE);
    GL11.glShadeModel(GL11.GL_FLAT);

    GL11.glPopMatrix();

    if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0 && (r_lefthand.value == 1.0F)) {
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glCullFace(GL11.GL_FRONT);
    }

    if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) {
        GL11.glDisable(GL11.GL_BLEND);
    }

    if ((currententity.flags & Defines.RF_DEPTHHACK) != 0)
        GL11.glDepthRange(gldepthmin, gldepthmax);

    if (gl_shadows.value != 0.0f
            && (currententity.flags & (Defines.RF_TRANSLUCENT | Defines.RF_WEAPONMODEL)) == 0) {
        GL11.glPushMatrix();
        R_RotateForEntity(e);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glColor4f(0, 0, 0, 0.5f);
        GL_DrawAliasShadow(paliashdr, currententity.frame);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glPopMatrix();
    }
    GL11.glColor4f(1, 1, 1, 1);
}

From source file:kuake2.render.lwjgl.Misc.java

License:Open Source License

void GL_SetDefaultState() {
    GL11.glClearColor(1f, 0f, 0.5f, 0.5f); // original quake2
    //GL11.glClearColor(0, 0, 0, 0); // replaced with black
    GL11.glCullFace(GL11.GL_FRONT);/*from  w w  w.  jav  a2s. c o  m*/
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.666f);

    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_BLEND);

    GL11.glColor4f(1, 1, 1, 1);

    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    GL11.glShadeModel(GL11.GL_FLAT);

    GL_TextureMode(gl_texturemode.string);
    GL_TextureAlphaMode(gl_texturealphamode.string);
    GL_TextureSolidMode(gl_texturesolidmode.string);

    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, gl_filter_min);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, gl_filter_max);

    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL_TexEnv(GL11.GL_REPLACE);

    if (qglPointParameterfEXT) {
        // float[] attenuations = { gl_particle_att_a.value, gl_particle_att_b.value, gl_particle_att_c.value };
        FloatBuffer att_buffer = BufferUtils.createFloatBuffer(4);
        att_buffer.put(0, gl_particle_att_a.value);
        att_buffer.put(1, gl_particle_att_b.value);
        att_buffer.put(2, gl_particle_att_c.value);

        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        EXTPointParameters.glPointParameterfEXT(EXTPointParameters.GL_POINT_SIZE_MIN_EXT,
                gl_particle_min_size.value);
        EXTPointParameters.glPointParameterfEXT(EXTPointParameters.GL_POINT_SIZE_MAX_EXT,
                gl_particle_max_size.value);
        EXTPointParameters.glPointParameterEXT(EXTPointParameters.GL_DISTANCE_ATTENUATION_EXT, att_buffer);
    }

    if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f) {
        GL11.glEnable(EXTSharedTexturePalette.GL_SHARED_TEXTURE_PALETTE_EXT);

        GL_SetTexturePalette(d_8to24table);
    }

    GL_UpdateSwapInterval();

    /*
     * vertex array extension
     */
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    ARBMultitexture.glClientActiveTextureARB(GL_TEXTURE0);
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
}

From source file:kubex.KubexGame.java

License:Creative Commons License

/**
 * Inits the game resources (Images, pools, shaders, objects, etc.)
 *//*from  w ww .  ja v  a2s . c om*/
private void initResources() throws IOException {
    //Inits static pools
    FloatBufferPool.init(Chunk.CHUNK_DIMENSION * Chunk.CHUNK_DIMENSION * Chunk.CHUNK_DIMENSION * 2 * 6 * 6, 20);
    ByteArrayPool.init(Chunk.CHUNK_DIMENSION,
            (settings.RENDER_DISTANCE * 2 + 1) * World.HEIGHT * (settings.RENDER_DISTANCE * 2 + 1) * 2);
    glEnable(GL11.GL_CULL_FACE);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL11.GL_BLEND);
    glClearColor(0.6f, 0.8f, 1.0f, 0f);

    //Inits shaders
    GL20.glUseProgram(0);
    textManager = new GlobalTextManager();
    this.DVSP = new DepthVoxelShaderProgram(true);
    this.VSP = new TerrainVoxelShaderProgram(true);
    this.HSP = new HudShaderProgram(true);
    this.DTSP = this.settings.SHADOWS_ENABLED ? new DeferredTerrainShaderProgram(true)
            : new DeferredTerrainUnshadowShaderProgram(true);
    this.DRSP = this.settings.REFLECTIONS_ENABLED ? new DeferredReflectionsShaderProgram(true)
            : new DeferredNoReflectionsShaderProgram(true);
    this.DUTSP = this.settings.SHADOWS_ENABLED ? new DeferredUnderwaterTerrainShaderProgram(true)
            : new DeferredUnderwaterUnshadowTerrainShaderProgram(true);
    this.DUFSP = new DeferredUnderwaterFinalShaderProgram(true);

    //Inits essential objects
    this.TM = new TimeManager();
    this.cam = new Camera(CAMERA_NEAR, CAMERA_FAR, 80f, (float) (X_RES * 3 / 4) / Y_RES); //FOV more width than height BY DESIGN, so blocks looks more "plane". Looks nicer that way, i think.
    this.camInvProjEnv = new CameraInverseProjEnvelope(this.cam);
    this.shadowsManager = new ShadowsManager(SHADOW_SPLITS, this.cam);
    this.liquidRenderer = new DepthPeelingLiquidRenderer(LIQUID_LAYERS);

    this.sunCam = new Camera(new Matrix4f());
    this.sunCam.moveTo(0, 5, 0);
    this.sunCam.setPitch(0);

    this.sky = new Sky(cam, this.sunCam);
    File mapRoute = new File(this.settings.MAP_ROUTE);
    mapRoute.mkdir(); //Creates the maps folder
    this.fileManager = new FileManager(mapRoute, settings.RENDER_DISTANCE);
    this.fileManager.getSettingsFromFile(settings); //Reads default settings from settings file.
    this.world = new World(this.VSP, this.cam, this.sunCam, this.shadowsManager, this.sky, fileManager,
            this.settings);
    this.finalDrawManager = new FinalDrawManager(this.world, this.sky, this.shadowsManager, this.liquidRenderer,
            this.camInvProjEnv.getInvProjMatrix(), CAMERA_NEAR, CAMERA_FAR);
    this.hud = new Hud(this.HSP, X_RES, Y_RES);

    //Load textures here
    glActiveTexture(TEXTURE_FETCH[TILES_TEXTURE_LOCATION]);

    //GL_NEAREST for that blocky look
    //loads the tiles textures into a array
    tilesTexture = Util.loadTextureAtlasIntoTextureArray(FileLoader.loadTileImages(), GL11.GL_NEAREST,
            GL11.GL_NEAREST_MIPMAP_LINEAR, true, settings.ANISOTROPIC_FILTERING_ENABLED);

    Util.loadPNGTexture(FileLoader.loadWaterNormalImage(), TEXTURE_FETCH[WATER_NORMAL_TEXTURE_LOCATION]); //loads the water normal texture

    glActiveTexture(GL_TEXTURE0);
    nightDomeTexture = TextureLoader.getTexture("JPG",
            ResourceLoader.getResourceAsStream("images/nightdome.jpg")); //loads the nightdome

    //Without this, text printing using Slick-Utils doesn't work. Seems it still uses some old mode OpenGL.
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glClearDepth(1);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glViewport(0, 0, X_RES, Y_RES);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, X_RES, Y_RES, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    //First pass deferred rendering
    this.baseFbo = glGenFramebuffers();
    glBindFramebuffer(GL_FRAMEBUFFER, this.baseFbo);

    int colorTexture = glGenTextures();
    int brightnessNormalsTexture = glGenTextures();

    //Creates and inits the base color texture as a RGB texture
    glActiveTexture(TEXTURE_FETCH[BASEFBO_COLOR_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, colorTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, X_RES, Y_RES, 0, GL_RGB, GL_UNSIGNED_BYTE, (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0);

    //Creates and inits the brightness and normals texture as a RGBA texture
    glActiveTexture(TEXTURE_FETCH[BASEFBO_NORMALS_BRIGHTNESS_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, brightnessNormalsTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA, X_RES, Y_RES, 0, GL11.GL_RGBA, GL_UNSIGNED_BYTE,
            (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, brightnessNormalsTexture,
            0);

    //The depth buffer of this FBO will be a texture, too. This will make depth sorting slower but we will be able to access depth values later.
    int baseFboDepth = glGenTextures();

    glActiveTexture(TEXTURE_FETCH[BASEFBO_DEPTH_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, baseFboDepth);
    glTexImage2D(GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, X_RES, Y_RES, 0, GL_DEPTH_COMPONENT,
            GL_UNSIGNED_INT, (FloatBuffer) null);
    System.out.println("ERR" + GL11.glGetError());
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, baseFboDepth, 0); //Set the depth texture as the default render depth target

    IntBuffer drawBuffers = BufferUtils.createIntBuffer(2); //Drawing to 2 textures

    drawBuffers.put(GL_COLOR_ATTACHMENT0);
    drawBuffers.put(GL_COLOR_ATTACHMENT1);

    drawBuffers.flip();
    GL20.glDrawBuffers(drawBuffers);

    //Second pass deferred rendering
    this.deferredFbo = glGenFramebuffers();
    glBindFramebuffer(GL_FRAMEBUFFER, this.deferredFbo);

    int deferredColorTex = glGenTextures();

    //Only uses one texture, a RGBA color texture
    glActiveTexture(TEXTURE_FETCH[DEFERREDFBO_COLOR_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, deferredColorTex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA, X_RES, Y_RES, 0, GL11.GL_RGBA, GL_UNSIGNED_BYTE,
            (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, deferredColorTex, 0);

    drawBuffers = BufferUtils.createIntBuffer(1);

    drawBuffers.put(GL_COLOR_ATTACHMENT0);

    drawBuffers.flip();
    GL20.glDrawBuffers(drawBuffers);

    //If shadows are enabled, we init each shadow map texture, placed in an array
    if (this.settings.SHADOWS_ENABLED) {

        int shadowTexture = glGenTextures();

        glActiveTexture(TEXTURE_FETCH[SHADOW_TEXTURE_LOCATION]);

        glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, shadowTexture);
        //Creates a texture array to place the shadows in
        GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL14.GL_DEPTH_COMPONENT16, SHADOW_XRES, SHADOW_YRES,
                this.shadowsManager.getNumberSplits(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
                (FloatBuffer) null);
        System.out.println("ERR" + GL11.glGetError());
        glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); //Needed to do hardware PCF comparisons via shader
        glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); //Needed to do hardware PCF comparisons via shader
        glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL14.GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); //Needed to do hardware PCF comparisons via shader

        this.shadowFbos = new int[this.shadowsManager.getNumberSplits()];
        //Creates one framebuffer per shadow map
        for (int i = 0; i < this.shadowsManager.getNumberSplits(); i++) {
            this.shadowFbos[i] = glGenFramebuffers();
            glBindFramebuffer(GL_FRAMEBUFFER, this.shadowFbos[i]);
            GL30.glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowTexture, 0, i); //Each framebuffer will have one texture layer (one index of the texture array created before) assigned as render target

            drawBuffers = BufferUtils.createIntBuffer(0);

            GL20.glDrawBuffers(drawBuffers);

        }
    }

    //Liquid layers depth generation. Equal to the shadows depth textures generation.
    int liquidLayers = glGenTextures();

    glActiveTexture(TEXTURE_FETCH[LIQUIDLAYERS_TEXTURE_LOCATION]);
    glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, liquidLayers);
    GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL14.GL_DEPTH_COMPONENT24, X_RES, Y_RES,
            this.liquidRenderer.getNumLayers(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, (FloatBuffer) null);

    glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); //We will compare manually the depth in the shader, we will not perform PCF of any sort in this case
    glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

    int currentLiquidNormalTex = glGenTextures();

    glActiveTexture(KubexGame.TEXTURE_FETCH[KubexGame.CURRENT_LIQUID_NORMAL_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, currentLiquidNormalTex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGB, X_RES, Y_RES, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE,
            (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    this.liquidRenderer.initResources(liquidLayers, currentLiquidNormalTex);

    //Reset active texture and fbo to the default
    glActiveTexture(GL13.GL_TEXTURE0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

From source file:lwjake2.render.lwjgl.Mesh.java

License:Open Source License

/**
 * R_DrawAliasModel/*from  w ww .j  a  v a 2 s.  co  m*/
 */
void R_DrawAliasModel(entity_t e) {
    if ((e.flags & Defines.RF_WEAPONMODEL) == 0) {
        if (R_CullAliasModel(e))
            return;
    }

    if ((e.flags & Defines.RF_WEAPONMODEL) != 0) {
        if (r_lefthand.value == 2.0f)
            return;
    }

    qfiles.dmdl_t paliashdr = (qfiles.dmdl_t) currentmodel.extradata;

    //
    // get lighting information
    //
    // PMM - rewrote, reordered to handle new shells & mixing
    // PMM - 3.20 code .. replaced with original way of doing it to keep mod authors happy
    //
    int i;
    if ((currententity.flags & (Defines.RF_SHELL_HALF_DAM | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_RED
            | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE)) != 0) {
        Math3D.VectorClear(shadelight);
        if ((currententity.flags & Defines.RF_SHELL_HALF_DAM) != 0) {
            shadelight[0] = 0.56f;
            shadelight[1] = 0.59f;
            shadelight[2] = 0.45f;
        }
        if ((currententity.flags & Defines.RF_SHELL_DOUBLE) != 0) {
            shadelight[0] = 0.9f;
            shadelight[1] = 0.7f;
        }
        if ((currententity.flags & Defines.RF_SHELL_RED) != 0)
            shadelight[0] = 1.0f;
        if ((currententity.flags & Defines.RF_SHELL_GREEN) != 0)
            shadelight[1] = 1.0f;
        if ((currententity.flags & Defines.RF_SHELL_BLUE) != 0)
            shadelight[2] = 1.0f;
    }

    else if ((currententity.flags & Defines.RF_FULLBRIGHT) != 0) {
        for (i = 0; i < 3; i++)
            shadelight[i] = 1.0f;
    } else {
        R_LightPoint(currententity.origin, shadelight);

        // player lighting hack for communication back to server
        // big hack!
        if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0) {
            // pick the greatest component, which should be the same
            // as the mono value returned by software
            if (shadelight[0] > shadelight[1]) {
                if (shadelight[0] > shadelight[2])
                    r_lightlevel.value = 150 * shadelight[0];
                else
                    r_lightlevel.value = 150 * shadelight[2];
            } else {
                if (shadelight[1] > shadelight[2])
                    r_lightlevel.value = 150 * shadelight[1];
                else
                    r_lightlevel.value = 150 * shadelight[2];
            }
        }

        if (gl_monolightmap.string.charAt(0) != '0') {
            float s = shadelight[0];

            if (s < shadelight[1])
                s = shadelight[1];
            if (s < shadelight[2])
                s = shadelight[2];

            shadelight[0] = s;
            shadelight[1] = s;
            shadelight[2] = s;
        }
    }

    if ((currententity.flags & Defines.RF_MINLIGHT) != 0) {
        for (i = 0; i < 3; i++)
            if (shadelight[i] > 0.1f)
                break;
        if (i == 3) {
            shadelight[0] = 0.1f;
            shadelight[1] = 0.1f;
            shadelight[2] = 0.1f;
        }
    }

    if ((currententity.flags & Defines.RF_GLOW) != 0) { // bonus items will pulse with time
        float scale;
        float min;

        scale = (float) (0.1f * Math.sin(r_newrefdef.time * 7));
        for (i = 0; i < 3; i++) {
            min = shadelight[i] * 0.8f;
            shadelight[i] += scale;
            if (shadelight[i] < min)
                shadelight[i] = min;
        }
    }

    // =================
    // PGM   ir goggles color override
    if ((r_newrefdef.rdflags & Defines.RDF_IRGOGGLES) != 0
            && (currententity.flags & Defines.RF_IR_VISIBLE) != 0) {
        shadelight[0] = 1.0f;
        shadelight[1] = 0.0f;
        shadelight[2] = 0.0f;
    }
    // PGM   
    // =================

    shadedots = r_avertexnormal_dots[((int) (currententity.angles[1] * (SHADEDOT_QUANT / 360.0)))
            & (SHADEDOT_QUANT - 1)];

    float an = (float) (currententity.angles[1] / 180 * Math.PI);
    shadevector[0] = (float) Math.cos(-an);
    shadevector[1] = (float) Math.sin(-an);
    shadevector[2] = 1;
    Math3D.VectorNormalize(shadevector);

    //
    // locate the proper data
    //

    c_alias_polys += paliashdr.num_tris;

    //
    // draw all the triangles
    //
    if ((currententity.flags & Defines.RF_DEPTHHACK) != 0) // hack the depth range to prevent view model from poking into walls
        GL11.glDepthRange(gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin));

    if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0 && (r_lefthand.value == 1.0f)) {
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glScalef(-1, 1, 1);
        MYgluPerspective(r_newrefdef.fov_y, (float) r_newrefdef.width / r_newrefdef.height, 4, 4096);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);

        GL11.glCullFace(GL11.GL_BACK);
    }

    GL11.glPushMatrix();
    e.angles[PITCH] = -e.angles[PITCH]; // sigh.
    R_RotateForEntity(e);
    e.angles[PITCH] = -e.angles[PITCH]; // sigh.

    image_t skin;
    // select skin
    if (currententity.skin != null)
        skin = currententity.skin; // custom player skin
    else {
        if (currententity.skinnum >= qfiles.MAX_MD2SKINS)
            skin = currentmodel.skins[0];
        else {
            skin = currentmodel.skins[currententity.skinnum];
            if (skin == null)
                skin = currentmodel.skins[0];
        }
    }
    if (skin == null)
        skin = r_notexture; // fallback...
    GL_Bind(skin.texnum);

    // draw it

    GL11.glShadeModel(GL11.GL_SMOOTH);

    GL_TexEnv(GL11.GL_MODULATE);
    if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) {
        GL11.glEnable(GL11.GL_BLEND);
    }

    if ((currententity.frame >= paliashdr.num_frames) || (currententity.frame < 0)) {
        VID.Printf(Defines.PRINT_ALL,
                "R_DrawAliasModel " + currentmodel.name + ": no such frame " + currententity.frame + '\n');
        currententity.frame = 0;
        currententity.oldframe = 0;
    }

    if ((currententity.oldframe >= paliashdr.num_frames) || (currententity.oldframe < 0)) {
        VID.Printf(Defines.PRINT_ALL, "R_DrawAliasModel " + currentmodel.name + ": no such oldframe "
                + currententity.oldframe + '\n');
        currententity.frame = 0;
        currententity.oldframe = 0;
    }

    if (r_lerpmodels.value == 0.0f)
        currententity.backlerp = 0;

    GL_DrawAliasFrameLerp(paliashdr, currententity.backlerp);

    GL_TexEnv(GL11.GL_REPLACE);
    GL11.glShadeModel(GL11.GL_FLAT);

    GL11.glPopMatrix();

    if ((currententity.flags & Defines.RF_WEAPONMODEL) != 0 && (r_lefthand.value == 1.0F)) {
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glCullFace(GL11.GL_FRONT);
    }

    if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) {
        GL11.glDisable(GL11.GL_BLEND);
    }

    if ((currententity.flags & Defines.RF_DEPTHHACK) != 0)
        GL11.glDepthRange(gldepthmin, gldepthmax);

    if (gl_shadows.value != 0.0f
            && (currententity.flags & (Defines.RF_TRANSLUCENT | Defines.RF_WEAPONMODEL)) == 0) {
        GL11.glPushMatrix();
        R_RotateForEntity(e);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glColor4f(0, 0, 0, 0.5f);
        GL_DrawAliasShadow(paliashdr, currententity.frame);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glPopMatrix();
    }
    GL11.glColor4f(1, 1, 1, 1);
}

From source file:lwjglapp.Lights.java

private void initGL() {
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, matSpecular); // sets specular material color
    GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 50.0f); // sets shininess

    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, lightPosition); // sets light position
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, whiteLight); // sets specular light to white
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, whiteLight); // sets diffuse light to white
    GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, lModelAmbient); // global ambient light 

    GL11.glEnable(GL11.GL_LIGHTING); // enables lighting
    GL11.glEnable(GL11.GL_LIGHT0); // enables light0

    GL11.glEnable(GL11.GL_COLOR_MATERIAL); // enables opengl to use glColor3f to define material color
    GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE); // tell opengl glColor3f effects the ambient and diffuse properties of material
}