Search in sources :

Example 1 with GL_ONE_MINUS_SRC_ALPHA

use of org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA in project LogisticsPipes by RS485.

the class RenderTickHandler method renderWorldLast.

// private static final ResourceLocation TEXTURE = new ResourceLocation("logisticspipes", "textures/blocks/pipes/White.png");
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void renderWorldLast(RenderWorldLastEvent worldEvent) {
    // if (LogisticsRenderPipe.config.isUseNewRenderer()) {
    if (displayPipeGhost()) {
        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayer player = mc.player;
        RayTraceResult box = mc.objectMouseOver;
        if (box != null && box.typeOfHit == RayTraceResult.Type.BLOCK) {
            ItemStack stack = FMLClientHandler.instance().getClient().player.inventory.mainInventory.get(FMLClientHandler.instance().getClient().player.inventory.currentItem);
            CoreUnroutedPipe pipe = ((ItemLogisticsPipe) stack.getItem()).getDummyPipe();
            World world = player.getEntityWorld();
            EnumFacing side = box.sideHit;
            BlockPos bPos = box.getBlockPos();
            Block block = world.getBlockState(bPos).getBlock();
            if (block == Blocks.SNOW_LAYER && block.isReplaceable(world, bPos)) {
                side = EnumFacing.UP;
            } else if (!block.isReplaceable(world, bPos)) {
                bPos = bPos.offset(side);
            }
            boolean isFreeSpace = true;
            ITubeOrientation orientation = null;
            if (pipe instanceof CoreMultiBlockPipe) {
                CoreMultiBlockPipe multipipe = (CoreMultiBlockPipe) pipe;
                DoubleCoordinates placeAt = new DoubleCoordinates(bPos);
                LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> globalPos = new LPPositionSet<>(DoubleCoordinatesType.class);
                globalPos.add(new DoubleCoordinatesType<>(placeAt, CoreMultiBlockPipe.SubBlockTypeForShare.NON_SHARE));
                LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> positions = multipipe.getSubBlocks();
                orientation = multipipe.getTubeOrientation(player, bPos.getX(), bPos.getZ());
                if (orientation != null) {
                    orientation.rotatePositions(positions);
                    positions.stream().map(pos -> pos.add(placeAt)).forEach(globalPos::add);
                    globalPos.addToAll(orientation.getOffset());
                    for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> pos : globalPos) {
                        if (!player.getEntityWorld().mayPlace(LPBlocks.pipe, pos.getBlockPos(), false, side, player)) {
                            TileEntity tile = player.getEntityWorld().getTileEntity(pos.getBlockPos());
                            boolean canPlace = false;
                            if (tile instanceof LogisticsTileGenericSubMultiBlock) {
                                if (CoreMultiBlockPipe.canShare(((LogisticsTileGenericSubMultiBlock) tile).getSubTypes(), pos.getType())) {
                                    canPlace = true;
                                }
                            }
                            if (!canPlace) {
                                isFreeSpace = false;
                                break;
                            }
                        }
                    }
                } else {
                    return;
                }
            } else {
                if (!player.getEntityWorld().mayPlace(LPBlocks.pipe, bPos, false, side, player)) {
                    isFreeSpace = false;
                }
            }
            if (isFreeSpace) {
                GlStateManager.pushMatrix();
                double x;
                double y;
                double z;
                if (orientation != null) {
                    x = bPos.getX() + orientation.getOffset().getXInt() - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.getPartialTicks());
                    y = bPos.getY() + orientation.getOffset().getYInt() - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.getPartialTicks());
                    z = bPos.getZ() + orientation.getOffset().getZInt() - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.getPartialTicks());
                } else {
                    x = bPos.getX() - player.prevPosX - ((player.posX - player.prevPosX) * worldEvent.getPartialTicks());
                    y = bPos.getY() - player.prevPosY - ((player.posY - player.prevPosY) * worldEvent.getPartialTicks());
                    z = bPos.getZ() - player.prevPosZ - ((player.posZ - player.prevPosZ) * worldEvent.getPartialTicks());
                }
                GL11.glTranslated(x + 0.001, y + 0.001, z + 0.001);
                GlStateManager.enableBlend();
                // GL11.glDepthMask(false);
                GlStateManager.disableTexture2D();
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                mc.renderEngine.bindTexture(new ResourceLocation("logisticspipes", "textures/blocks/pipes/white.png"));
                SimpleServiceLocator.cclProxy.getRenderState().reset();
                SimpleServiceLocator.cclProxy.getRenderState().setAlphaOverride(0xff);
                GlStateManager.enableTexture2D();
                SimpleServiceLocator.cclProxy.getRenderState().setAlphaOverride(0x50);
                SimpleServiceLocator.cclProxy.getRenderState().startDrawing(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                pipe.getHighlightRenderer().renderHighlight(orientation);
                SimpleServiceLocator.cclProxy.getRenderState().draw();
                SimpleServiceLocator.cclProxy.getRenderState().setAlphaOverride(0xff);
                GlStateManager.disableBlend();
                GlStateManager.depthMask(true);
                GlStateManager.popMatrix();
            }
        }
    }
