Example usage for org.lwjgl.opengl GL11 glGetInteger

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

Introduction

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

Prototype

@NativeType("void")
public static int glGetInteger(@NativeType("GLenum") int pname) 

Source Link

Document

Returns the current integer value of the specified state variable.

Usage

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static int glGetInteger(int a) {
    switch (a) {//  w  ww .  j  a v  a  2  s. c o  m
    case GL_CURRENT_PROGRAM:
        return currentProgram;
    case GL_MAX_TEXTURE_UNITS:
        return textureUnits1d.length;
    case GL_TEXTURE_BINDING_1D:
        return textureUnits1d[activeTexture];
    case GL_TEXTURE_BINDING_2D:
        return textureUnits2d[activeTexture];
    case GL_TEXTURE_BINDING_3D:
        return textureUnits3d[activeTexture];
    case GL_TEXTURE_BINDING_1D_ARRAY:
        return textureUnits1dArr[activeTexture];
    case GL_TEXTURE_BINDING_2D_ARRAY:
        return textureUnits2dArr[activeTexture];
    case GL_TEXTURE_BINDING_RECTANGLE:
        return textureUnitsRect[activeTexture];
    case GL_TEXTURE_BINDING_BUFFER:
        return textureUnitsBuf[activeTexture];
    case GL_TEXTURE_BINDING_CUBE_MAP:
        return textureUnitsCube[activeTexture];
    case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
        return textureUnitsCubeArr[activeTexture];
    case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
        return textureUnitsSampled[activeTexture];
    case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
        return textureUnitsSampledArr[activeTexture];
    case GL_ACTIVE_TEXTURE:
        return activeTexture + GL_TEXTURE0;
    default:
        return GL11.glGetInteger(a);
    }
}

From source file:vazkii.botania.client.core.handler.DebugHandler.java

License:Open Source License

