Search in sources :

Example 11 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project Wizardry by TeamWizardry.

the class FairyData method render.

@SideOnly(Side.CLIENT)
public void render(World world, Vec3d pos, Vec3d prevPos, float partialTicks) {
    if (!wasTamperedWith && !isDepressed) {
        LibParticles.FAIRY_HEAD(world, pos.add(0, 0.25, 0), primaryColor);
        ParticleBuilder glitter = new ParticleBuilder(age / 2);
        glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
        glitter.setAlphaFunction(new InterpFloatInOut(0.2f, 1f));
        if (RandUtil.nextInt(3) == 0)
            ParticleSpawner.spawn(glitter, world, new StaticInterp<>(pos), 1, 0, (i, build) -> {
                build.setMotion(new Vec3d(RandUtil.nextDouble(-0.01, 0.01), RandUtil.nextDouble(-0.01, 0.01), RandUtil.nextDouble(-0.01, 0.01)));
                if (RandUtil.nextBoolean())
                    build.setColor(primaryColor);
                else
                    build.setColor(secondaryColor);
                if (isDepressed) {
                    build.setCollision(true);
                    build.enableMotionCalculation();
                    build.setAcceleration(new Vec3d(0, -0.005, 0));
                }
            });
    } else {
        {
            GlStateManager.pushMatrix();
            EntityPlayer player = Minecraft.getMinecraft().player;
            if (player == null)
                return;
            double interpPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
            double interpPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
            double interpPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
            GlStateManager.translate(-interpPosX, -interpPosY, -interpPosZ);
            GlStateManager.translate(pos.x, pos.y, pos.z);
            Minecraft.getMinecraft().entityRenderer.disableLightmap();
            GlStateManager.enableDepth();
            GlStateManager.disableCull();
            GlStateManager.enableAlpha();
            GlStateManager.enableBlend();
            GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE);
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.color(1, 1, 1, 1);
            GlStateManager.disableTexture2D();
            GlStateManager.enableColorMaterial();
            GlStateManager.disableLighting();
            GlStateManager.shadeModel(GL11.GL_SMOOTH);
            int alphaFunc = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
            float alphaTest = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
            GlStateManager.alphaFunc(GL11.GL_ALWAYS, 1);
            GlStateManager.pushMatrix();
            GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate((float) (Minecraft.getMinecraft().getRenderManager().options.thirdPersonView == 2 ? -1 : 1) * Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder bb = tessellator.getBuffer();
            double radius = 0.1;
            Color color = primaryColor;
            bb.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);
            for (int i = 0; i <= 50; i++) {
                double x = radius * MathHelper.cos((float) ((i / 50.0) * Math.PI * 2));
                double z = radius * MathHelper.sin((float) ((i / 50.0) * Math.PI * 2));
                bb.pos(x, z, 0).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
            }
            tessellator.draw();
            GlStateManager.popMatrix();
            bb.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR);
            Vec3d sub = pos.subtract(prevPos).scale(-1).add(0, 0.2, 0).scale(3);
            Vec3d posCross = sub.crossProduct(new Vec3d(0, 1, 0)).normalize();
            Vec3d posPerp = posCross.crossProduct(sub).normalize().scale(radius - 0.2);
            Vec3d vec1 = posPerp;
            Vec3d vec2 = posPerp.scale(-1);
            bb.pos(sub.x, sub.y, sub.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
            bb.pos(vec1.x, vec1.y, vec1.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
            bb.pos(vec2.x, vec2.y, vec2.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
            Vec3d vec3 = posCross.scale(radius);
            Vec3d vec4 = posCross.scale(-1).scale(radius);
            bb.pos(sub.x, sub.y, sub.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
            bb.pos(vec3.x, vec3.y, vec3.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
            bb.pos(vec4.x, vec4.y, vec4.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
            tessellator.draw();
            GlStateManager.pushMatrix();
            GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate((float) (Minecraft.getMinecraft().getRenderManager().options.thirdPersonView == 2 ? -1 : 1) * Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
            int sections = 50;
            float epsilon = 2 * (float) Math.PI / sections;
            double innerRadius = radius;
            double outerRadius = radius + 0.01;
            Color inner = primaryColor;
            Color outer = new Color(primaryColor.getRed(), primaryColor.getGreen(), primaryColor.getBlue(), 0);
            bb.begin(GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_COLOR);
            for (int i = 0; i <= sections; i++) {
                float angle = i * epsilon;
                float nextAngle = (i + 1) * epsilon;
                float x1 = (float) (MathHelper.cos(angle) * innerRadius);
                float y1 = (float) (MathHelper.sin(angle) * innerRadius);
                float x2 = (float) (MathHelper.cos(nextAngle) * outerRadius);
                float y2 = (float) (MathHelper.sin(nextAngle) * outerRadius);
                bb.pos(x1, y1, 0).color(inner.getRed(), inner.getGreen(), inner.getBlue(), inner.getAlpha()).endVertex();
                bb.pos(x2, y2, 0).color(outer.getRed(), outer.getGreen(), outer.getBlue(), outer.getAlpha()).endVertex();
            }
            tessellator.draw();
            radius = 0.2;
            color = secondaryColor;
            GlStateManager.translate(0, 0, 0.01);
            bb.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);
            bb.pos(0, 0, 0).color(color.getRed(), color.getGreen(), color.getBlue(), 100).endVertex();
            for (int i = 0; i <= 50; i++) {
                double x = radius * MathHelper.cos((float) ((i / 50.0) * Math.PI * 2));
                double z = radius * MathHelper.sin((float) ((i / 50.0) * Math.PI * 2));
                bb.pos(x, z, 0).color(color.getRed(), color.getGreen(), color.getBlue(), 0).endVertex();
            }
            tessellator.draw();
            GlStateManager.translate(0, 0, -0.01);
            GlStateManager.alphaFunc(alphaFunc, alphaTest);
            GlStateManager.disableBlend();
            GlStateManager.enableAlpha();
            GlStateManager.enableTexture2D();
            GlStateManager.disableColorMaterial();
            Minecraft.getMinecraft().entityRenderer.enableLightmap();
            GlStateManager.enableDepth();
            GlStateManager.popMatrix();
            GlStateManager.popMatrix();
        }
    }
}
Also used : StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) CustomManaCapability(com.teamwizardry.wizardry.api.capability.player.mana.CustomManaCapability) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Constants(net.minecraftforge.common.util.Constants) GL_ONE(org.lwjgl.opengl.GL11.GL_ONE) ParticleSpawner(com.teamwizardry.librarianlib.features.particle.ParticleSpawner) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) ArrayList(java.util.ArrayList) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) NBTTagList(net.minecraft.nbt.NBTTagList) Vec3d(net.minecraft.util.math.Vec3d) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) ManaCapabilityProvider(com.teamwizardry.wizardry.api.capability.player.mana.ManaCapabilityProvider) GL11(org.lwjgl.opengl.GL11) InterpFloatInOut(com.teamwizardry.librarianlib.features.math.interpolate.numeric.InterpFloatInOut) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GL_SRC_ALPHA(org.lwjgl.opengl.GL11.GL_SRC_ALPHA) World(net.minecraft.world.World) GlStateManager(net.minecraft.client.renderer.GlStateManager) NBTBase(net.minecraft.nbt.NBTBase) Wizardry(com.teamwizardry.wizardry.Wizardry) EnumFacing(net.minecraft.util.EnumFacing) ColorUtils(com.teamwizardry.wizardry.api.util.ColorUtils) UUID(java.util.UUID) Capability(net.minecraftforge.common.capabilities.Capability) java.awt(java.awt) IManaCapability(com.teamwizardry.wizardry.api.capability.player.mana.IManaCapability) List(java.util.List) Tessellator(net.minecraft.client.renderer.Tessellator) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) NBTHelper(com.teamwizardry.librarianlib.features.helpers.NBTHelper) ResourceLocation(net.minecraft.util.ResourceLocation) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) NBTConstants(com.teamwizardry.wizardry.api.NBTConstants) NotNull(org.jetbrains.annotations.NotNull) INBTSerializable(net.minecraftforge.common.util.INBTSerializable) Tessellator(net.minecraft.client.renderer.Tessellator) InterpFloatInOut(com.teamwizardry.librarianlib.features.math.interpolate.numeric.InterpFloatInOut) ResourceLocation(net.minecraft.util.ResourceLocation) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 12 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project chunkstories by Hugobros3.