// }
}
Also used : ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) RenderTickEvent(net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent) Blocks(net.minecraft.init.Blocks) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) ActiveRenderInfo(net.minecraft.client.renderer.ActiveRenderInfo) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) ClientViewController(logisticspipes.routing.debug.ClientViewController) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) GL11(org.lwjgl.opengl.GL11) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) World(net.minecraft.world.World) GlStateManager(net.minecraft.client.renderer.GlStateManager) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) EventPriority(net.minecraftforge.fml.common.eventhandler.EventPriority) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) LPBlocks(logisticspipes.LPBlocks) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Phase(net.minecraftforge.fml.common.gameevent.TickEvent.Phase) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) ResourceLocation(net.minecraft.util.ResourceLocation) ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) BlockPos(net.minecraft.util.math.BlockPos) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) RayTraceResult(net.minecraft.util.math.RayTraceResult) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Minecraft(net.minecraft.client.Minecraft) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) LPPositionSet(logisticspipes.utils.LPPositionSet) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with GL_ONE_MINUS_SRC_ALPHA

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

the class GLFWGameWindow method displaySplashScreen.

@SuppressWarnings("unused")
private void displaySplashScreen() throws IOException {
    int texture = glGenTextures();
    InputStream is = getClass().getResourceAsStream("/splash.png");
    PNGDecoder decoder = new PNGDecoder(is);
    int width = decoder.getWidth();
    int height = decoder.getHeight();
    ByteBuffer temp = ByteBuffer.allocateDirect(4 * width * height);
    decoder.decode(temp, width * 4, Format.RGBA);
    is.close();
    // ChunkStoriesLogger.getInstance().log("decoded " + width + " by " + height + " pixels (" + name + ")", ChunkStoriesLogger.LogType.RENDERING, ChunkStoriesLogger.LogLevel.DEBUG);
    temp.flip();
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer) temp);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    int shaderProgramId = glCreateProgram();
    int vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
    int fragShaderId = glCreateShader(GL_FRAGMENT_SHADER);
    String vertexSource = "#version 330\n\n\nin vec3 vertexIn;\nout vec2 texCoord;\nuniform float ratio;\n\nvoid main()\n{\ngl_Position = vec4(vertexIn.x*ratio, vertexIn.y, 0.0, 1.0);\ntexCoord = vertexIn.xy*0.5+0.5;\n}";
    String fragSource = "#version 330\nuniform sampler2D diffuseTexture;\n\nin vec2 texCoord;\nout vec4 fragColor;\n\nvoid main()\n{\nfragColor = texture(diffuseTexture, vec2(texCoord.x, 1.0-texCoord.y));\n}\n";
    // System.out.println(vertexSource);
    // System.out.println(fragSource);
    glShaderSource(vertexShaderId, vertexSource);
    glCompileShader(vertexShaderId);
    glBindFragDataLocation(shaderProgramId, 0, "fragColor");
    glShaderSource(fragShaderId, fragSource);
    glCompileShader(fragShaderId);
    glAttachShader(shaderProgramId, vertexShaderId);
    glAttachShader(shaderProgramId, fragShaderId);
    glLinkProgram(shaderProgramId);
    glUseProgram(shaderProgramId);
    int uniformLocation = glGetUniformLocation(shaderProgramId, "diffuseTexture");
    // glUniform2f(uniformLocation, ((Vector2fc)uniformData).x(), ((Vector2fc)uniformData).y());
    glUniform1i(uniformLocation, (Integer) 0);
    float ratio = (float) windowHeight / windowWidth;
    uniformLocation = glGetUniformLocation(shaderProgramId, "ratio");
    glUniform1f(uniformLocation, ratio);
    glValidateProgram(shaderProgramId);
    FloatBuffer fsQuadBuffer = BufferUtils.createFloatBuffer(6 * 2);
    fsQuadBuffer.put(new float[] { 1f, 1f, -1f, -1f, 1f, -1f, 1f, 1f, -1f, 1f, -1f, -1f });
    fsQuadBuffer.flip();
    int vertexBuffer = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, (FloatBuffer) fsQuadBuffer, GL_STATIC_DRAW);
    int location = glGetAttribLocation(shaderProgramId, "vertexIn");
    glEnableVertexAttribArray(location);
    glVertexAttribPointer(location, 2, GL_FLOAT, false, 0, 0L);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    // while(1 - Math.floor(1) == 0 && !glfwWindowShouldClose(glfwWindowHandle))
    {
        glClearColor(0.25f, 0.25f, 0.25f, 1f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // Draw happens here
        glDrawArrays(GL_TRIANGLES, 0, 6);
        glfwSwapBuffers(glfwWindowHandle);
        glfwPollEvents();
    }
    glDisable(GL_BLEND);
    glDisableVertexAttribArray(location);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDeleteBuffers(vertexBuffer);
    glBindTexture(GL_TEXTURE_2D, 0);
    glDeleteTextures(texture);
    glUseProgram(0);
    glDeleteProgram(shaderProgramId);
    glDeleteShader(vertexShaderId);
    glDeleteShader(fragShaderId);
    glClearColor(0.0f, 0.0f, 0.0f, 1f);
}
Also used : PNGDecoder(de.matthiasmann.twl.utils.PNGDecoder) InputStream(java.io.InputStream) FloatBuffer(java.nio.FloatBuffer) GL11.glGetString(org.lwjgl.opengl.GL11.glGetString) ByteBuffer(java.nio.ByteBuffer) GLFW.glfwWindowHint(org.lwjgl.glfw.GLFW.glfwWindowHint)

