Example usage for org.lwjgl.opengl GL11 glPushMatrix

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

Introduction

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

Prototype

public static native void glPushMatrix();

Source Link

Document

Pushes the current matrix stack down by one, duplicating the current matrix in both the top of the stack and the entry below it.

Usage

From source file:RobotDemo.java

private void loop() {
    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

    while (GLFW.glfwWindowShouldClose(window) != GL11.GL_TRUE) {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glPushMatrix();
        for (Robot r : robots)
            r.draw();/*from   w  ww. j  av  a2 s. co m*/
        GL11.glPopMatrix();
        GLFW.glfwSwapBuffers(window);
        GLFW.glfwPollEvents();
    }
}

From source file:Robot.java

private void drawHead() {
    GL11.glColor4f(robotColor[0], robotColor[1], robotColor[2], 1);
    float EYE_RADIUS = HEAD_RADIUS / 5;
    float MOUTH_WIDTH = HEAD_RADIUS * 0.7f;
    // the circular face
    if (selected.get("HEAD")) {
        DrawShapes.fillCircle(HEAD_RADIUS, HEAD_SIDES);
    } else {/*from w w  w . j a va2  s .  com*/
        DrawShapes.strokeCircle(HEAD_RADIUS, HEAD_SIDES);
    }
    // draw the right eye
    GL11.glPushMatrix();
    GL11.glTranslatef(HEAD_RADIUS / 2 - EYE_RADIUS / 2, HEAD_RADIUS * 0.1f, 0);
    if (selected.get("HEAD")) {
        GL11.glColor4f(1, 1, 0, 1);
        DrawShapes.strokeCircle(EYE_RADIUS, HEAD_SIDES);
        GL11.glColor4f(1, 1, 1, 1);
        DrawShapes.fillCircle(EYE_RADIUS * 0.8f, HEAD_SIDES);
        setColor(robotColor[0], robotColor[1], robotColor[2]);
    } else {
        DrawShapes.strokeCircle(EYE_RADIUS, HEAD_SIDES);
        DrawShapes.strokeCircle(EYE_RADIUS * 0.8f, HEAD_SIDES);
    }

    GL11.glPopMatrix();
    // draw the left eye
    GL11.glPushMatrix();
    GL11.glTranslatef(-HEAD_RADIUS / 2 + EYE_RADIUS / 2, HEAD_RADIUS * 0.1f, 0);
    if (selected.get("HEAD")) {
        GL11.glColor4f(1, 1, 0, 1);
        DrawShapes.strokeCircle(EYE_RADIUS, HEAD_SIDES);
        GL11.glColor4f(1, 1, 1, 1);
        DrawShapes.fillCircle(EYE_RADIUS * 0.8f, HEAD_SIDES);
        setColor(robotColor[0], robotColor[1], robotColor[2]);
    } else {
        DrawShapes.strokeCircle(EYE_RADIUS, HEAD_SIDES);
        DrawShapes.strokeCircle(EYE_RADIUS * 0.8f, HEAD_SIDES);
    }
    GL11.glPopMatrix();
    // draw the mouth
    GL11.glPushMatrix();
    GL11.glTranslatef(0, -HEAD_RADIUS / 2, 0);
    if (selected.get("HEAD")) {
        GL11.glColor4f(1, 1, 1, 1);
        DrawShapes.fillRectangle(-MOUTH_WIDTH * 0.5f, 0, MOUTH_WIDTH, MOUTH_WIDTH * 0.1f);
        setColor(robotColor[0], robotColor[1], robotColor[2]);
    } else {
        DrawShapes.strokeRectangle(-MOUTH_WIDTH * 0.5f, 0, MOUTH_WIDTH, MOUTH_WIDTH * 0.1f);
    }
    GL11.glPopMatrix();
}

From source file:Robot.java