the class GLFWGameWindow method switchResolution.

private void switchResolution() {
    long mainMonitor = glfwGetPrimaryMonitor();
    GLFWVidMode currentVideoMode = glfwGetVideoMode(mainMonitor);
    boolean isFullscreenEnabled = client.getConfiguration() == null ? false : client.getConfiguration().getBooleanOption("client.video.fullScreen");
    if (isFullscreenEnabled) {
        // Enable fullscreen using desktop resolution, by default on the primary monitor and at it's nominal video mode
        String modeString = client.getConfiguration().getStringOption("client.video.fullScreenResolution");
        if (modeString == null || modeString.contains("x") || !modeString.contains(":")) {
            modeString = "1:" + currentVideoMode.width() + ":" + currentVideoMode.height() + ":" + currentVideoMode.refreshRate();
            client.getConfiguration().getOption("client.video.fullScreenResolution").trySetting(modeString);
        }
        DisplayMode videoMode = findMatchForVideoMode(modeString);
        glfwSetWindowMonitor(this.glfwWindowHandle, monitors[videoMode.monitorId - 1], 0, 0, videoMode.videoMode.width(), videoMode.videoMode.height(), videoMode.videoMode.refreshRate());
        windowWidth = videoMode.videoMode.width();
        windowHeight = videoMode.videoMode.height();
        glViewport(0, 0, windowWidth, windowHeight);
        if (layer != null)
            layer.onResize(windowWidth, windowHeight);
    } else {
        glfwSetWindowMonitor(this.glfwWindowHandle, MemoryUtil.NULL, (currentVideoMode.width() - defaultWidth) / 2, (currentVideoMode.height() - defaultHeight) / 2, defaultWidth, defaultHeight, GLFW_DONT_CARE);
        windowWidth = defaultWidth;
        windowHeight = defaultHeight;
        glViewport(0, 0, windowWidth, windowHeight);
        if (layer != null)
            layer.onResize(windowWidth, windowHeight);
    }
}
Also used : GL11.glGetString(org.lwjgl.opengl.GL11.glGetString) GLFWVidMode(org.lwjgl.glfw.GLFWVidMode)