Aggregations

PNGDecoder (de.matthiasmann.twl.utils.PNGDecoder)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 FloatBuffer (java.nio.FloatBuffer)1 LPBlocks (logisticspipes.LPBlocks)1 ITubeOrientation (logisticspipes.interfaces.ITubeOrientation)1 ItemLogisticsPipe (logisticspipes.items.ItemLogisticsPipe)1 CoreMultiBlockPipe (logisticspipes.pipes.basic.CoreMultiBlockPipe)1 CoreUnroutedPipe (logisticspipes.pipes.basic.CoreUnroutedPipe)1 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)1 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)1 LogisticsGuiOverrenderer (logisticspipes.renderer.LogisticsGuiOverrenderer)1 LogisticsHUDRenderer (logisticspipes.renderer.LogisticsHUDRenderer)1 ClientViewController (logisticspipes.routing.debug.ClientViewController)1 LPPositionSet (logisticspipes.utils.LPPositionSet)1 Block (net.minecraft.block.Block)1 Minecraft (net.minecraft.client.Minecraft)1 ActiveRenderInfo (net.minecraft.client.renderer.ActiveRenderInfo)1 GlStateManager (net.minecraft.client.renderer.GlStateManager)1 DefaultVertexFormats (net.minecraft.client.renderer.vertex.DefaultVertexFormats)1