@SubscribeEvent
public static void onDrawDebugText(RenderGameOverlayEvent.Text event) {
    World world = Minecraft.getMinecraft().theWorld;
    if (Minecraft.getMinecraft().gameSettings.showDebugInfo) {
        event.getLeft().add("");
        String version = LibMisc.VERSION;
        if (version.contains("GRADLE"))
            version = "N/A";

        event.getLeft().add(PREFIX + "pS: " + ParticleRenderDispatcher.sparkleFxCount + ", pFS: "
                + ParticleRenderDispatcher.fakeSparkleFxCount + ", pW: " + ParticleRenderDispatcher.wispFxCount
                + ", pDIW: " + ParticleRenderDispatcher.depthIgnoringWispFxCount + ", pLB: "
                + ParticleRenderDispatcher.lightningCount);
        event.getLeft()//from www. j a  v  a  2  s .c o  m
                .add(PREFIX + "(CLIENT) netColl: "
                        + ManaNetworkHandler.instance.getAllCollectorsInWorld(world).size() + ", netPool: "
                        + ManaNetworkHandler.instance.getAllPoolsInWorld(world).size() + ", rv: " + version);

        if (Minecraft.getMinecraft().isSingleplayer()) {
            UUID id = Minecraft.getMinecraft().thePlayer.getUniqueID();
            Entity ent = Minecraft.getMinecraft().getIntegratedServer().getEntityFromUuid(id);
            if (ent != null) {
                World serverWorld = Minecraft.getMinecraft().getIntegratedServer()
                        .getEntityFromUuid(id).worldObj;
                event.getLeft()
                        .add(PREFIX + String.format("(INTEGRATED SERVER DIM %d) netColl : %d, netPool: %d",
                                serverWorld.provider.getDimension(),
                                ManaNetworkHandler.instance.getAllCollectorsInWorld(serverWorld).size(),
                                ManaNetworkHandler.instance.getAllPoolsInWorld(serverWorld).size()));
            }
        }

        if (GuiScreen.isCtrlKeyDown() && GuiScreen.isShiftKeyDown()) {
            event.getLeft().add(PREFIX + "Config Context");
            event.getLeft().add("  shaders.enabled: " + ConfigHandler.useShaders);
            event.getLeft().add("  shaders.secondaryUnit: " + ConfigHandler.glSecondaryTextureUnit);

            ContextCapabilities caps = GLContext.getCapabilities();
            event.getLeft().add(PREFIX + "OpenGL Context");
            event.getLeft().add("  GL_VERSION: " + GL11.glGetString(GL11.GL_VERSION));
            event.getLeft().add("  GL_RENDERER: " + GL11.glGetString(GL11.GL_RENDERER));
            event.getLeft().add(
                    "  GL_SHADING_LANGUAGE_VERSION: " + GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
            event.getLeft().add("  GL_MAX_TEXTURE_IMAGE_UNITS_ARB: "
                    + GL11.glGetInteger(ARBFragmentShader.GL_MAX_TEXTURE_IMAGE_UNITS_ARB));
            event.getLeft().add("  GL_ARB_multitexture: " + caps.GL_ARB_multitexture);
            event.getLeft().add("  GL_ARB_texture_non_power_of_two: " + caps.GL_ARB_texture_non_power_of_two);
            event.getLeft().add("  OpenGL13: " + caps.OpenGL13);

            if (Minecraft.getMinecraft().objectMouseOver != null
                    && Minecraft.getMinecraft().objectMouseOver.getBlockPos() != null) {
                BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
                IBlockState state = world.getBlockState(pos);
                state = state.getActualState(world, pos);
                state = state.getBlock().getExtendedState(state, world, pos);
                if (state instanceof IExtendedBlockState) {
                    try {
                        for (Map.Entry<IUnlistedProperty<?>, Optional<?>> e : ((IExtendedBlockState) state)
                                .getUnlistedProperties().entrySet()) {
                            event.getRight().add(TextFormatting.LIGHT_PURPLE + e.getKey().getName() + ": "
                                    + TextFormatting.RESET + e.getValue().orNull());
                        }
                    } catch (Throwable t) {
                        event.getRight().add("Error getting extended state");
                    }
                }
            }
        } else if (Minecraft.IS_RUNNING_ON_MAC)
            event.getLeft().add(PREFIX + "SHIFT+CMD for context");
        else
            event.getLeft().add(PREFIX + "SHIFT+CTRL for context");
    }
}

From source file:vazkii.botania.client.gui.lexicon.button.GuiButtonCategory.java

License:Open Source License

@Override
public void drawButton(@Nonnull Minecraft mc, int mx, int my) {
    boolean inside = mx >= xPosition && my >= yPosition && mx < xPosition + width && my < yPosition + height;
    if (inside)/* w  w w. j av  a 2 s.c o  m*/
        ticksHovered = Math.min(time, ticksHovered + gui.timeDelta);
    else
        ticksHovered = Math.max(0F, ticksHovered - gui.timeDelta);

    if (resource == null) {
        if (category == null)
            resource = fallbackResource;
        else
            resource = category.getIcon();
        if (resource == null)
            resource = fallbackResource;
    }

    float s = 1F / 32F;

    GlStateManager.pushMatrix();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.scale(0.5F, 0.5F, 0.5F);
    GlStateManager.color(1F, 1F, 1F, 1F);

    if (!boundStencil) { // Allow for the texture manager to take care of the ResourceLocation before we use it directly with gl
        mc.renderEngine.bindTexture(stencilResource);
        boundStencil = true;
    }
    mc.renderEngine.bindTexture(resource);

    int texture = 0;
    boolean shaders = ShaderHelper.useShaders();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + ConfigHandler.glSecondaryTextureUnit);
        texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    }

    ShaderHelper.useShader(ShaderHelper.categoryButton, shaderCallback);
    RenderHelper.drawTexturedModalRect(xPosition * 2, yPosition * 2, zLevel * 2, 0, 0, 32, 32, s, s);
    ShaderHelper.releaseShader();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + ConfigHandler.glSecondaryTextureUnit);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB);
    }

    GlStateManager.popMatrix();

    if (inside)
        gui.categoryHighlight = I18n.format(getTooltipText());
}

From source file:vazkii.psi.client.core.handler.HUDHandler.java

