Example usage for org.lwjgl.opengl GL11 glMatrixMode

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

Introduction

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

Prototype

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

Source Link

Document

Set the current matrix mode.

Usage

From source file:org.eclipse.swt.snippets.Snippet341.java

License:Open Source License

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;// www .ja  va  2  s.  c  om
    final GLCanvas canvas = new GLCanvas(shell, SWT.NONE, data);
    canvas.setLayoutData(new GridData(640, 480));

    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    canvas.addListener(SWT.Resize, new Listener() {
        @Override
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
                GLContext.useContext(canvas);
            } catch (LWJGLException e) {
                e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
        }
    });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            capture(canvas);
        }
    });
    shell.pack();
    shell.open();

    display.asyncExec(new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.evilco.emulator.core.graphic.matrix.MonochromeMatrixScreen.java

License:Apache License

/**
 * {@inheritDoc}//from  www.jav a 2  s  . com
 */
@Override
public void initialize() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    GL11.glOrtho(0, this.getWidth(), this.getHeight(), 0, 1, -1);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:org.fenggui.binding.render.lwjgl.LWJGLOpenGL.java

License:Open Source License

public void setModelMatrixMode() {
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:org.fenggui.binding.render.lwjgl.LWJGLOpenGL.java

License:Open Source License

public void setProjectionMatrixMode() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
}

From source file:org.fenggui.example.ExampleBasisLWJGL.java

License:Open Source License

private void glInit(int width, int height) {
    // Go into orthographic projection mode.
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();/*from  www .j av  a2  s  . co m*/
    GLU.gluOrtho2D(0, width, 0, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, width, height);

    //set clear color to ... ugly
    GL11.glClearColor(0.1f, 0.5f, 0.2f, 0.0f);
    //sync frame (only works on windows )   => THAT IS NOT TRUE (ask Rainer)
    Display.setVSyncEnabled(false);
}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_SetupGL//from  ww w  .  j  a  v  a 2  s. co  m
 */
void R_SetupGL() {

    //
    // set up viewport
    //
    //int x = (int) Math.floor(r_newrefdef.x * vid.width / vid.width);
    int x = r_newrefdef.x;
    //int x2 = (int) Math.ceil((r_newrefdef.x + r_newrefdef.width) * vid.width / vid.width);
    int x2 = r_newrefdef.x + r_newrefdef.width;
    //int y = (int) Math.floor(vid.height - r_newrefdef.y * vid.height / vid.height);
    int y = vid.height - r_newrefdef.y;
    //int y2 = (int) Math.ceil(vid.height - (r_newrefdef.y + r_newrefdef.height) * vid.height / vid.height);
    int y2 = vid.height - (r_newrefdef.y + r_newrefdef.height);

    int w = x2 - x;
    int h = y - y2;

    GL11.glViewport(x, y2, w, h);

    //
    // set up projection matrix
    //
    float screenaspect = (float) r_newrefdef.width / r_newrefdef.height;
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    MYgluPerspective(r_newrefdef.fov_y, screenaspect, 4, 4096);

    GL11.glCullFace(GL11.GL_FRONT);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    GL11.glRotatef(-90, 1, 0, 0); // put Z going up
    GL11.glRotatef(90, 0, 0, 1); // put Z going up
    GL11.glRotatef(-r_newrefdef.viewangles[2], 1, 0, 0);
    GL11.glRotatef(-r_newrefdef.viewangles[0], 0, 1, 0);
    GL11.glRotatef(-r_newrefdef.viewangles[1], 0, 0, 1);
    GL11.glTranslatef(-r_newrefdef.vieworg[0], -r_newrefdef.vieworg[1], -r_newrefdef.vieworg[2]);

    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, r_world_matrix);
    r_world_matrix.clear();

    //
    // set drawing parms
    //
    if (gl_cull.value != 0.0f) {
        GL11.glEnable(GL11.GL_CULL_FACE);
    } else {
        GL11.glDisable(GL11.GL_CULL_FACE);
    }

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_BeginFrame/*from w  ww. j  a v  a  2  s. c  o  m*/
 */
protected void R_BeginFrame(float camera_separation) {

    gl_state.camera_separation = camera_separation;

    /*
     ** change modes if necessary
     */
    if (gl_mode.modified || vid_fullscreen.modified) {
        // FIXME: only restart if CDS is required
        cvar ref;

        ref = Cvar.Get("vid_ref", "lwjgl", 0);
        ref.modified = true;
    }

    if (gl_log.modified) {
        GLimp_EnableLogging((gl_log.value != 0.0f));
        gl_log.modified = false;
    }

    if (gl_log.value != 0.0f) {
        GLimp_LogNewFrame();
    }

    /*
     ** update 3Dfx gamma -- it is expected that a user will do a vid_restart
     ** after tweaking this value
     */
    if (vid_gamma.modified) {
        vid_gamma.modified = false;

        if ((gl_config.renderer & GL_RENDERER_VOODOO) != 0) {
            // wird erstmal nicht gebraucht

            /*
            char envbuffer[1024];
            float g;
                    
            g = 2.00 * ( 0.8 - ( vid_gamma->value - 0.5 ) ) + 1.0F;
            Com_sprintf( envbuffer, sizeof(envbuffer), "SSTV2_GAMMA=%f", g );
            putenv( envbuffer );
            Com_sprintf( envbuffer, sizeof(envbuffer), "SST_GAMMA=%f", g );
            putenv( envbuffer );
             */
            VID.Printf(Defines.PRINT_DEVELOPER, "gamma anpassung fuer VOODOO nicht gesetzt");
        }
    }

    GLimp_BeginFrame(camera_separation);

    /*
     ** go into 2D mode
     */
    GL11.glViewport(0, 0, vid.width, vid.height);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, vid.width, vid.height, 0, -99999, 99999);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glColor4f(1, 1, 1, 1);

    /*
     ** draw buffer stuff
     */
    if (gl_drawbuffer.modified) {
        gl_drawbuffer.modified = false;

        if (gl_state.camera_separation == 0 || !gl_state.stereo_enabled) {
            if (gl_drawbuffer.string.equalsIgnoreCase("GL_FRONT")) {
                GL11.glDrawBuffer(GL11.GL_FRONT);
            } else {
                GL11.glDrawBuffer(GL11.GL_BACK);
            }
        }
    }

    /*
     ** texturemode stuff
     */
    if (gl_texturemode.modified) {
        GL_TextureMode(gl_texturemode.string);
        gl_texturemode.modified = false;
    }

    if (gl_texturealphamode.modified) {
        GL_TextureAlphaMode(gl_texturealphamode.string);
        gl_texturealphamode.modified = false;
    }

    if (gl_texturesolidmode.modified) {
        GL_TextureSolidMode(gl_texturesolidmode.string);
        gl_texturesolidmode.modified = false;
    }

    /*
     ** swapinterval stuff
     */
    GL_UpdateSwapInterval();

    //
    // clear screen if desired
    //
    R_Clear();
}

