Example usage for org.lwjgl.opengl GL11 glLoadIdentity

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

Introduction

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

Prototype

public static native void glLoadIdentity();

Source Link

Document

Sets the current matrix to the identity matrix.

Usage

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);
            }//www  .ja v a 2 s  . 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();/* ww  w  .j ava 2s . c  o m*/
        GL11.glLoadIdentity();
        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:a1.gui.GUI_Map.java

License:Open Source License

public void DrawObjects() {

    // render all parts
    if (!render_rects) {
        player_rendered = false;/*from w  w w. j  av  a2 s.c om*/
        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();/*w w  w .  j  a  v a  2 s  .  co  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();
        }
    }
}

From source file:a1.Main.java

License:Open Source License

private void setView(int screenWidth, int screenHeight) {
    GL11.glViewport(0, 0, screenWidth, screenHeight);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, screenWidth, screenHeight, 0, -1, 1);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();//from w  w w . j  a v  a 2  s . c  o  m
}

From source file:a1.Main.java

License:Open Source License

private void render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    GL11.glLoadIdentity();

    GL11.glPushMatrix();/*  ww w .  j  a  va 2 s .  c o m*/
    GUI.getInstance().Render();
    GL11.glPopMatrix();

    // render debug info
    if (Config.debug)
        DrawDebug();

    fps_counter++;
    if (System.currentTimeMillis() - last_fps_tick > 1000) {
        last_fps_tick = System.currentTimeMillis();
        FPS = fps_counter;
        fps_counter = 0;
    }

}

From source file:a1.ObjExp.java

License:Open Source License

@SuppressWarnings("AccessStaticViaInstance")
public void render(Coord dc) {
    double t = (float) life_time / (float) MAX_LIFE_TIME;
    int a = FlyParam.GetAlpha(t);

    String s1 = Integer.toString(combat);
    String s2 = Integer.toString(industry);
    String s3 = Integer.toString(nature);
    String ss = "+" + s1 + "/" + s2 + "/" + s3;
    String s;/* ww  w . j a v a2  s .  c  om*/
    int tw = Render2D.GetTextWidth("", ss);
    int x = dc.x - tw / 2 - 7;
    int y = (int) (dc.y - (FlyParam.GetY(t) + 35) - 38 * GUI.map.scale);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    s = "+";
    Render2D.Text("default", x, y, s, new Color(255, 255, 255, a));
    x += Render2D.GetTextWidth("", s) + 2;
    s = s1;
    Render2D.Text("default", x, y, s, new Color(255, 40, 40, a));
    x += Render2D.GetTextWidth("", s) + 4;
    s = "/";
    Render2D.Text("default", x, y, s, new Color(255, 255, 255, a));
    x += Render2D.GetTextWidth("", s) + 2;
    s = s2;
    Render2D.Text("default", x, y, s, new Color(100, 209, 232, a));
    x += Render2D.GetTextWidth("", s) + 4;
    s = "/";
    Render2D.Text("default", x, y, s, new Color(255, 255, 255, a));
    x += Render2D.GetTextWidth("", s) + 2;
    s = s3;
    Render2D.Text("default", x, y, s, new Color(40, 255, 40, a));
    GL11.glPopMatrix();
}

From source file:adrianton.gloptat.plotter.Displayer.java

License:Open Source License

private void surface() {
    GL11.glLoadIdentity();

    GL11.glTranslatef(posx, posy, posz);

    GL11.glRotatef(roty, 1, 0, 0);//w w  w.  java  2  s . c  o m
    GL11.glRotatef(rotz, 0, 0, 1);

    GL11.glScaled(0.3, 0.3, 0.3);
    GL11.glScaled(pasz, pasz, pasz);

    Surface.call();
}

From source file:akarnokd.opengl.experiment.FontExample.java

License:Apache License

/**
 * Initialise the GL display//from   w ww. j a va2 s.  co m
 * 
 * @param width The width of the display
 * @param height The height of the display
 */
private void initGL(int width, int height) {
    try {
        Display.setDisplayMode(new DisplayMode(width, height));
        Display.create();
        Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glClearDepth(1);

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

    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, height, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:aphelion.client.Client.java

License:Open Source License

public static void initGL() {
    int displayWidth = Display.getWidth();
    int displayHeight = Display.getHeight();

    glDisableAll();//from  w w  w  .ja  va 2 s .  c  om

    GL11.glViewport(0, 0, displayWidth, displayHeight);

    GL11.glMatrixMode(GL11.GL_PROJECTION); // Apply subsequent matrix operations to the projection matrix stack.
    GL11.glLoadIdentity();
    GL11.glOrtho(0, displayWidth, displayHeight, 0, -1, 1);

    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glLoadIdentity();

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

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
    AsyncTexture.unbind();

    // Enable alpha channels for images
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);

    Graph.g.setDimensions(displayWidth, displayHeight);
    Graphics.setCurrent(Graph.g);
    Graph.g.setDrawMode(Graphics.MODE_NORMAL);
}