Example 13 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project Nothirium by Meldexun.

the class RenderChunkTaskCompile method run.

@Override
public RenderChunkTaskResult run() {
    if (this.canceled()) {
        return RenderChunkTaskResult.CANCELLED;
    }
    RegionRenderCacheBuilder bufferBuilderPack;
    try {
        bufferBuilderPack = BUFFER_QUEUE.take();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return RenderChunkTaskResult.CANCELLED;
    }
    if (this.canceled()) {
        freeBuffer(bufferBuilderPack);
        return RenderChunkTaskResult.CANCELLED;
    }
    try {
        Minecraft mc = Minecraft.getMinecraft();
        MutableBlockPos pos = new MutableBlockPos();
        VisibilityGraph visibilityGraph = new VisibilityGraph();
        for (int x = 0; x < 16; x++) {
            for (int y = 0; y < 16; y++) {
                for (int z = 0; z < 16; z++) {
                    pos.setPos(this.renderChunk.getX() + x, this.renderChunk.getY() + y, this.renderChunk.getZ() + z);
                    IBlockState blockState = this.chunkCache.getBlockState(pos);
                    if (blockState.getRenderType() == EnumBlockRenderType.INVISIBLE) {
                        continue;
                    }
                    for (Direction dir : Direction.ALL) {
                        if (blockState.doesSideBlockRendering(chunkCache, pos, EnumFacingUtil.getFacing(dir)))
                            visibilityGraph.setOpaque(pos.getX(), pos.getY(), pos.getZ(), dir);
                    }
                    // I will just quote another mod here "This is a ridiculously hacky workaround, I would not recommend it to anyone."
                    blockState.getBlock().hasTileEntity(blockState);
                    for (BlockRenderLayer layer : BlockRenderLayerUtil.ALL) {
                        if (Nothirium.isBetterFoliageInstalled ? !BetterFoliage.canRenderBlockInLayer(blockState.getBlock(), blockState, layer) : !blockState.getBlock().canRenderInLayer(blockState, layer)) {
                            continue;
                        }
                        ForgeHooksClient.setRenderLayer(layer);
                        BufferBuilder bufferBuilder = bufferBuilderPack.getWorldRendererByLayer(layer);
                        if (!bufferBuilder.isDrawing) {
                            bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                            bufferBuilder.setTranslation(-this.renderChunk.getX(), -this.renderChunk.getY(), -this.renderChunk.getZ());
                        }
                        if (Nothirium.isBetterFoliageInstalled) {
                            BetterFoliage.renderWorldBlock(mc.getBlockRendererDispatcher(), blockState, pos, this.chunkCache, bufferBuilder, layer);
                        } else {
                            mc.getBlockRendererDispatcher().renderBlock(blockState, pos, this.chunkCache, bufferBuilder);
                        }
                        ForgeHooksClient.setRenderLayer(null);
                    }
                }
            }
            if (this.canceled()) {
                freeBuffer(bufferBuilderPack);
                return RenderChunkTaskResult.CANCELLED;
            }
        }
        VisibilitySet visibilitySet = visibilityGraph.compute();
        if (bufferBuilderPack.getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT).isDrawing) {
            BufferBuilder bufferBuilder = bufferBuilderPack.getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT);
            Entity entity = mc.getRenderViewEntity();
            double x = entity.posX - renderChunk.getX();
            double y = (entity.posY + entity.getEyeHeight()) - renderChunk.getY();
            double z = entity.posZ - renderChunk.getZ();
            // use translation to fix float inaccuracy
            bufferBuilder.setTranslation(x, y, z);
            bufferBuilder.sortVertexData(0.0F, 0.0F, 0.0F);
        }
        if (this.canceled()) {
            freeBuffer(bufferBuilderPack);
            return RenderChunkTaskResult.CANCELLED;
        }
        BufferBuilder[] finishedBufferBuilders = Arrays.stream(BlockRenderLayerUtil.ALL).map(bufferBuilderPack::getWorldRendererByLayer).map(bufferBuilder -> {
            if (!bufferBuilder.isDrawing) {
                return null;
            }
            bufferBuilder.finishDrawing();
            if (bufferBuilder.getVertexCount() == 0) {
                return null;
            }
            return bufferBuilder;
        }).toArray(BufferBuilder[]::new);
        if (this.canceled()) {
            freeBuffer(bufferBuilderPack);
            return RenderChunkTaskResult.CANCELLED;
        }
        this.taskDispatcher.runOnRenderThread(() -> {
            try {
                if (!this.canceled()) {
                    this.renderChunk.setVisibility(visibilitySet);
                    for (ChunkRenderPass pass : ChunkRenderPass.ALL) {
                        BufferBuilder bufferBuilder = finishedBufferBuilders[pass.ordinal()];
                        if (bufferBuilder == null) {
                            this.renderChunk.setVBOPart(pass, null);
                        } else {
                            this.renderChunk.setVBOPart(pass, this.chunkRenderer.buffer(pass, bufferBuilder.getByteBuffer()));
                        }
                    }
                }
            } finally {
                freeBuffer(bufferBuilderPack);
            }
        });
        return RenderChunkTaskResult.SUCCESSFUL;
    } catch (Throwable e) {
        freeBuffer(bufferBuilderPack);
        throw e;
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) RegionRenderCacheBuilder(net.minecraft.client.renderer.RegionRenderCacheBuilder) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) VisibilityGraph(meldexun.nothirium.util.VisibilityGraph) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) IChunkRenderer(meldexun.nothirium.api.renderer.chunk.IChunkRenderer) Minecraft(net.minecraft.client.Minecraft) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) GL11(org.lwjgl.opengl.GL11) Direction(meldexun.nothirium.util.Direction) AbstractRenderChunkTask(meldexun.nothirium.renderer.chunk.AbstractRenderChunkTask) IBlockAccess(net.minecraft.world.IBlockAccess) Entity(net.minecraft.entity.Entity) RenderChunkTaskResult(meldexun.nothirium.api.renderer.chunk.RenderChunkTaskResult) Nothirium(meldexun.nothirium.mc.Nothirium) BetterFoliage(meldexun.nothirium.mc.integration.BetterFoliage) BlockingQueue(java.util.concurrent.BlockingQueue) ChunkRenderPass(meldexun.nothirium.api.renderer.chunk.ChunkRenderPass) IRenderChunkDispatcher(meldexun.nothirium.api.renderer.chunk.IRenderChunkDispatcher) BlockRenderLayerUtil(meldexun.nothirium.mc.util.BlockRenderLayerUtil) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBlockState(net.minecraft.block.state.IBlockState) VisibilitySet(meldexun.nothirium.util.VisibilitySet) EnumFacingUtil(meldexun.nothirium.mc.util.EnumFacingUtil) EnumBlockRenderType(net.minecraft.util.EnumBlockRenderType) ForgeHooksClient(net.minecraftforge.client.ForgeHooksClient) Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) VisibilitySet(meldexun.nothirium.util.VisibilitySet) ChunkRenderPass(meldexun.nothirium.api.renderer.chunk.ChunkRenderPass) RegionRenderCacheBuilder(net.minecraft.client.renderer.RegionRenderCacheBuilder) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) VisibilityGraph(meldexun.nothirium.util.VisibilityGraph) Minecraft(net.minecraft.client.Minecraft) Direction(meldexun.nothirium.util.Direction) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos)

