Example usage for org.lwjgl.opengl GL11 glEnable

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

Introduction

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

Prototype

public static void glEnable(@NativeType("GLenum") int target) 

Source Link

Document

Enables the specified OpenGL state.

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);
            }//w w  w. j a  v a 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 drawSprite(Sprite sprite) {
        Vector pos = spriteProjector.project(sprite.getPosition());
        final IPlay play = sprite.getPlay();
        if (null != play) {
            GL11.glPushMatrix();//  w ww. j a  v  a2  s  . c o  m
            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);
            }
            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_Edit.java

License:Open Source License

public void DoRender() {
    int state;// ww w. j a va2s . c  o  m
    if (!enabled)
        state = StateDisable;
    else {
        if (isFocused())
            state = StateNormal_Checked;
        else {
            if (MouseInMe()) {
                if (pressed)
                    state = StatePressed;
                else
                    state = StateHighlight;
            } else
                state = StateNormal;
        }
    }
    getSkin().Draw(skin_element, abs_pos.x, abs_pos.y, size.x, size.y, state);

    Render2D.PushScissor(new Rect(abs_pos.x + OFFSET, abs_pos.y + OFFSET, size.x - OFFSET, size.y - OFFSET));
    int left = Render2D.GetTextWidth(font_name, getVisualText().substring(0, getSelectionStart()));
    int SelectionWidth = Render2D.GetTextWidth(font_name,
            getVisualText().substring(getSelectionStart(), getSelectionFinish()));
    int CursorShift = Render2D.GetTextWidth(font_name, getVisualText().substring(0, pos2));

    if (isFocused()) {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        if (pos1 != pos2) {
            Render2D.FillRect(new Coord(abs_pos.x + left + OFFSET - scroll, abs_pos.y),
                    new Coord(SelectionWidth, size.y), new Color(0.5f, 0.5f, 0.8f, 0.9f));
        }
        if ((System.currentTimeMillis() % 1000) > 500) {
            Render2D.ChangeColor(Color.green);
            Render2D.Rectangle(new Coord(abs_pos.x + CursorShift + OFFSET - scroll + 1, abs_pos.y),
                    new Coord(1, size.y));
        }
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }

    if (getVisualText().length() > 0)
        Render2D.Text(font_name, abs_pos.x + OFFSET - scroll, abs_pos.y + OFFSET, size.x - OFFSET,
                size.y - OFFSET, Render2D.Align_Left + Render2D.Align_VStretch, getVisualText(), text_color);

    Render2D.PopScissor();
}

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void CreateLightMap() {

    //Coord screen_size = new Coord(Config.getScreenWidth(), Config.getScreenHeight());
    //Coord screen_coord = new Coord(GUI.map.mc).sub(screen_size.div(2));
    List<Coord> lst = new ArrayList<Coord>();

    for (RenderPart p : render_parts) {
        Drawable d = p.owner.getattr(Drawable.class);
        if (d != null) {
            if (d.name.contains("fir")) {
                lst.add(p.dc);//from   w w  w  . j  av  a  2 s .  c o  m
            }
            if (d.name.contains("player")) {
                lst.add(p.dc);
            }
        }
    }

    //      for (Obj o : ObjCache.objs.values()) {
    //         Drawable d = o.getattr(Drawable.class);
    //         if (d != null) {
    //            if (d.name.contains("tree")) {
    //               if (o.getpos().in_rect(screen_coord, screen_size))
    //                  lst.add(o.getpos());
    //            }
    //         }
    //      }

    if (first) {
        first = false;
        boolean FBOEnabled = GLContext.getCapabilities().GL_EXT_framebuffer_object;
        if (!FBOEnabled)
            Log.info("No FBO");
        myFBOId = EXTFramebufferObject.glGenFramebuffersEXT();
        //LightMap = GL11.glGenTextures();

        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, myFBOId);
        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, LightMap, 0);
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
    }

    //ByteBuffer bb = ByteBuffer.allocate(1024 * 1024 * 4);
    //GL11.glReadPixels(0, 0, 1024, 768, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bb);

    // ? FBO  ?  ?
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, myFBOId);
    //      GL11.glPushAttrib(GL11.GL_VIEWPORT_BIT);
    //  ?
    //      GL11.glViewport( 0, 0, 1024, 1024 );
    //      
    // ? 
    //   ?
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glClearColor(0.3f, 0.3f, 0.4f, 1.0f);
    GL11.glClear(GL_COLOR_BUFFER_BIT);

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

    //  ? ? ?
    for (Coord c : lst)
        DrawLight(c, 100, 100);

    /*GL11.glTranslatef(0, 0, -6f);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex3f(0, 0, 0);
    GL11.glVertex3f(200, 0, 0);
    GL11.glVertex3f(200, 200, 0);
    GL11.glVertex3f(0, 200, 0);
    GL11.glEnd();*/
    //      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
    //      GL11.glPopAttrib();

    //      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    //      
    //  
    //GL11.glBindTexture(GL11.GL_TEXTURE_2D, LightMap);
    //Render2D.CheckError();

    //    ?  - ? 
    //GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, 0, 0, 1024, 1024, 0);
    //GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1024, 1024);
    //Render2D.CheckError();

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

}