public void draw() {
    updateAngles();/*from w w  w  .j  av a 2s .c om*/
    updateLocation();
    GL11.glPushMatrix();
    GL11.glScalef(0.5f, 0.5f, 0.5f);
    // drawing the torso
    GL11.glTranslatef(torsoX, torsoY, 0);
    GL11.glRotatef(torsoAngle[CURRENT_ANGLE], 0, 0, 1);
    drawTorso();

    // drawing the neck
    GL11.glPushMatrix();
    GL11.glTranslatef(0, TORSO_HEIGHT, 0);
    GL11.glRotatef(neckAngle[CURRENT_ANGLE], 0, 0, 1);
    drawNeck();

    // drawing the head
    GL11.glTranslatef(0, NECK_HEIGHT + HEAD_RADIUS, 0);
    GL11.glRotatef(headAngle[CURRENT_ANGLE], 0, 0, 1);
    drawHead();
    GL11.glPopMatrix();

    // drawing the right arms
    GL11.glPushMatrix();
    GL11.glTranslatef(TORSO_WIDTH / 2, TORSO_HEIGHT - UPPER_ARM_HEIGHT, 0);
    GL11.glRotatef(upperRightArmAngle[CURRENT_ANGLE], 0, 0, 1);
    drawUpperRightArm();
    GL11.glTranslatef(UPPER_ARM_WIDTH, LOWER_ARM_HEIGHT, 0);
    GL11.glRotatef(lowerRightArmAngle[CURRENT_ANGLE], 0, 0, 1);
    drawLowerRightArm();
    GL11.glPopMatrix();

    // drawing the left arms
    GL11.glPushMatrix();
    GL11.glScalef(-1, 1, 1); // same as the right arm but on the other side
    GL11.glTranslatef(TORSO_WIDTH / 2, TORSO_HEIGHT - UPPER_ARM_HEIGHT, 0);
    GL11.glRotatef(upperLeftArmAngle[CURRENT_ANGLE], 0, 0, 1);
    drawUpperLeftArm();
    GL11.glTranslatef(UPPER_ARM_WIDTH, LOWER_ARM_HEIGHT, 0);
    GL11.glRotatef(lowerLeftArmAngle[CURRENT_ANGLE], 0, 0, 1);
    drawLowerLeftArm();
    GL11.glPopMatrix();

    // drawing the right leg
    GL11.glPushMatrix();
    GL11.glTranslatef(TORSO_WIDTH / 4 - THIGH_WIDTH / 2, 0, 0);
    GL11.glRotatef(rightThighAngle[CURRENT_ANGLE], 0, 0, 1);
    drawRightThigh();
    GL11.glTranslatef(0, -THIGH_HEIGHT, 0);
    GL11.glRotatef(rightCalfAngle[CURRENT_ANGLE], 0, 0, 1);
    drawRightCalf();
    GL11.glPopMatrix();

    // drawing the left leg
    GL11.glPushMatrix();
    GL11.glScalef(-1, 1, 1); // same as the right arm but on the other side
    GL11.glTranslatef(TORSO_WIDTH / 4 - THIGH_WIDTH / 2, 0, 0);
    GL11.glRotatef(leftThighAngle[CURRENT_ANGLE], 0, 0, 1);
    drawLeftThigh();
    GL11.glTranslatef(0, -THIGH_HEIGHT, 0);
    GL11.glRotatef(leftCalfAngle[CURRENT_ANGLE], 0, 0, 1);
    drawLeftCalf();
    GL11.glPopMatrix();
    GL11.glPopMatrix();
}

From source file:DrawShapes.java

public static void strokeCircle(float x, float y, float z, float radius, int sides) {
    GL11.glPushMatrix();
    GL11.glTranslatef(x, y, z);//www  .  j av a 2  s. c o  m
    strokeCircle(radius, sides);
    GL11.glPopMatrix();
}

From source file:$.DrawSystem.java

License:Open Source License