From source file:org.free.jake2.render.lwjgl.Mesh.java

License:Open Source License

/**
 * R_DrawAliasModel/*from ww  w  .j av  a  2s .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:org.geekygoblin.nedetlesmaki.game.systems.DrawSystem.java

License:Open Source License

@Override
protected void processEntities(ImmutableBag<Entity> entities) {
    GL11.glClearColor(99f / 255f, 201f / 255f, 183f / 255f, 1f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    Sort.instance().sort(sprites, zComparator);

    GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_TRANSFORM_BIT | GL11.GL_HINT_BIT | GL11.GL_COLOR_BUFFER_BIT
            | GL11.GL_SCISSOR_BIT | GL11.GL_LINE_BIT | GL11.GL_TEXTURE_BIT);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();/*w w w  . ja v a 2 s . c o  m*/
    GL11.glLoadIdentity();

    updateViewPort();
    GL11.glViewport(viewPort.x, viewPort.y, viewPort.width, viewPort.height);
    GLU.gluOrtho2D(-VirtualResolution.WIDTH / 2.0f, VirtualResolution.WIDTH / 2.0f,
            VirtualResolution.HEIGHT / 2.0f, -VirtualResolution.HEIGHT / 2.0f);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);

    NedGame game = (NedGame) world;
    Entity ned = game.getNed();
    if (null != ned) {
        Sprite nedSprite = spriteMapper.get(ned);
        Vector nedPos = spriteProjector.project(nedSprite.getPosition());
        GL11.glTranslatef(-nedPos.x, -nedPos.y, 0.0f);
    }

    for (Entity e : backgrounds) {
        LevelBackground level = levelBackgroundMapper.getSafe(e);
        if (null != level) {
            drawLevel(level);
        }
    }

    GL11.glPushMatrix();
    GL11.glScalef(spriteGlobalScale, spriteGlobalScale, 1.0f);
    spriteBatcher.begin();
    for (Entity e : sprites) {
        spriteBatcher.draw(spriteMapper.getSafe(e));
    }
    spriteBatcher.end();
    for (Entity e : sprites) {
        drawSpriteLabel(spriteMapper.getSafe(e));
    }
    GL11.glPopMatrix();

    for (Entity e : uis) {
        MainMenu mainMenu = mainMenuMapper.getSafe(e);
        if (null != mainMenu) {
            nuitRenderer.render(mainMenu.getRoot());
        }
        DialogComponent dialog = dialogMapper.getSafe(e);
        if (null != dialog) {
            nuitRenderer.render(dialog.getRoot());
        }
        InGameUI inGameUI = inGameUIMapper.getSafe(e);
        if (null != inGameUI) {
            nuitRenderer.render(inGameUI.getRoot());
        }
    }
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();
    GL11.glPopAttrib();

}

From source file:org.jogamp.glg2d.impl.gl2.FastLineVisitor.java

License:Apache License

@Override
public void beginPoly(int windingRule) {
    buffer.clear();/* w w  w . j a  va  2 s.c  o m*/

    /*
     * pen hangs down and to the right. See java.awt.Graphics
     */
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glTranslatef(0.5f, 0.5f, 0);

    GL11.glPushAttrib(GL11.GL_LINE_BIT | GL11.GL_POINT_BIT);
}