Example 14 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project Terasology by MovingBlocks.

the class GLFWSplashScreen method run.

@Override
public void run() {
    if (!GLFW.glfwInit()) {
        throw new RuntimeException("Cannot init GLFW!");
    }
    int width = 800;
    int height = 289;
    window = new Window(width, height, "", false);
    pixel = new Texture();
    ByteBuffer bytes = BufferUtils.createByteBuffer(4);
    bytes.put((byte) -1).put((byte) -1).put((byte) -1).put((byte) -1);
    bytes.flip();
    pixel.bind();
    pixel.uploadData(1, 1, bytes);
    try {
        widgets.add(new Image(GLFWSplashScreen.class.getResource("/splash/splash.png"), 0, 0));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_1.png"), 0, 0, TerasologyEngineStatus.PREPARING_SUBSYSTEMS.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_2.png"), 150, 0, TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_3.png"), 300, 0, TerasologyEngineStatus.INITIALIZING_ASSET_TYPES.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_4.png"), 450, 0, TerasologyEngineStatus.INITIALIZING_SUBSYSTEMS.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_5.png"), 630, 0, TerasologyEngineStatus.INITIALIZING_ASSET_MANAGEMENT.getDescription()));
        widgets.add(new Image(GLFWSplashScreen.class.getResource("/splash/splash_text.png"), 0, 0));
        widgets.add(new BorderedRectangle(pixel, 20, 20, 600, 30));
        widgets.add(new AnimatedBoxRow(pixel, 20 + 450 + 10, 20, 600 - 450 - 20, 30));
    } catch (IOException e) {
        throw new RuntimeException("Cannot load splash image resources");
    }
    Renderer renderer = new Renderer();
    renderer.init();
    countDownLatch.countDown();
    GL11.glClearColor(0f, 0f, 0f, 0f);
    double last = GLFW.glfwGetTime();
    try {
        while (!isClosing && !window.isClosing()) {
            double dTime = GLFW.glfwGetTime() - last;
            last = GLFW.glfwGetTime();
            renderer.clear();
            widgets.forEach(widget -> widget.update(dTime));
            widgets.forEach(i -> i.render(renderer));
            renderer.drawText(message, 30, 25, Color.BLACK);
            window.update();
        }
    } finally {
        widgets.stream().filter(w -> w instanceof Image).map(w -> (Image) w).forEach(Image::delete);
        pixel.delete();
        renderer.dispose();
        window.destroy();
    }
}
Also used : Window(org.terasology.splash.glfw.graphics.Window) ActivatableImage(org.terasology.splash.glfw.widgets.ActivatableImage) Image(org.terasology.splash.glfw.widgets.Image) Renderer(org.terasology.splash.glfw.graphics.Renderer) IOException(java.io.IOException) TerasologyEngineStatus(org.terasology.engine.core.TerasologyEngineStatus) GLFW(org.lwjgl.glfw.GLFW) Widget(org.terasology.splash.glfw.widgets.Widget) ByteBuffer(java.nio.ByteBuffer) BufferUtils(org.lwjgl.BufferUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Window(org.terasology.splash.glfw.graphics.Window) AnimatedBoxRow(org.terasology.splash.glfw.widgets.AnimatedBoxRow) BorderedRectangle(org.terasology.splash.glfw.widgets.BorderedRectangle) GL11(org.lwjgl.opengl.GL11) Texture(org.terasology.splash.glfw.graphics.Texture) LinkedList(java.util.LinkedList) SplashScreen(org.terasology.splash.SplashScreen) Color(org.terasology.splash.glfw.graphics.Color) BorderedRectangle(org.terasology.splash.glfw.widgets.BorderedRectangle) ActivatableImage(org.terasology.splash.glfw.widgets.ActivatableImage) IOException(java.io.IOException) ActivatableImage(org.terasology.splash.glfw.widgets.ActivatableImage) Image(org.terasology.splash.glfw.widgets.Image) Texture(org.terasology.splash.glfw.graphics.Texture) ByteBuffer(java.nio.ByteBuffer) Renderer(org.terasology.splash.glfw.graphics.Renderer) AnimatedBoxRow(org.terasology.splash.glfw.widgets.AnimatedBoxRow)

Example 15 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project runelite by runelite.

the class ModelViewer method main.

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(null, "npcdir", true, "npc directory");
    options.addOption(null, "mapdir", true, "maps directory");
    options.addOption(null, "objectdir", true, "objects directory");
    options.addOption(null, "npc", true, "npc to render");
    options.addOption(null, "object", true, "object to render");
    options.addOption(null, "model", true, "model to render");
    options.addOption(null, "map", true, "map region to render");
    options.addOption(null, "kits", true, "kits to render");
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);
    String npcdir = cmd.getOptionValue("npcdir");
    String mapdir = cmd.getOptionValue("mapdir");
    String objectdir = cmd.getOptionValue("objectdir");
    NpcDefinition npcdef = null;
    ObjectDefinition objdef = null;
    List<ModelDefinition> models = new ArrayList<>();
    Region region = null;
    if (cmd.hasOption("model")) {
        // render model
        String model = cmd.getOptionValue("model");
        ModelDefinition md = ModelManager.getModel(Integer.parseInt(model), null, null);
        models.add(md);
    }
    if (cmd.hasOption("npc")) {
        String npc = cmd.getOptionValue("npc");
        try (FileInputStream fin = new FileInputStream(npcdir + "/" + npc + ".json")) {
            npcdef = new Gson().fromJson(new InputStreamReader(fin), NpcDefinition.class);
        }
        for (int model : npcdef.models) {
            ModelDefinition md = ModelManager.getModel(model, null, null);
            models.add(md);
        }
    }
    if (cmd.hasOption("object")) {
        String obj = cmd.getOptionValue("object");
        try (FileInputStream fin = new FileInputStream(objectdir + "/" + obj + ".json")) {
            objdef = new Gson().fromJson(new InputStreamReader(fin), ObjectDefinition.class);
        }
        for (int model : objdef.getObjectModels()) {
            ModelDefinition md = ModelManager.getModel(model, null, null);
            models.add(md);
        }
    }
    if (cmd.hasOption("map")) {
        String map = cmd.getOptionValue("map");
        String[] s = map.split(",");
        int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]);
        region = new Region(x, y);
        MapLoader mapLoader = new MapLoader();
        LocationsLoader locationsLoader = new LocationsLoader();
        try (FileInputStream fin = new FileInputStream(mapdir + "/m" + x + "_" + y + ".dat")) {
            byte[] b = IOUtils.toByteArray(fin);
            MapDefinition mapDef = mapLoader.load(x, y, b);
            region.loadTerrain(mapDef);
        }
        try (FileInputStream fin = new FileInputStream(mapdir + "/l" + x + "_" + y + ".dat")) {
            byte[] b = IOUtils.toByteArray(fin);
            LocationsDefinition locDef = locationsLoader.load(x, y, b);
            region.loadLocations(locDef);
        } catch (FileNotFoundException ex) {
            logger.info("No landscape file for {},{}", x, y);
        }
        loadUnderlays();
        loadOverlays();
    }
    if (cmd.hasOption("kits")) {
        String kits = cmd.getOptionValue("kits");
        Integer[] kitIds = Arrays.stream(kits.split(",")).map(s -> Integer.parseInt(s)).toArray(Integer[]::new);
        for (int kitId : kitIds) {
            KitDefinition kit = KitManager.getKit(kitId);
            for (int model : kit.modelIds) {
                ModelDefinition md = ModelManager.getModel(model, null, null);
                models.add(md);
            }
        }
    }
    Display.setDisplayMode(new DisplayMode(800, 600));
    Display.setTitle("Model Viewer");
    Display.setInitialBackground((float) Color.gray.getRed() / 255f, (float) Color.gray.getGreen() / 255f, (float) Color.gray.getBlue() / 255f);
    Display.create();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    double aspect = 1;
    // near should be chosen as far into the scene as possible
    double near = 1;
    double far = 10000;
    // 1 gives you a 90° field of view. It's tan(fov_angle)/2.
    double fov = 1;
    GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far);
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glCullFace(GL11.GL_BACK);
    GL11.glEnable(GL11.GL_CULL_FACE);
    long last = 0;
    Camera camera = new Camera();
    while (!Display.isCloseRequested()) {
        // Clear the screen and depth buffer
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        for (ModelDefinition def : models) {
            short[] recolourToFind = null, recolourToReplace = null;
            if (npcdef != null) {
                recolourToFind = npcdef.recolorToFind;
                recolourToReplace = npcdef.recolorToReplace;
            }
            if (objdef != null) {
                recolourToFind = objdef.getRecolorToFind();
                recolourToReplace = objdef.getRecolorToReplace();
            }
            drawModel(def, recolourToFind, recolourToReplace);
        }
        drawRegion(region);
        Display.update();
        // fps
        Display.sync(50);
        long delta = System.currentTimeMillis() - last;
        last = System.currentTimeMillis();
        camera.acceptInput(delta);
        camera.apply();
    }
    Display.destroy();
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) Location(net.runelite.cache.region.Location) Options(org.apache.commons.cli.Options) GL_TEXTURE_WRAP_T(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T) LoggerFactory(org.slf4j.LoggerFactory) GL_TEXTURE_WRAP_S(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S) HashMap(java.util.HashMap) Vector3f(net.runelite.cache.models.Vector3f) GL_NEAREST(org.lwjgl.opengl.GL11.GL_NEAREST) GL_TEXTURE_2D(org.lwjgl.opengl.GL11.GL_TEXTURE_2D) ByteBuffer(java.nio.ByteBuffer) Position(net.runelite.cache.region.Position) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) Gson(com.google.gson.Gson) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) CommandLine(org.apache.commons.cli.CommandLine) Region(net.runelite.cache.region.Region) OverlayDefinition(net.runelite.cache.definitions.OverlayDefinition) GL11(org.lwjgl.opengl.GL11) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) VertexNormal(net.runelite.cache.models.VertexNormal) Display(org.lwjgl.opengl.Display) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) CommandLineParser(org.apache.commons.cli.CommandLineParser) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition) GL_TEXTURE_MIN_FILTER(org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER) LocationsLoader(net.runelite.cache.definitions.loaders.LocationsLoader) IOUtils(org.apache.commons.compress.utils.IOUtils) IOException(java.io.IOException) LocationsDefinition(net.runelite.cache.definitions.LocationsDefinition) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) MapDefinition(net.runelite.cache.definitions.MapDefinition) List(java.util.List) KitDefinition(net.runelite.cache.definitions.KitDefinition) DisplayMode(org.lwjgl.opengl.DisplayMode) GL_TEXTURE_MAG_FILTER(org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) GL_CLAMP_TO_EDGE(org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE) GL11.glTexParameteri(org.lwjgl.opengl.GL11.glTexParameteri) MapLoader(net.runelite.cache.definitions.loaders.MapLoader) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) Options(org.apache.commons.cli.Options) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) MapDefinition(net.runelite.cache.definitions.MapDefinition) KitDefinition(net.runelite.cache.definitions.KitDefinition) CommandLineParser(org.apache.commons.cli.CommandLineParser) LocationsDefinition(net.runelite.cache.definitions.LocationsDefinition) DefaultParser(org.apache.commons.cli.DefaultParser) InputStreamReader(java.io.InputStreamReader) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) LocationsLoader(net.runelite.cache.definitions.loaders.LocationsLoader) FileInputStream(java.io.FileInputStream) DisplayMode(org.lwjgl.opengl.DisplayMode) CommandLine(org.apache.commons.cli.CommandLine) MapLoader(net.runelite.cache.definitions.loaders.MapLoader) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) Region(net.runelite.cache.region.Region)