@SideOnly(Side.CLIENT)
public void drawPsiBar(ScaledResolution res, float pticks) {
    Minecraft mc = Minecraft.getMinecraft();
    ItemStack cadStack = PsiAPI.getPlayerCAD(mc.thePlayer);

    if (cadStack == null)
        return;//from   ww w . ja va 2s. co m

    ICAD cad = (ICAD) cadStack.getItem();
    PlayerData data = PlayerDataHandler.get(mc.thePlayer);
    if (data.level == 0 && !mc.thePlayer.capabilities.isCreativeMode)
        return;

    GlStateManager.pushMatrix();
    int scaleFactor = res.getScaleFactor();

    if (scaleFactor > ConfigHandler.maxPsiBarScale) {
        int guiScale = mc.gameSettings.guiScale;

        mc.gameSettings.guiScale = ConfigHandler.maxPsiBarScale;
        res = new ScaledResolution(mc);
        mc.gameSettings.guiScale = guiScale;

        float s = (float) ConfigHandler.maxPsiBarScale / (float) scaleFactor;
        GlStateManager.scale(s, s, s);
    }

    boolean right = ConfigHandler.psiBarOnRight;

    int pad = 3;
    int width = 32;
    int height = 140;

    int x = -pad;
    if (right)
        x = res.getScaledWidth() + pad - width;
    int y = res.getScaledHeight() / 2 - height / 2;

    if (!registeredMask) {
        mc.renderEngine.bindTexture(psiBarMask);
        mc.renderEngine.bindTexture(psiBarShatter);
        registeredMask = true;
    }
    mc.renderEngine.bindTexture(psiBar);
    Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 0, width, height, 64, 256);

    x += 8;
    y += 26;

    width = 16;
    height = 106;

    float r = 0.6F;
    float g = 0.65F;
    float b = 1F;

    int origHeight = height;
    int origY = y;
    int v = 0;
    int max = data.getTotalPsi();

    int texture = 0;
    boolean shaders = ShaderHandler.useShaders();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);
        texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    }

    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    for (Deduction d : data.deductions) {
        float a = d.getPercentile(pticks);
        GlStateManager.color(r, g, b, a);
        height = (int) Math.ceil(origHeight * (double) d.deduct / max);
        int effHeight = (int) (origHeight * (double) d.current / max);
        v = origHeight - effHeight;
        y = origY + v;

        ShaderHandler.useShader(ShaderHandler.psiBar, generateCallback(a, d.shatter));
        Gui.drawModalRectWithCustomSizedTexture(x, y, 32, v, width, height, 64, 256);
    }

    float textY = origY;
    if (max > 0) {
        height = (int) ((double) origHeight * (double) data.availablePsi / max);
        v = origHeight - height;
        y = origY + v;

        if (data.availablePsi != data.lastAvailablePsi) {
            float textHeight = (float) (origHeight
                    * (data.availablePsi * pticks + data.lastAvailablePsi * (1.0 - pticks)) / max);
            textY = origY + (origHeight - textHeight);
        } else
            textY = y;
    } else
        height = 0;

    GlStateManager.color(r, g, b);
    ShaderHandler.useShader(ShaderHandler.psiBar, generateCallback(1F, false));
    Gui.drawModalRectWithCustomSizedTexture(x, y, 32, v, width, height, 64, 256);
    ShaderHandler.releaseShader();

    if (shaders) {
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB);
    }

    GlStateManager.color(1F, 1F, 1F);

    GlStateManager.pushMatrix();
    GlStateManager.translate(0F, textY, 0F);
    width = 44;
    height = 3;

    String s1 = "" + data.availablePsi;
    String s2 = "" + cad.getStoredPsi(cadStack);

    int offBar = 22;
    int offStr1 = 7 + mc.fontRendererObj.getStringWidth(s1);
    int offStr2 = 7 + mc.fontRendererObj.getStringWidth(s2);

    if (!right) {
        offBar = 6;
        offStr1 = -23;
        offStr2 = -23;
    }

    Color color = new Color(cad.getSpellColor(cadStack));
    GlStateManager.color(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F);

    Gui.drawModalRectWithCustomSizedTexture(x - offBar, -2, 0, 140, width, height, 64, 256);
    mc.fontRendererObj.drawStringWithShadow(s1, x - offStr1, -11, 0xFFFFFF);
    GlStateManager.popMatrix();

    GlStateManager.pushMatrix();
    GlStateManager.translate(0F, Math.max(textY + 3, origY + 100), 0F);
    mc.fontRendererObj.drawStringWithShadow(s2, x - offStr2, 0, 0xFFFFFF);
    GlStateManager.popMatrix();
    GlStateManager.popMatrix();
}

From source file:vazkii.psi.client.core.handler.HUDHandler.java

@SideOnly(Side.CLIENT)
private static Consumer<Integer> generateCallback(final float percentile, final boolean shatter) {
    Minecraft mc = Minecraft.getMinecraft();
    return (Integer shader) -> {
        int percentileUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "percentile");
        int imageUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "image");
        int maskUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "mask");

        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(psiBar).getGlTextureId());
        ARBShaderObjects.glUniform1iARB(imageUniform, 0);

        OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);

        GlStateManager.enableTexture2D();
        GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D,
                mc.renderEngine.getTexture(shatter ? psiBarShatter : psiBarMask).getGlTextureId());
        ARBShaderObjects.glUniform1iARB(maskUniform, secondaryTextureUnit);

        ARBShaderObjects.glUniform1fARB(percentileUniform, percentile);
    };//from   w w  w  .  j av  a  2s  . com
}

From source file:voxicity.ChunkNode.java

License:Open Source License