From source file:a1.Main.java

License:Open Source License

private void initGL() {
    // enable textures since we're going to use these for our sprites
    GL11.glPointSize(1);/*from   ww  w .j  av a2  s.  co  m*/
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_LIGHTING);

    glClearColor(0.0f, 0.0f, 0.0f, 0);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // disable the OpenGL depth test since we're rendering 2D graphics
    GL11.glDisable(GL11.GL_DEPTH_TEST);
}

From source file:a1.Render2D.java

License:Open Source License

static public void PushScissor(Rect s) {
    if (current_scissor == null)
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
    Rect NewRect;/*from w  w w  .  j  a  v a  2s.  com*/
    if (current_scissor == null)
        NewRect = CompareScissorRects(s, s);
    else
        NewRect = CompareScissorRects(s, current_scissor);

    scissors.push(current_scissor);
    current_scissor = NewRect;
    GL11.glScissor(NewRect.x, Config.getScreenHeight() - NewRect.y - NewRect.h, NewRect.w, NewRect.h);
    //GL11.glScissor(s.x, Config.ScreenHeight-s.y-s.h, s.w, s.h);
}

From source file:a1.Render2D.java

License:Open Source License

static public void Enable2D() {
    if (!enabled2d) {
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        Sprite.binded_texture_id = -1;/*from  w  w w. j ava  2 s.  co m*/
        enabled2d = true;
    }
}

From source file:abo.pipes.fluids.gui.GuiPipeFluidsDiamond.java

License:Open Source License

@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {

    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    mc.renderEngine.bindTexture(TEXTURE);

    int cornerX = (width - xSize) / 2;
    int cornerY = (height - ySize) / 2;
    drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);

    drawBackgroundSlots();//w  w  w .  j  a  va2 s  . c  om
}

From source file:abo.pipes.liquids.gui.GuiPipeLiquidsDiamond.java

License:Open Source License

@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {

    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    mc.renderEngine.bindTexture("/gfx/abo/gui/pipeLiquidsDiamond.png");

    int cornerX = (width - xSize) / 2;
    int cornerY = (height - ySize) / 2;
    drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);

    drawBackgroundSlots();/* www  .j av  a  2  s. c o m*/
}

From source file:abo.pipes.power.gui.GuiPipePowerDiamond.java

License:Open Source License

@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {

    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    mc.renderEngine.bindTexture(TEXTURE);

    int cornerX = (width - xSize) / 2;
    int cornerY = (height - ySize) / 2;
    drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);

    for (AdvancedSlot slot : slots) {
        if (slot instanceof YesNoSlot) {
            YesNoSlot s = (YesNoSlot) slot;
            drawTexturedModalRect(cornerX + slot.x, cornerY + slot.y, 240, s.isYes() ? 0 : 16, 16, 16);
        }//from   w  w  w .ja va2 s  .c  o  m
    }
}