Aggregations

GL11 (org.lwjgl.opengl.GL11)19 List (java.util.List)10 Minecraft (net.minecraft.client.Minecraft)8 DefaultVertexFormats (net.minecraft.client.renderer.vertex.DefaultVertexFormats)8 IOException (java.io.IOException)7 GlStateManager (net.minecraft.client.renderer.GlStateManager)7 GLFW (org.lwjgl.glfw.GLFW)7 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)6 Tessellator (net.minecraft.client.renderer.Tessellator)6 Vector2i (org.joml.Vector2i)6 GL (org.lwjgl.opengl.GL)6 Frame (com.spinyowl.legui.component.Frame)5 EventProcessorProvider (com.spinyowl.legui.listener.processor.EventProcessorProvider)5 CallbackKeeper (com.spinyowl.legui.system.context.CallbackKeeper)5 Context (com.spinyowl.legui.system.context.Context)5 DefaultCallbackKeeper (com.spinyowl.legui.system.context.DefaultCallbackKeeper)5 SystemEventProcessor (com.spinyowl.legui.system.handler.processor.SystemEventProcessor)5 SystemEventProcessorImpl (com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl)5 LayoutManager (com.spinyowl.legui.system.layout.LayoutManager)5 Renderer (com.spinyowl.legui.system.renderer.Renderer)5