public void render(Frustum camera) {
    if (empty)/*from   w  w w  . j  a va 2s  .  c  o m*/
        return;

    AABB chunk_box = new AABB(Constants.Chunk.side_length, Constants.Chunk.side_length,
            Constants.Chunk.side_length);

    chunk_box.center_on(chunk.get_x() + chunk_box.dimensions().x, chunk.get_y() + chunk_box.dimensions().y,
            chunk.get_z() + chunk_box.dimensions().z);

    if (!camera.collides(chunk_box))
        return;

    Renderer.draw_calls++;

    if (shader_prog != 0)
        GL20.glUseProgram(shader_prog);

    // Bind VBO to vertex pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vert_buf);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);

    // Bind the texture coord VBO to texture pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tex_buf);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    int tex_bak = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

    for (Batch batch : batches) {
        // Bind the texture for this batch
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, batch.tex);

        // Bind index array
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, batch.indices);

        // Draw the block
        GL12.glDrawRangeElements(GL11.GL_QUADS, 0, Constants.Chunk.block_number * 24 - 1, batch.num_elements,
                GL11.GL_UNSIGNED_INT, 0);

        Renderer.batch_draw_calls++;
        Renderer.quads += batch.num_elements;
    }

    // Unbind the texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_bak);

    // Unbind all buffers
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    // Disable the shader once more
    if (shader_prog != 0)
        GL20.glUseProgram(0);
}

From source file:voxicity.TextureManager.java

License:Open Source License

public static int get_texture(String name) {
    if (name == null)
        return 0;

    if (textures.containsKey(name))
        return textures.get(name).getTextureID();

    try {/*from   w  w w  .  j  a  va 2s  .c  om*/
        Texture new_tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(name), true,
                GL11.GL_NEAREST);
        System.out.println("Loaded texture: " + new_tex);

        textures.put(name, new_tex);

        int tex_bak = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, new_tex.getTextureID());
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_bak);

        return new_tex.getTextureID();
    } catch (java.io.IOException e) {
        System.out.println("Failed to load texture " + name);
        e.printStackTrace();
        System.exit(0);
    }

    return 0;
}

From source file:voxicity.Voxicity.java

License:Open Source License

static void init(Arguments args) {
    // Load the specified config file
    Config config = new Config(args.get_value("config", "voxicity.properties"));

    String mode = args.get_value("mode", "client");

    if (mode.equals("server")) {
        // Start the server, it spawns its own thread
        // and takes over from here
        new Server(config).run();
    } else if (mode.equals("client")) {
        try {//  w w  w  .  ja  v a 2  s. c  om
            System.out.println("Intializing display");
            Display.setDisplayMode(new DisplayMode(1200, 720));
            Display.create();
            Display.setTitle("Voxicity");
            System.out.println("Display created");
        } catch (LWJGLException e) {
            System.out.println("Unable to open Display");
            e.printStackTrace();
            System.exit(1);
        }

        System.out.println("Setting up OpenGL states");
        GL11.glShadeModel(GL11.GL_SMOOTH);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glClearColor(126.0f / 255.0f, 169.0f / 255.0f, 254.0f / 255.0f, 1.0f);
        GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

        System.out.println("Number of texture units: " + GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS));
        System.out.println(
                "Number of image texture units: " + GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS));
        System.out.println(
                "Number of vertex texture units: " + GL11.glGetInteger(GL20.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS));
        System.out.println("Number of combined vertex/image texture units: "
                + GL11.glGetInteger(GL20.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS));

        try {
            LWJGLRenderer gui_renderer = new LWJGLRenderer();
            LoginGUI login_gui = new LoginGUI();
            ThemeManager theme = ThemeManager.createThemeManager(Voxicity.class.getResource("/login.xml"),
                    gui_renderer);
            GUI gui = new GUI(login_gui, gui_renderer);
            gui.applyTheme(theme);

            while (!login_gui.is_login_pressed()) {
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
                gui.update();
                Display.update();

                if (Display.isCloseRequested()) {
                    Display.destroy();
                    System.exit(0);
                }
            }

            Socket client_s = new Socket(login_gui.get_server_name(), 11000);
            Client client = new Client(config, new NetworkConnection(client_s));
            client.run();

            System.out.println("Destroying display");
            Display.destroy();
        }

        // Catch exceptions from the game init and main game-loop

        catch (LWJGLException e) {
            System.out.println(e);
            e.printStackTrace();
            System.exit(1);
        } catch (IOException e) {
            System.out.println(e);
            e.printStackTrace();
            System.exit(1);
        } catch (Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }
    } else {
        System.out.println("Invalid mode: " + mode);
    }
}