@Override
    protected void processEntities(ImmutableBag<Entity> entities) {
        GL11.glClearColor(0.1f, 0, 0, 1f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        List<Entity> entititesSortedByZ = new ArrayList<>(entities.size());
        for (int i = 0, n = entities.size(); i < n; ++i) {
            final Entity e = entities.get(i);
            if (e.isEnabled()) {
                entititesSortedByZ.add(e);
            }/*  w w  w  .  j a  va 2s.c  o  m*/
        }
        Collections.sort(entititesSortedByZ, 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();
        GL11.glLoadIdentity();

        updateViewPort();
        GL11.glViewport(viewPort.x, viewPort.y, viewPort.width, viewPort.height);
        GLU.gluOrtho2D(-toolkit.getVirtualResolutionWidth() / 2.0f, toolkit.getVirtualResolutionWidth() / 2.0f,
                toolkit.getVirtualResolutionHeight() / 2.0f, -toolkit.getVirtualResolutionHeight() / 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);

        Game game = (Game) world;
        Entity hero = game.getHero();
        if (null != hero) {
            Sprite heroSprite = spriteMapper.get(hero);
            Vector heroPos = spriteProjector.project(heroSprite.getPosition());
            GL11.glTranslatef(-heroPos.x, -heroPos.y, 0.0f);
        }

        for (Entity e : entititesSortedByZ) {
            MainMenu mainMenu = mainMenuMapper.getSafe(e);
            if (null != mainMenu) {
                mainMenu.draw();
            }
            DialogueComponent dialog = dialogMapper.getSafe(e);
            if (null != dialog) {
                dialog.draw();
            }
            Level level = levelMapper.getSafe(e);
            if (null != level) {
                drawLevel(level);
            }
            Sprite sprite = spriteMapper.getSafe(e);
            if (null != sprite) {
                drawSprite(sprite);
            }
        }
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPopMatrix();
        GL11.glPopAttrib();

    }

From source file:$.DrawSystem.java

License:Open Source License

private void drawLevel(Level level) {

        GL11.glPushMatrix();
        GL11.glLoadIdentity();// w  w w  .ja  v a  2 s .c om
        IPlay backgroundAnimationPlay = level.getBackground();
        backgroundAnimationPlay.update((long) (world.getDelta() * 1000L));
        final IAnimationFrame currentFrame = backgroundAnimationPlay.getCurrentFrame();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, (Integer) currentFrame.getImage().getId());
        float x1 = -toolkit.getVirtualResolutionWidth() / 2.0f;
        float x2 = toolkit.getVirtualResolutionWidth() / 2.0f;
        float y1 = toolkit.getVirtualResolutionHeight() / 2.0f;
        float y2 = -toolkit.getVirtualResolutionHeight() / 2.0f;
        float u1 = currentFrame.getU1();
        float u2 = currentFrame.getU2();

        float v1 = currentFrame.getV2();
        float v2 = currentFrame.getV1();
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(u1, v1);
        GL11.glVertex2f(x1, y2);
        GL11.glTexCoord2f(u2, v1);
        GL11.glVertex2f(x2, y2);
        GL11.glTexCoord2f(u2, v2);
        GL11.glVertex2f(x2, y1);
        GL11.glTexCoord2f(u1, v2);
        GL11.glVertex2f(x1, y1);
        GL11.glEnd();
        GL11.glPopMatrix();
    }

From source file:$.DrawSystem.java

License:Open Source License

private void drawSprite(Sprite sprite) {
        Vector pos = spriteProjector.project(sprite.getPosition());
        final IPlay play = sprite.getPlay();
        if (null != play) {
            GL11.glPushMatrix();
            GL11.glTranslatef(pos.x, pos.y, 0.0f);
            GL11.glRotatef(sprite.getRotate(), 0, 0, 1.0f);
            GL11.glScalef(sprite.getScale(), sprite.getScale(), 1);
            final IAnimationFrame frame = play.getCurrentFrame();
            final IAnimationImage image = frame.getImage();
            if (image.hasAlpha()) {
                GL11.glEnable(GL11.GL_BLEND);
            }/*from www .j a  va 2 s  . com*/
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, (Integer) image.getId());

            final float u1, u2;
            if (sprite.isMirrorX()) {
                u1 = frame.getU2();
                u2 = frame.getU1();
            } else {
                u1 = frame.getU1();
                u2 = frame.getU2();
            }

            final float v1, v2;
            if (sprite.isMirrorY()) {
                v1 = frame.getV1();
                v2 = frame.getV2();
            } else {
                v1 = frame.getV2();
                v2 = frame.getV1();
            }
            GL11.glColor4f(sprite.getRed(), sprite.getGreen(), sprite.getBlue(), sprite.getAlpha());
            float x1 = -sprite.getWidth() / 2.0f;
            float x2 = sprite.getWidth() / 2.0f;
            float y1 = -sprite.getHeight() / 2.0f;
            float y2 = sprite.getHeight() / 2.0f;
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(u1, v1);
            GL11.glVertex2f(x1, y2);
            GL11.glTexCoord2f(u2, v1);
            GL11.glVertex2f(x2, y2);
            GL11.glTexCoord2f(u2, v2);
            GL11.glVertex2f(x2, y1);
            GL11.glTexCoord2f(u1, v2);
            GL11.glVertex2f(x1, y1);
            GL11.glEnd();
            GL11.glColor3f(1f, 1f, 1f);
            if (image.hasAlpha()) {
                GL11.glDisable(GL11.GL_BLEND);
            }
            GL11.glPopMatrix();
        }
        if (null != sprite.getLabel()) {
            GL11.glPushMatrix();
            GL11.glTranslatef(pos.x, pos.y, 0.0f);
            GL11.glScalef(0.5f, -0.5f, 1f);
            GL11.glEnable(GL11.GL_BLEND);
            LwjglNuitFont font = (LwjglNuitFont) assets.getFont("");
            font.drawString(sprite.getLabel(), LwjglNuitFont.Align.CENTER);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glPopMatrix();
        }
    }

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void DoRender() {
    if (!gui_map_rendered)
        return;/*from   w  w w .  j a  va  2 s.co m*/

    if (render_lightmap)
        CreateLightMap();

    RenderedObjects = 0;
    GL11.glPushMatrix();
    GL11.glScalef(scale, scale, 1.0f);
    if (render_tiles)
        DrawTiles();
    if (render_objects)
        DrawObjects();
    DrawFlyText();

    if (render_lightmap)
        RenderLightMap();
    GL11.glPopMatrix();

    if (Config.debug) {
        Render2D.Text("", 10, 200, "mc=" + mc.toString());
        if (mouse_in_object != null)
            Render2D.Text("", 10, 220, "obj=" + mouse_in_object.toString());
        if (mouse_map_pos != null)
            Render2D.Text("", 10, 240, "mouse_map_pos=" + mouse_map_pos.toString());
        if (mouse_tile_coord != null) {
            Render2D.Text("", 10, 260, "mouse_tile_coord=" + mouse_tile_coord.toString());
            Coord tc = mouse_tile_coord.div(TILE_SIZE);
            Render2D.Text("", 10, 280, "mouse_tile=" + tc.toString());
            Render2D.Text("", 10, 300, "mouse_tile_type=" + Integer.toString(MapCache.GetTile(tc)));
        }

        if (player_rect != null)
            Render2D.Text("", 10, 320, "player_rect=" + player_rect.toString());
        Render2D.Text("", 10, 340, "scale=" + String.valueOf(scale));
    }
}

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void DrawObjects() {

    // render all parts
    if (!render_rects) {
        player_rendered = false;/* w w  w .  j av a  2 s  .  com*/
        player_rect = null;
        for (RenderPart p : render_parts) {
            Color col = get_render_part_color(p);

            if (Config.hide_overlapped && !p.ignore_overlap) {
                if (player_rendered && !p.is_my_player) {
                    if (player_rect.is_intersect(p.screen_coord.x, p.screen_coord.y, p.size.x, p.size.y)) {
                        p.is_overlapped = true;
                        if (col == null)
                            col = new Color(1.0f, 1.0f, 1.0f, OVERLAY_K);
                        else
                            col.a = col.a * OVERLAY_K;
                    }
                }
            }

            Sprite.setStaticColor(col);

            p.render();

            if (Config.hide_overlapped && (!p.ignore_overlap || p.is_my_player)) {
                if (p.is_my_player && p.z > 1) {
                    if (!player_rendered)
                        player_rect = new Rect(p.screen_coord, p.size);
                    else
                        player_rect = player_rect.Union(p.screen_coord, p.size);
                    player_rendered = true;
                }
            }
        }

        mouse_in_object = null;
        ignore_overlapped = false;
        if (MouseInMe()) {
            //  ?? 
            for (int u = render_parts.size() - 1; u >= 0; u--) {
                RenderPart p = render_parts.get(u);
                if (p.owner != place_obj && p.owner != null && p.check_hit(gui.mouse_pos.mul(1 / scale))) {
                    mouse_in_object = p.owner;
                    break;
                }
            }
            if (mouse_in_object == null && Config.hide_overlapped) {
                ignore_overlapped = true;
                for (RenderPart p : render_parts) {
                    if (p.is_overlapped && p.owner != place_obj && p.owner != null
                            && p.check_hit(gui.mouse_pos.mul(1 / scale))) {
                        mouse_in_object = p.owner;
                        break;
                    }
                }
            }
        }

    }
    Sprite.setStaticColor();

    Coord oc = viewoffset(scaled_size, mc);
    //   
    for (Obj o : ObjCache.objs.values()) {
        Coord dc = m2s(o.getpos()).add(oc).mul(scale);
        if (!CheckDrawCoord(dc))
            continue;
        ///////////////
        if (render_rects) {
            Render2D.ChangeColor(Color.red);
            Render2D.Disable2D();
            Render2D.FillRect(dc.add(-10, -40), new Coord(20, 40));
            Render2D.Enable2D();
        }
        ///////////////////-----------------------------------------------
        // 
        String nick = "";
        KinInfo kin = o.getattr(KinInfo.class);
        if (kin != null) {
            nick = kin.name;
        }

        ///////////
        if (Config.debug) {
            nick += " objid=" + o.id;
            nick += " dir=" + o.direction;
            //  ?
            LineMove l = o.getattr(LineMove.class);
            if (l != null) {
                Render2D.Disable2D();
                Render2D.ChangeColor(Color.red);
                Render2D.Line(m2s(o.getpos()).add(oc), m2s(l.get_end()).add(oc), 1f);
                Render2D.Enable2D();
                nick += " move";
            }
        }
        if (kin != null) {// || Config.debug) {
            GL11.glPushMatrix();
            GL11.glLoadIdentity();
            Render2D.Text("default", dc.x, dc.y - 10 - Math.round(38 * (scale)), 0, 0, Render2D.Align_Center,
                    nick, Color.white);
            GL11.glPopMatrix();
        }
        //----------------------------------------------------------------

        ///////////////
        //  ? 
        ObjSay say = o.getattr(ObjSay.class);
        if (say != null) {
            String m = say.msg;
            if (m.length() > 32)
                m = m.substring(0, 31) + "...";
            int w = Render2D.GetTextWidth("default", m) + 15;
            int w1, w2, w3;
            int left_w = 35;
            int bh = getSkin().GetElementSize("baloon_center").y;
            w2 = getSkin().GetElementSize("baloon_center").x;
            if (w < 38)
                w = 38;
            if (w < left_w + getSkin().GetElementSize("baloon_right").x) {
                w3 = getSkin().GetElementSize("baloon_right").x;
                w1 = w - w2 - w3;
            } else {
                w3 = w - left_w;
                w1 = left_w - w2;
            }
            int bx = dc.x - w1 - (w2 / 2);
            int by = dc.y - bh - 15 - Math.round(38 * scale);
            GL11.glPushMatrix();
            GL11.glLoadIdentity();
            getSkin().Draw("baloon_left", bx, by, w1, bh);
            getSkin().Draw("baloon_center", bx + w1, by, w2, bh);
            getSkin().Draw("baloon_right", bx + w1 + w2, by, w3, bh);

            Render2D.Text("default", bx, by, w, 27, Render2D.Align_Center, m, Color.white);
            GL11.glPopMatrix();
        }

        //  ? 
        o.render_effects(dc);
    }
}

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void DrawFlyText() {
    Sprite.setStaticColor();//from  w w  w  .j  av a  2s.c o m
    Coord oc = viewoffset(scaled_size, mc);

    for (FlyText.FlyTextItem i : FlyText.items) {
        Coord dc = m2s(i.getpos()).add(oc).mul(scale);
        if (CheckDrawCoord(dc)) {
            GL11.glPushMatrix();
            GL11.glLoadIdentity();
            i.Render(dc);
            GL11.glPopMatrix();
        }
    }
}