Search in sources :

Example 16 with GL11.glViewport

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

the class GuiZonePlanner method drawForegroundLayer.

@SuppressWarnings("PointlessBitwiseExpression")
@Override
protected void drawForegroundLayer() {
    camY += scaleSpeed;
    scaleSpeed *= 0.7F;
    int posX = (int) positionX;
    int posZ = (int) positionZ;
    int dimension = mc.world.provider.getDimension();
    {
        ChunkPos chunkPos = new ChunkPos(posX >> 4, posZ >> 4);
        ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
        BlockPos pos = null;
        if (zonePlannerMapChunk != null) {
            MapColourData data = zonePlannerMapChunk.getData(posX, posZ);
            if (data != null) {
                pos = new BlockPos(posX, data.posY, posZ);
            }
        }
        if (pos != null && pos.getY() + 10 > camY) {
            camY = Math.max(camY, pos.getY() + 10);
        }
    }
    int x = guiLeft;
    int y = guiTop;
    if (lastSelected != null) {
        String text = "X: " + lastSelected.getX() + " Y: " + lastSelected.getY() + " Z: " + lastSelected.getZ();
        fontRenderer.drawString(text, x + 130, y + 130, 0x404040);
    }
    int offsetX = 8;
    int offsetY = 9;
    int sizeX = 213;
    int sizeY = 100;
    GlStateManager.pushMatrix();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();
    ScaledResolution scaledResolution = new ScaledResolution(mc);
    int viewportX = (x + offsetX) * scaledResolution.getScaleFactor();
    int viewportY = mc.displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor();
    int viewportWidth = sizeX * scaledResolution.getScaleFactor();
    int viewportHeight = sizeY * scaledResolution.getScaleFactor();
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glScissor(viewportX, viewportY, viewportWidth, viewportHeight);
    GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    GlStateManager.viewport(viewportX, viewportY, viewportWidth, viewportHeight);
    GlStateManager.scale(scaledResolution.getScaleFactor(), scaledResolution.getScaleFactor(), 1);
    GLU.gluPerspective(70.0F, (float) sizeX / sizeY, 1F, 10000.0F);
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.loadIdentity();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.enableRescaleNormal();
    // look down
    GlStateManager.rotate(90, 1, 0, 0);
    GlStateManager.pushMatrix();
    GlStateManager.translate(-positionX, -camY, -positionZ);
    GlStateManager.disableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.disableTexture2D();
    int minScreenX = (x + offsetX) * scaledResolution.getScaleFactor();
    int minScreenY = (scaledResolution.getScaledHeight() - (y + offsetY)) * scaledResolution.getScaleFactor();
    int maxScreenX = (x + offsetX + sizeX) * scaledResolution.getScaleFactor();
    int maxScreenY = (scaledResolution.getScaledHeight() - (y + offsetY + sizeY)) * scaledResolution.getScaleFactor();
    int minChunkX = (posX >> 4) - 8;
    int minChunkZ = (posZ >> 4) - 8;
    int maxChunkX = (posX >> 4) + 8;
    int maxChunkZ = (posZ >> 4) + 8;
    // noinspection SuspiciousNameCombination
    List<ChunkPos> chunkPosBounds = Stream.of(Pair.of(minScreenX, minScreenY), Pair.of(minScreenX, maxScreenY), Pair.of(maxScreenX, minScreenY), Pair.of(maxScreenX, maxScreenY)).map(p -> rayTrace(p.getLeft(), p.getRight())).filter(Objects::nonNull).map(ChunkPos::new).collect(Collectors.toList());
    for (ChunkPos chunkPos : chunkPosBounds) {
        if (chunkPos.x < minChunkX) {
            minChunkX = chunkPos.x;
        }
        if (chunkPos.z < minChunkZ) {
            minChunkZ = chunkPos.z;
        }
        if (chunkPos.x > maxChunkX) {
            maxChunkX = chunkPos.x;
        }
        if (chunkPos.z > maxChunkZ) {
            maxChunkZ = chunkPos.z;
        }
    }
    minChunkX--;
    minChunkZ--;
    maxChunkX++;
    maxChunkZ++;
    for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
        for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
            ZonePlannerMapRenderer.INSTANCE.getChunkGlList(new ZonePlannerMapChunkKey(new ChunkPos(chunkX, chunkZ), dimension, container.tile.getLevel())).ifPresent(GlStateManager::callList);
        }
    }
    BlockPos found = null;
    int foundColor = 0;
    if (Mouse.getX() >= minScreenX && Mouse.getY() <= minScreenY && Mouse.getX() <= maxScreenX && Mouse.getY() >= maxScreenY) {
        found = rayTrace(Mouse.getX(), Mouse.getY());
    }
    if (found != null) {
        ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(new ChunkPos(found), mc.world.provider.getDimension(), container.tile.getLevel()));
        if (zonePlannerMapChunk != null) {
            MapColourData data = zonePlannerMapChunk.getData(found.getX(), found.getZ());
            if (data != null) {
                foundColor = data.colour;
            }
        }
    }
    if (found != null) {
        GlStateManager.disableDepth();
        GlStateManager.enableBlend();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
        GlStateManager.glLineWidth(2);
        int r = (int) (((foundColor >> 16) & 0xFF) * 0.7);
        int g = (int) (((foundColor >> 8) & 0xFF) * 0.7);
        int b = (int) (((foundColor >> 0) & 0xFF) * 0.7);
        int a = 0x77;
        ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
        BufferBuilder builder = Tessellator.getInstance().getBuffer();
        builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
        ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(builder, found.getX(), found.getY(), found.getZ());
        Tessellator.getInstance().draw();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
        GlStateManager.disableBlend();
        GlStateManager.enableDepth();
    }
    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    for (int i = 0; i < container.tile.layers.length; i++) {
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
            continue;
        }
        ZonePlan layer = container.tile.layers[i];
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i && bufferLayer != null) {
            layer = bufferLayer;
        }
        if (!layer.getChunkPoses().isEmpty()) {
            Tessellator.getInstance().getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
                for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
                    ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ);
                    for (int blockX = chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
                        for (int blockZ = chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
                            if (!layer.get(blockX - container.tile.getPos().getX(), blockZ - container.tile.getPos().getZ())) {
                                continue;
                            }
                            int height;
                            ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
                            if (zonePlannerMapChunk != null) {
                                MapColourData data = zonePlannerMapChunk.getData(blockX, blockZ);
                                if (data != null) {
                                    height = data.posY;
                                } else {
                                    continue;
                                }
                            } else {
                                continue;
                            }
                            int color = EnumDyeColor.byMetadata(i).getColorValue();
                            int r = (color >> 16) & 0xFF;
                            int g = (color >> 8) & 0xFF;
                            int b = (color >> 0) & 0xFF;
                            int a = 0x55;
                            ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
                            ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(Tessellator.getInstance().getBuffer(), blockX, height + 0.1, blockZ, height, 0.6);
                        }
                    }
                }
            }
            Tessellator.getInstance().draw();
        }
    }
    GlStateManager.disableBlend();
    GlStateManager.disableLighting();
    GlStateManager.enableTexture2D();
    lastSelected = found;
    GlStateManager.popMatrix();
    GlStateManager.disableRescaleNormal();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.viewport(0, 0, mc.displayWidth, mc.displayHeight);
    GlStateManager.popMatrix();
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.popMatrix();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableBlend();
}
Also used : ItemPaintbrush_BC8(buildcraft.core.item.ItemPaintbrush_BC8) FloatBuffer(java.nio.FloatBuffer) ZonePlannerMapChunkKey(buildcraft.robotics.zone.ZonePlannerMapChunkKey) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Vector3d(javax.vecmath.Vector3d) GuiIcon(buildcraft.lib.gui.GuiIcon) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) GuiBC8(buildcraft.lib.gui.GuiBC8) BCCoreItems(buildcraft.core.BCCoreItems) Pair(org.apache.commons.lang3.tuple.Pair) IntBuffer(java.nio.IntBuffer) RenderHelper(net.minecraft.client.renderer.RenderHelper) GL11(org.lwjgl.opengl.GL11) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ZonePlan(buildcraft.robotics.zone.ZonePlan) GLU(org.lwjgl.util.glu.GLU) ZonePlannerMapChunk(buildcraft.robotics.zone.ZonePlannerMapChunk) ScaledResolution(net.minecraft.client.gui.ScaledResolution) GlStateManager(net.minecraft.client.renderer.GlStateManager) ContainerZonePlanner(buildcraft.robotics.container.ContainerZonePlanner) ZonePlannerMapRenderer(buildcraft.robotics.zone.ZonePlannerMapRenderer) ChunkPos(net.minecraft.util.math.ChunkPos) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) Mouse(org.lwjgl.input.Mouse) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BufferUtils(org.lwjgl.BufferUtils) List(java.util.List) Stream(java.util.stream.Stream) EnumDyeColor(net.minecraft.item.EnumDyeColor) Tessellator(net.minecraft.client.renderer.Tessellator) ResourceLocation(net.minecraft.util.ResourceLocation) MapColourData(buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData) ZonePlannerMapDataClient(buildcraft.robotics.zone.ZonePlannerMapDataClient) ZonePlannerMapChunkKey(buildcraft.robotics.zone.ZonePlannerMapChunkKey) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ZonePlannerMapChunk(buildcraft.robotics.zone.ZonePlannerMapChunk) GlStateManager(net.minecraft.client.renderer.GlStateManager) ScaledResolution(net.minecraft.client.gui.ScaledResolution) ZonePlan(buildcraft.robotics.zone.ZonePlan) Objects(java.util.Objects) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) MapColourData(buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData)

Example 17 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project legui by SpinyOwl.

the class MultipleWindowsExample method main.

public static void main(String[] args) {
    System.setProperty("joml.nounsafe", Boolean.TRUE.toString());
    System.setProperty("java.awt.headless", Boolean.TRUE.toString());
    if (!GLFW.glfwInit()) {
        throw new RuntimeException("Can't initialize GLFW");
    }
    glfwSetErrorCallback(GLFWErrorCallback.createPrint(System.err));
    int N = 3;
    long[] windows = new long[N];
    Renderer[] renderers = new NvgRenderer[N];
    Context[] contexts = new Context[N];
    Frame[] frames = new Frame[N];
    CallbackKeeper[] keepers = new DefaultCallbackKeeper[N];
    SystemEventProcessor[] systemEventProcessors = new SystemEventProcessor[N];
    GLFWKeyCallbackI glfwKeyCallbackI = (w1, key, code, action, mods) -> running = !(key == GLFW_KEY_ESCAPE && action != GLFW_RELEASE);
    GLFWWindowCloseCallbackI glfwWindowCloseCallbackI = w -> running = false;
    for (int i = 0; i < N; i++) {
        windows[i] = glfwCreateWindow(WIDTH, HEIGHT, "Multiple Windows Example " + (i + 1), NULL, NULL);
        glfwShowWindow(windows[i]);
        glfwMakeContextCurrent(windows[i]);
        GL.createCapabilities();
        glfwSwapInterval(0);
        glfwSetWindowPos(windows[i], 50, 50 + (HEIGHT + 50) * i);
        // Renderer which will render our ui components.
        renderers[i] = new NvgRenderer();
        renderers[i].initialize();
        createGuiElements(frames[i] = new Frame(WIDTH, HEIGHT));
        contexts[i] = new Context(windows[i]);
        keepers[i] = new DefaultCallbackKeeper();
        CallbackKeeper.registerCallbacks(windows[i], keepers[i]);
        keepers[i].getChainKeyCallback().add(glfwKeyCallbackI);
        keepers[i].getChainWindowCloseCallback().add(glfwWindowCloseCallbackI);
        systemEventProcessors[i] = new SystemEventProcessorImpl();
        SystemEventProcessor.addDefaultCallbacks(keepers[i], systemEventProcessors[i]);
    }
    running = true;
    while (running) {
        for (int i = 0; i < N; i++) {
            glfwMakeContextCurrent(windows[i]);
            GL.getCapabilities();
            glfwSwapInterval(0);
            contexts[i].updateGlfwWindow();
            Vector2i windowSize = contexts[i].getFramebufferSize();
            glClearColor(1, 1, 1, 1);
            glViewport(0, 0, windowSize.x, windowSize.y);
            glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
            renderers[i].render(frames[i], contexts[i]);
            glfwPollEvents();
            glfwSwapBuffers(windows[i]);
            systemEventProcessors[i].processEvents(frames[i], contexts[i]);
            EventProcessorProvider.getInstance().processEvents();
            // When everything done we need to relayout components.
            LayoutManager.getInstance().layout(frames[i]);
        }
    }
    for (int i = 0; i < N; i++) {
        renderers[i].destroy();
        glfwDestroyWindow(windows[i]);
    }
    glfwTerminate();
}
Also used : Context(com.spinyowl.legui.system.context.Context) GLFW.glfwDestroyWindow(org.lwjgl.glfw.GLFW.glfwDestroyWindow) GLFW.glfwSwapBuffers(org.lwjgl.glfw.GLFW.glfwSwapBuffers) GLFW_RELEASE(org.lwjgl.glfw.GLFW.GLFW_RELEASE) Component(com.spinyowl.legui.component.Component) MouseClickEventListener(com.spinyowl.legui.listener.MouseClickEventListener) Button(com.spinyowl.legui.component.Button) GLFW.glfwCreateWindow(org.lwjgl.glfw.GLFW.glfwCreateWindow) GLFW.glfwPollEvents(org.lwjgl.glfw.GLFW.glfwPollEvents) GLFWErrorCallback(org.lwjgl.glfw.GLFWErrorCallback) GLFW.glfwSwapInterval(org.lwjgl.glfw.GLFW.glfwSwapInterval) RadioButton(com.spinyowl.legui.component.RadioButton) GL11.glViewport(org.lwjgl.opengl.GL11.glViewport) NULL(org.lwjgl.system.MemoryUtil.NULL) ArrayList(java.util.ArrayList) GL_COLOR_BUFFER_BIT(org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT) Renderer(com.spinyowl.legui.system.renderer.Renderer) GLFW.glfwSetErrorCallback(org.lwjgl.glfw.GLFW.glfwSetErrorCallback) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) GL11.glClear(org.lwjgl.opengl.GL11.glClear) GLFW.glfwShowWindow(org.lwjgl.glfw.GLFW.glfwShowWindow) LayoutManager(com.spinyowl.legui.system.layout.LayoutManager) CursorEnterEventListener(com.spinyowl.legui.listener.CursorEnterEventListener) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) GL_STENCIL_BUFFER_BIT(org.lwjgl.opengl.GL11.GL_STENCIL_BUFFER_BIT) CursorEnterEvent(com.spinyowl.legui.event.CursorEnterEvent) Context(com.spinyowl.legui.system.context.Context) ColorConstants(com.spinyowl.legui.style.color.ColorConstants) Frame(com.spinyowl.legui.component.Frame) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) RadioButtonGroup(com.spinyowl.legui.component.RadioButtonGroup) GLFW.glfwTerminate(org.lwjgl.glfw.GLFW.glfwTerminate) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) GL11.glClearColor(org.lwjgl.opengl.GL11.glClearColor) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) Label(com.spinyowl.legui.component.Label) GLFW.glfwSetWindowPos(org.lwjgl.glfw.GLFW.glfwSetWindowPos) GLFW(org.lwjgl.glfw.GLFW) GLFW.glfwMakeContextCurrent(org.lwjgl.glfw.GLFW.glfwMakeContextCurrent) MouseClickEvent(com.spinyowl.legui.event.MouseClickEvent) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor) EventProcessorProvider(com.spinyowl.legui.listener.processor.EventProcessorProvider) List(java.util.List) Vector2i(org.joml.Vector2i) SimpleLineBorder(com.spinyowl.legui.style.border.SimpleLineBorder) GLFW_KEY_ESCAPE(org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE) GL(org.lwjgl.opengl.GL) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) Frame(com.spinyowl.legui.component.Frame) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) Renderer(com.spinyowl.legui.system.renderer.Renderer) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) Vector2i(org.joml.Vector2i) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor)

Example 18 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project legui by SpinyOwl.

the class SingleClassExample2 method main.

public static void main(String[] args) throws IOException {
    System.setProperty("joml.nounsafe", Boolean.TRUE.toString());
    System.setProperty("java.awt.headless", Boolean.TRUE.toString());
    if (!GLFW.glfwInit()) {
        throw new RuntimeException("Can't initialize GLFW");
    }
    long window = glfwCreateWindow(WIDTH, HEIGHT, "Legui", NULL, NULL);
    glfwShowWindow(window);
    glfwMakeContextCurrent(window);
    GL.createCapabilities();
    glfwSwapInterval(0);
    // Firstly we need to create frame component for window.
    Frame frame = new Frame(WIDTH, HEIGHT);
    // we can add elements here or on the fly
    // We need to create legui context which shared by renderer and event processor.
    // Also we need to pass event processor for ui events such as click on component, key typing and
    // etc.
    Context context = new Context(window);
    // We need to create callback keeper which will hold all of callbacks.
    // These callbacks will be used in initialization of system event processor
    // (will be added callbacks which will push system events to event queue and after that
    // processed by SystemEventProcessor)
    CallbackKeeper keeper = new DefaultCallbackKeeper();
    // register callbacks for window. Note: all previously binded callbacks will be unbinded.
    CallbackKeeper.registerCallbacks(window, keeper);
    GLFWKeyCallbackI glfwKeyCallbackI = (w1, key, code, action, mods) -> running = !(key == GLFW_KEY_ESCAPE && action != GLFW_RELEASE);
    GLFWWindowCloseCallbackI glfwWindowCloseCallbackI = w -> running = false;
    // if we want to create some callbacks for system events you should create and put them to
    // keeper
    // 
    // Wrong:
    // glfwSetKeyCallback(window, glfwKeyCallbackI);
    // glfwSetWindowCloseCallback(window, glfwWindowCloseCallbackI);
    // 
    // Right:
    keeper.getChainKeyCallback().add(glfwKeyCallbackI);
    keeper.getChainWindowCloseCallback().add(glfwWindowCloseCallbackI);
    // Event processor for system events. System events should be processed and translated to gui
    // events.
    SystemEventProcessor systemEventProcessor = new SystemEventProcessorImpl();
    SystemEventProcessor.addDefaultCallbacks(keeper, systemEventProcessor);
    // Also we need to create renderer provider
    // and create renderer which will render our ui components.
    Renderer renderer = new NvgRenderer();
    // Initialization finished, so we can start render loop.
    running = true;
    // Everything can be done in one thread as well as in separated threads.
    // Here is one-thread example.
    // before render loop we need to initialize renderer
    renderer.initialize();
    AtomicBoolean needToUpdate = new AtomicBoolean(true);
    keeper.getChainKeyCallback().add((w, key, scancode, action, mods) -> {
        if (key == GLFW_KEY_F1 && action == GLFW_RELEASE)
            needToUpdate.set(true);
    });
    // createUI(frame);
    while (running) {
        if (needToUpdate.getAndSet(false))
            createUI(frame);
        // Before rendering we need to update context with window size and window framebuffer size
        // {
        // int[] windowWidth = {0}, windowHeight = {0};
        // GLFW.glfwGetWindowSize(window, windowWidth, windowHeight);
        // int[] frameBufferWidth = {0}, frameBufferHeight = {0};
        // GLFW.glfwGetFramebufferSize(window, frameBufferWidth, frameBufferHeight);
        // int[] xpos = {0}, ypos = {0};
        // GLFW.glfwGetWindowPos(window, xpos, ypos);
        // double[] mx = {0}, my = {0};
        // GLFW.glfwGetCursorPos(window, mx, my);
        // 
        // context.update(windowWidth[0], windowHeight[0],
        // frameBufferWidth[0], frameBufferHeight[0],
        // xpos[0], ypos[0],
        // mx[0], my[0]
        // );
        // }
        // Also we can do it in one line
        context.updateGlfwWindow();
        Vector2i windowSize = context.getFramebufferSize();
        glClearColor(1, 1, 1, 1);
        // Set viewport size
        glViewport(0, 0, windowSize.x, windowSize.y);
        // Clear screen
        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        // render frame
        renderer.render(frame, context);
        // poll events to callbacks
        glfwPollEvents();
        glfwSwapBuffers(window);
        // Now we need to process events. Firstly we need to process system events.
        systemEventProcessor.processEvents(frame, context);
        // When system events are translated to GUI events we need to process them.
        // This event processor calls listeners added to ui components
        EventProcessorProvider.getInstance().processEvents();
        // When everything done we need to relayout components.
        LayoutManager.getInstance().layout(frame);
        // Run animations. Should be also called cause some components use animations for updating
        // state.
        AnimatorProvider.getAnimator().runAnimations();
    }
    // And when rendering is ended we need to destroy renderer
    renderer.destroy();
    glfwDestroyWindow(window);
    glfwTerminate();
}
Also used : Context(com.spinyowl.legui.system.context.Context) COLUMN(com.spinyowl.legui.style.flex.FlexStyle.FlexDirection.COLUMN) GLFW.glfwDestroyWindow(org.lwjgl.glfw.GLFW.glfwDestroyWindow) GLFW_RELEASE(org.lwjgl.glfw.GLFW.GLFW_RELEASE) Button(com.spinyowl.legui.component.Button) GLFW.glfwCreateWindow(org.lwjgl.glfw.GLFW.glfwCreateWindow) GLFW.glfwPollEvents(org.lwjgl.glfw.GLFW.glfwPollEvents) GLFW.glfwSwapInterval(org.lwjgl.glfw.GLFW.glfwSwapInterval) ROW(com.spinyowl.legui.style.flex.FlexStyle.FlexDirection.ROW) GL11.glViewport(org.lwjgl.opengl.GL11.glViewport) NULL(org.lwjgl.system.MemoryUtil.NULL) ABSOLUTE(com.spinyowl.legui.style.Style.PositionType.ABSOLUTE) Renderer(com.spinyowl.legui.system.renderer.Renderer) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) GLFW.glfwShowWindow(org.lwjgl.glfw.GLFW.glfwShowWindow) LayoutManager(com.spinyowl.legui.system.layout.LayoutManager) GL_STENCIL_BUFFER_BIT(org.lwjgl.opengl.GL11.GL_STENCIL_BUFFER_BIT) ColorUtil(com.spinyowl.legui.style.color.ColorUtil) FLEX(com.spinyowl.legui.style.Style.DisplayType.FLEX) ColorConstants(com.spinyowl.legui.style.color.ColorConstants) Frame(com.spinyowl.legui.component.Frame) GLFW.glfwTerminate(org.lwjgl.glfw.GLFW.glfwTerminate) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) JustifyContent(com.spinyowl.legui.style.flex.FlexStyle.JustifyContent) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) Label(com.spinyowl.legui.component.Label) GLFW(org.lwjgl.glfw.GLFW) GLFW.glfwMakeContextCurrent(org.lwjgl.glfw.GLFW.glfwMakeContextCurrent) EventProcessorProvider(com.spinyowl.legui.listener.processor.EventProcessorProvider) Vector2i(org.joml.Vector2i) Vector2f(org.joml.Vector2f) AlignContent(com.spinyowl.legui.style.flex.FlexStyle.AlignContent) GLFW.glfwSwapBuffers(org.lwjgl.glfw.GLFW.glfwSwapBuffers) Component(com.spinyowl.legui.component.Component) Intersector(com.spinyowl.legui.intersection.Intersector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GL_COLOR_BUFFER_BIT(org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT) RELATIVE(com.spinyowl.legui.style.Style.PositionType.RELATIVE) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) GL11.glClear(org.lwjgl.opengl.GL11.glClear) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) Context(com.spinyowl.legui.system.context.Context) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) FontRegistry(com.spinyowl.legui.style.font.FontRegistry) GL11.glClearColor(org.lwjgl.opengl.GL11.glClearColor) GLFW_KEY_F1(org.lwjgl.glfw.GLFW.GLFW_KEY_F1) IOException(java.io.IOException) AlignItems(com.spinyowl.legui.style.flex.FlexStyle.AlignItems) AnimatorProvider(com.spinyowl.legui.animation.AnimatorProvider) Panel(com.spinyowl.legui.component.Panel) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor) SimpleLineBorder(com.spinyowl.legui.style.border.SimpleLineBorder) Widget(com.spinyowl.legui.component.Widget) GLFW_KEY_ESCAPE(org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE) GL(org.lwjgl.opengl.GL) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) Frame(com.spinyowl.legui.component.Frame) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) Renderer(com.spinyowl.legui.system.renderer.Renderer) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) Vector2i(org.joml.Vector2i) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor)

Example 19 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project legui by SpinyOwl.

the class SingleClassExample method main.

public static void main(String[] args) throws IOException {
    System.setProperty("joml.nounsafe", Boolean.TRUE.toString());
    System.setProperty("java.awt.headless", Boolean.TRUE.toString());
    if (!GLFW.glfwInit()) {
        throw new RuntimeException("Can't initialize GLFW");
    }
    long window = glfwCreateWindow(WIDTH, HEIGHT, "Single Class Example", NULL, NULL);
    glfwShowWindow(window);
    glfwMakeContextCurrent(window);
    GL.createCapabilities();
    glfwSwapInterval(0);
    // Firstly we need to create frame component for window.
    Frame frame = new Frame(WIDTH, HEIGHT);
    // we can add elements here or on the fly
    createGuiElements(frame);
    // We need to create legui context which shared by renderer and event processor.
    // Also we need to pass event processor for ui events such as click on component, key typing and
    // etc.
    Context context = new Context(window);
    // We need to create callback keeper which will hold all of callbacks.
    // These callbacks will be used in initialization of system event processor
    // (will be added callbacks which will push system events to event queue and after that
    // processed by SystemEventProcessor)
    CallbackKeeper keeper = new DefaultCallbackKeeper();
    // register callbacks for window. Note: all previously binded callbacks will be unbinded.
    CallbackKeeper.registerCallbacks(window, keeper);
    GLFWKeyCallbackI glfwKeyCallbackI = (w1, key, code, action, mods) -> running = !(key == GLFW_KEY_ESCAPE && action != GLFW_RELEASE);
    GLFWWindowCloseCallbackI glfwWindowCloseCallbackI = w -> running = false;
    // if we want to create some callbacks for system events you should create and put them to
    // keeper
    // 
    // Wrong:
    // glfwSetKeyCallback(window, glfwKeyCallbackI);
    // glfwSetWindowCloseCallback(window, glfwWindowCloseCallbackI);
    // 
    // Right:
    keeper.getChainKeyCallback().add(glfwKeyCallbackI);
    keeper.getChainWindowCloseCallback().add(glfwWindowCloseCallbackI);
    // Event processor for system events. System events should be processed and translated to gui
    // events.
    SystemEventProcessor systemEventProcessor = new SystemEventProcessorImpl();
    SystemEventProcessor.addDefaultCallbacks(keeper, systemEventProcessor);
    // Also we need to create renderer provider
    // and create renderer which will render our ui components.
    Renderer renderer = new NvgRenderer();
    // Initialization finished, so we can start render loop.
    running = true;
    // Everything can be done in one thread as well as in separated threads.
    // Here is one-thread example.
    // before render loop we need to initialize renderer
    renderer.initialize();
    while (running) {
        // Before rendering we need to update context with window size and window framebuffer size
        // {
        // int[] windowWidth = {0}, windowHeight = {0};
        // GLFW.glfwGetWindowSize(window, windowWidth, windowHeight);
        // int[] frameBufferWidth = {0}, frameBufferHeight = {0};
        // GLFW.glfwGetFramebufferSize(window, frameBufferWidth, frameBufferHeight);
        // int[] xpos = {0}, ypos = {0};
        // GLFW.glfwGetWindowPos(window, xpos, ypos);
        // double[] mx = {0}, my = {0};
        // GLFW.glfwGetCursorPos(window, mx, my);
        // 
        // context.update(windowWidth[0], windowHeight[0],
        // frameBufferWidth[0], frameBufferHeight[0],
        // xpos[0], ypos[0],
        // mx[0], my[0]
        // );
        // }
        // Also we can do it in one line
        context.updateGlfwWindow();
        Vector2i windowSize = context.getFramebufferSize();
        glClearColor(1, 1, 1, 1);
        // Set viewport size
        glViewport(0, 0, windowSize.x, windowSize.y);
        // Clear screen
        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        // render frame
        renderer.render(frame, context);
        // poll events to callbacks
        glfwPollEvents();
        glfwSwapBuffers(window);
        // Now we need to process events. Firstly we need to process system events.
        systemEventProcessor.processEvents(frame, context);
        // When system events are translated to GUI events we need to process them.
        // This event processor calls listeners added to ui components
        EventProcessorProvider.getInstance().processEvents();
        // When everything done we need to relayout components.
        LayoutManager.getInstance().layout(frame);
        // Run animations. Should be also called cause some components use animations for updating
        // state.
        AnimatorProvider.getAnimator().runAnimations();
        update(context);
    }
    // And when rendering is ended we need to destroy renderer
    renderer.destroy();
    glfwDestroyWindow(window);
    glfwTerminate();
}
Also used : Context(com.spinyowl.legui.system.context.Context) TOP(com.spinyowl.legui.component.TabbedPanel.TabStripPosition.TOP) GLFW.glfwDestroyWindow(org.lwjgl.glfw.GLFW.glfwDestroyWindow) GLFW_RELEASE(org.lwjgl.glfw.GLFW.GLFW_RELEASE) Button(com.spinyowl.legui.component.Button) RIGHT(com.spinyowl.legui.component.TabbedPanel.TabStripPosition.RIGHT) GLFW.glfwCreateWindow(org.lwjgl.glfw.GLFW.glfwCreateWindow) GLFW.glfwPollEvents(org.lwjgl.glfw.GLFW.glfwPollEvents) GLFW.glfwSwapInterval(org.lwjgl.glfw.GLFW.glfwSwapInterval) GL11.glViewport(org.lwjgl.opengl.GL11.glViewport) NULL(org.lwjgl.system.MemoryUtil.NULL) KeyEvent(com.spinyowl.legui.event.KeyEvent) Renderer(com.spinyowl.legui.system.renderer.Renderer) FlexDirection(com.spinyowl.legui.style.flex.FlexStyle.FlexDirection) MouseClickAction(com.spinyowl.legui.event.MouseClickEvent.MouseClickAction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) GLFW.glfwShowWindow(org.lwjgl.glfw.GLFW.glfwShowWindow) LayoutManager(com.spinyowl.legui.system.layout.LayoutManager) CursorEnterEventListener(com.spinyowl.legui.listener.CursorEnterEventListener) GL_STENCIL_BUFFER_BIT(org.lwjgl.opengl.GL11.GL_STENCIL_BUFFER_BIT) CursorEnterEvent(com.spinyowl.legui.event.CursorEnterEvent) PositionType(com.spinyowl.legui.style.Style.PositionType) ColorUtil(com.spinyowl.legui.style.color.ColorUtil) LEFT(com.spinyowl.legui.component.TabbedPanel.TabStripPosition.LEFT) FLEX(com.spinyowl.legui.style.Style.DisplayType.FLEX) ColorConstants(com.spinyowl.legui.style.color.ColorConstants) Frame(com.spinyowl.legui.component.Frame) GLFW.glfwTerminate(org.lwjgl.glfw.GLFW.glfwTerminate) GLFW_KEY_5(org.lwjgl.glfw.GLFW.GLFW_KEY_5) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) GLFW_KEY_6(org.lwjgl.glfw.GLFW.GLFW_KEY_6) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) Label(com.spinyowl.legui.component.Label) GLFW(org.lwjgl.glfw.GLFW) GLFW.glfwMakeContextCurrent(org.lwjgl.glfw.GLFW.glfwMakeContextCurrent) EventProcessorProvider(com.spinyowl.legui.listener.processor.EventProcessorProvider) List(java.util.List) Vector2i(org.joml.Vector2i) TabStripPosition(com.spinyowl.legui.component.TabbedPanel.TabStripPosition) NotNull(org.jetbrains.annotations.NotNull) GLFW.glfwSwapBuffers(org.lwjgl.glfw.GLFW.glfwSwapBuffers) Component(com.spinyowl.legui.component.Component) TabbedPanel(com.spinyowl.legui.component.TabbedPanel) MouseClickEventListener(com.spinyowl.legui.listener.MouseClickEventListener) BOTTOM(com.spinyowl.legui.component.TabbedPanel.TabStripPosition.BOTTOM) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) GL_COLOR_BUFFER_BIT(org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) GLFW_KEY_3(org.lwjgl.glfw.GLFW.GLFW_KEY_3) GL11.glClear(org.lwjgl.opengl.GL11.glClear) GLFW_KEY_4(org.lwjgl.glfw.GLFW.GLFW_KEY_4) GLFW_KEY_1(org.lwjgl.glfw.GLFW.GLFW_KEY_1) GLFW_KEY_2(org.lwjgl.glfw.GLFW.GLFW_KEY_2) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) Context(com.spinyowl.legui.system.context.Context) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) GL11.glClearColor(org.lwjgl.opengl.GL11.glClearColor) IOException(java.io.IOException) AnimatorProvider(com.spinyowl.legui.animation.AnimatorProvider) Panel(com.spinyowl.legui.component.Panel) MouseClickEvent(com.spinyowl.legui.event.MouseClickEvent) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor) SimpleLineBorder(com.spinyowl.legui.style.border.SimpleLineBorder) Widget(com.spinyowl.legui.component.Widget) GLFW_KEY_ESCAPE(org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE) Tab(com.spinyowl.legui.component.TabbedPanel.Tab) Vector4f(org.joml.Vector4f) GL(org.lwjgl.opengl.GL) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) Frame(com.spinyowl.legui.component.Frame) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) Renderer(com.spinyowl.legui.system.renderer.Renderer) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) Vector2i(org.joml.Vector2i) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor)

Example 20 with GL11.glViewport

use of org.lwjgl.opengl.GL11.glViewport in project legui by SpinyOwl.

the class FBOImageExample method main.

public static void main(String[] args) throws IOException {
    System.setProperty("joml.nounsafe", Boolean.TRUE.toString());
    System.setProperty("java.awt.headless", Boolean.TRUE.toString());
    if (!GLFW.glfwInit()) {
        throw new RuntimeException("Can't initialize GLFW");
    }
    long window = glfwCreateWindow(WIDTH, HEIGHT, "FBO Image example", NULL, NULL);
    glfwShowWindow(window);
    glfwMakeContextCurrent(window);
    GL.createCapabilities();
    glfwSwapInterval(0);
    // Firstly we need to create frame component for window.
    Frame frame = new Frame(WIDTH, HEIGHT);
    // We need to create legui context which shared by renderer and event processor.
    // Also we need to pass event processor for ui events such as click on component, key typing and etc.
    Context context = new Context(window);
    // We need to create callback keeper which will hold all of callbacks.
    // These callbacks will be used in initialization of system event processor
    // (will be added callbacks which will push system events to event queue and after that processed by SystemEventProcessor)
    CallbackKeeper keeper = new DefaultCallbackKeeper();
    // register callbacks for window. Note: all previously binded callbacks will be unbinded.
    CallbackKeeper.registerCallbacks(window, keeper);
    GLFWKeyCallbackI glfwKeyCallbackI = (w1, key, code, action, mods) -> running = !(key == GLFW_KEY_ESCAPE && action != GLFW_RELEASE);
    GLFWWindowCloseCallbackI glfwWindowCloseCallbackI = w -> running = false;
    // if we want to create some callbacks for system events you should create and put them to keeper
    // 
    // Wrong:
    // glfwSetKeyCallback(window, glfwKeyCallbackI);
    // glfwSetWindowCloseCallback(window, glfwWindowCloseCallbackI);
    // 
    // Right:
    keeper.getChainKeyCallback().add(glfwKeyCallbackI);
    keeper.getChainWindowCloseCallback().add(glfwWindowCloseCallbackI);
    // Event processor for system events. System events should be processed and translated to gui events.
    SystemEventProcessor systemEventProcessor = new SystemEventProcessorImpl();
    SystemEventProcessor.addDefaultCallbacks(keeper, systemEventProcessor);
    // Also we need to create renderer provider
    // and create renderer which will render our ui components.
    Renderer renderer = new NvgRenderer();
    // Initialization finished, so we can start render loop.
    running = true;
    // Everything can be done in one thread as well as in separated threads.
    // Here is one-thread example.
    // before render loop we need to initialize renderer
    renderer.initialize();
    // //// rendering to texture and use this texture as image
    long nvgContext = 0;
    FBOImage fboTexture = null;
    boolean isVersionNew = (glGetInteger(GL_MAJOR_VERSION) > 3) || (glGetInteger(GL_MAJOR_VERSION) == 3 && glGetInteger(GL_MINOR_VERSION) >= 2);
    if (isVersionNew) {
        int flags = NanoVGGL3.NVG_STENCIL_STROKES | NanoVGGL3.NVG_ANTIALIAS;
        nvgContext = NanoVGGL3.nvgCreate(flags);
    } else {
        int flags = NanoVGGL2.NVG_STENCIL_STROKES | NanoVGGL2.NVG_ANTIALIAS;
        nvgContext = NanoVGGL2.nvgCreate(flags);
    }
    if (nvgContext != 0) {
        fboTexture = createFBOTexture(textureWidth, textureHeight);
        Widget widget = new Widget(10, 10, 100, 100);
        widget.setCloseable(false);
        widget.setMinimizable(false);
        widget.setResizable(true);
        widget.getContainer().getStyle().setDisplay(DisplayType.FLEX);
        ImageView imageView = new ImageView(fboTexture);
        imageView.setPosition(10, 10);
        imageView.getStyle().setPosition(PositionType.RELATIVE);
        imageView.getStyle().getFlexStyle().setFlexGrow(1);
        imageView.getStyle().setMargin(10f);
        imageView.getStyle().setMinimumSize(50, 50);
        widget.getContainer().add(imageView);
        frame.getContainer().add(widget);
    }
    while (running) {
        if (fboTexture != null) {
            renderToFBO(nvgContext);
        }
        // Before rendering we need to update context with window size and window framebuffer size
        // {
        // int[] windowWidth = {0}, windowHeight = {0};
        // GLFW.glfwGetWindowSize(window, windowWidth, windowHeight);
        // int[] frameBufferWidth = {0}, frameBufferHeight = {0};
        // GLFW.glfwGetFramebufferSize(window, frameBufferWidth, frameBufferHeight);
        // int[] xpos = {0}, ypos = {0};
        // GLFW.glfwGetWindowPos(window, xpos, ypos);
        // double[] mx = {0}, my = {0};
        // GLFW.glfwGetCursorPos(window, mx, my);
        // 
        // context.update(windowWidth[0], windowHeight[0],
        // frameBufferWidth[0], frameBufferHeight[0],
        // xpos[0], ypos[0],
        // mx[0], my[0]
        // );
        // }
        // Also we can do it in one line
        context.updateGlfwWindow();
        Vector2i windowSize = context.getFramebufferSize();
        glClearColor(1, 1, 1, 1);
        // Set viewport size
        glViewport(0, 0, windowSize.x, windowSize.y);
        // Clear screen
        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        // render frame
        renderer.render(frame, context);
        // poll events to callbacks
        glfwPollEvents();
        glfwSwapBuffers(window);
        // Now we need to process events. Firstly we need to process system events.
        systemEventProcessor.processEvents(frame, context);
        // When system events are translated to GUI events we need to process them.
        // This event processor calls listeners added to ui components
        EventProcessorProvider.getInstance().processEvents();
        // When everything done we need to relayout components.
        LayoutManager.getInstance().layout(frame);
        // Run animations. Should be also called cause some components use animations for updating state.
        AnimatorProvider.getAnimator().runAnimations();
    }
    if (nvgContext != 0) {
        glDeleteRenderbuffers(renderBufferID);
        glDeleteTextures(textureID);
        glDeleteFramebuffers(frameBufferID);
        if (isVersionNew) {
            NanoVGGL3.nnvgDelete(nvgContext);
        } else {
            NanoVGGL2.nnvgDelete(nvgContext);
        }
    }
    // And when rendering is ended we need to destroy renderer
    renderer.destroy();
    glfwDestroyWindow(window);
    glfwTerminate();
}
Also used : Context(com.spinyowl.legui.system.context.Context) GLFW.glfwDestroyWindow(org.lwjgl.glfw.GLFW.glfwDestroyWindow) GLFW_RELEASE(org.lwjgl.glfw.GLFW.GLFW_RELEASE) NanoVG.nvgEndFrame(org.lwjgl.nanovg.NanoVG.nvgEndFrame) GLFW.glfwCreateWindow(org.lwjgl.glfw.GLFW.glfwCreateWindow) GLFW.glfwPollEvents(org.lwjgl.glfw.GLFW.glfwPollEvents) GLFW.glfwSwapInterval(org.lwjgl.glfw.GLFW.glfwSwapInterval) GL30.glDisable(org.lwjgl.opengl.GL30.glDisable) GL_COLOR_BUFFER_BIT(org.lwjgl.opengl.GL30.GL_COLOR_BUFFER_BIT) NanoVG.nvgStroke(org.lwjgl.nanovg.NanoVG.nvgStroke) GL_ONE_MINUS_SRC_ALPHA(org.lwjgl.opengl.GL30.GL_ONE_MINUS_SRC_ALPHA) NULL(org.lwjgl.system.MemoryUtil.NULL) GL_COLOR_ATTACHMENT0(org.lwjgl.opengl.GL30.GL_COLOR_ATTACHMENT0) GL_RGBA(org.lwjgl.opengl.GL30.GL_RGBA) Renderer(com.spinyowl.legui.system.renderer.Renderer) GL30.glBindFramebuffer(org.lwjgl.opengl.GL30.glBindFramebuffer) GL_SRC_ALPHA(org.lwjgl.opengl.GL30.GL_SRC_ALPHA) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) GLFW.glfwShowWindow(org.lwjgl.glfw.GLFW.glfwShowWindow) GL30.glDeleteTextures(org.lwjgl.opengl.GL30.glDeleteTextures) LayoutManager(com.spinyowl.legui.system.layout.LayoutManager) GL30.glRenderbufferStorage(org.lwjgl.opengl.GL30.glRenderbufferStorage) GL30.glDrawBuffer(org.lwjgl.opengl.GL30.glDrawBuffer) PositionType(com.spinyowl.legui.style.Style.PositionType) NVGColor(org.lwjgl.nanovg.NVGColor) Frame(com.spinyowl.legui.component.Frame) GL30.glDeleteFramebuffers(org.lwjgl.opengl.GL30.glDeleteFramebuffers) GLFW.glfwTerminate(org.lwjgl.glfw.GLFW.glfwTerminate) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) GL_UNSIGNED_BYTE(org.lwjgl.opengl.GL30.GL_UNSIGNED_BYTE) GL_STENCIL_BUFFER_BIT(org.lwjgl.opengl.GL30.GL_STENCIL_BUFFER_BIT) GL30.glClearColor(org.lwjgl.opengl.GL30.glClearColor) GL_DEPTH_COMPONENT(org.lwjgl.opengl.GL30.GL_DEPTH_COMPONENT) GLFW(org.lwjgl.glfw.GLFW) GLFW.glfwMakeContextCurrent(org.lwjgl.glfw.GLFW.glfwMakeContextCurrent) EventProcessorProvider(com.spinyowl.legui.listener.processor.EventProcessorProvider) GL30.glGenRenderbuffers(org.lwjgl.opengl.GL30.glGenRenderbuffers) GL30.glGenTextures(org.lwjgl.opengl.GL30.glGenTextures) FBOImage(com.spinyowl.legui.image.FBOImage) Vector2i(org.joml.Vector2i) GL_TEXTURE_MIN_FILTER(org.lwjgl.opengl.GL30.GL_TEXTURE_MIN_FILTER) GL30.glTexImage2D(org.lwjgl.opengl.GL30.glTexImage2D) NanoVGGL2(org.lwjgl.nanovg.NanoVGGL2) GLFW.glfwSwapBuffers(org.lwjgl.glfw.GLFW.glfwSwapBuffers) GL30.glBindTexture(org.lwjgl.opengl.GL30.glBindTexture) GL_MINOR_VERSION(org.lwjgl.opengl.GL30.GL_MINOR_VERSION) GL32.glFramebufferTexture(org.lwjgl.opengl.GL32.glFramebufferTexture) NanoVG.nvgFill(org.lwjgl.nanovg.NanoVG.nvgFill) GL30(org.lwjgl.opengl.GL30) ImageView(com.spinyowl.legui.component.ImageView) NanoVGGL3(org.lwjgl.nanovg.NanoVGGL3) NanoVG.nvgStrokeColor(org.lwjgl.nanovg.NanoVG.nvgStrokeColor) GL_TEXTURE_MAG_FILTER(org.lwjgl.opengl.GL30.GL_TEXTURE_MAG_FILTER) GL30.glEnable(org.lwjgl.opengl.GL30.glEnable) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) GL_RENDERBUFFER(org.lwjgl.opengl.GL30.GL_RENDERBUFFER) GL_BLEND(org.lwjgl.opengl.GL30.GL_BLEND) GL30.glFramebufferRenderbuffer(org.lwjgl.opengl.GL30.glFramebufferRenderbuffer) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) Context(com.spinyowl.legui.system.context.Context) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) GL30.glClear(org.lwjgl.opengl.GL30.glClear) GL_TEXTURE_2D(org.lwjgl.opengl.GL30.GL_TEXTURE_2D) IOException(java.io.IOException) NanoVG.nvgBeginPath(org.lwjgl.nanovg.NanoVG.nvgBeginPath) NanoVG.nvgBeginFrame(org.lwjgl.nanovg.NanoVG.nvgBeginFrame) GL_MAJOR_VERSION(org.lwjgl.opengl.GL30.GL_MAJOR_VERSION) AnimatorProvider(com.spinyowl.legui.animation.AnimatorProvider) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor) DisplayType(com.spinyowl.legui.style.Style.DisplayType) GL30.glDeleteRenderbuffers(org.lwjgl.opengl.GL30.glDeleteRenderbuffers) NanoVG.nvgRotate(org.lwjgl.nanovg.NanoVG.nvgRotate) GL30.glViewport(org.lwjgl.opengl.GL30.glViewport) GL30.glBindRenderbuffer(org.lwjgl.opengl.GL30.glBindRenderbuffer) GL30.glBlendFunc(org.lwjgl.opengl.GL30.glBlendFunc) GL_FRAMEBUFFER(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER) GL_NEAREST(org.lwjgl.opengl.GL30.GL_NEAREST) NanoVG.nvgFillColor(org.lwjgl.nanovg.NanoVG.nvgFillColor) GL30.glTexParameteri(org.lwjgl.opengl.GL30.glTexParameteri) Widget(com.spinyowl.legui.component.Widget) GLFW_KEY_ESCAPE(org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE) GL_DEPTH_ATTACHMENT(org.lwjgl.opengl.GL30.GL_DEPTH_ATTACHMENT) GL30.glGetInteger(org.lwjgl.opengl.GL30.glGetInteger) NanoVG.nvgRect(org.lwjgl.nanovg.NanoVG.nvgRect) NanoVG.nvgTranslate(org.lwjgl.nanovg.NanoVG.nvgTranslate) GL(org.lwjgl.opengl.GL) GLFWKeyCallbackI(org.lwjgl.glfw.GLFWKeyCallbackI) NanoVG.nvgEndFrame(org.lwjgl.nanovg.NanoVG.nvgEndFrame) Frame(com.spinyowl.legui.component.Frame) NanoVG.nvgBeginFrame(org.lwjgl.nanovg.NanoVG.nvgBeginFrame) CallbackKeeper(com.spinyowl.legui.system.context.CallbackKeeper) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) Widget(com.spinyowl.legui.component.Widget) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) GLFWWindowCloseCallbackI(org.lwjgl.glfw.GLFWWindowCloseCallbackI) DefaultCallbackKeeper(com.spinyowl.legui.system.context.DefaultCallbackKeeper) SystemEventProcessorImpl(com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl) Renderer(com.spinyowl.legui.system.renderer.Renderer) NvgRenderer(com.spinyowl.legui.system.renderer.nvg.NvgRenderer) ImageView(com.spinyowl.legui.component.ImageView) Vector2i(org.joml.Vector2i) FBOImage(com.spinyowl.legui.image.FBOImage) SystemEventProcessor(com.spinyowl.legui.system.handler.processor.SystemEventProcessor)

Aggregations

GL11 (org.lwjgl.opengl.GL11)16 List (java.util.List)10 IOException (java.io.IOException)7 Minecraft (net.minecraft.client.Minecraft)7 GlStateManager (net.minecraft.client.renderer.GlStateManager)7 DefaultVertexFormats (net.minecraft.client.renderer.vertex.DefaultVertexFormats)7 GLFW (org.lwjgl.glfw.GLFW)7 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 NvgRenderer (com.spinyowl.legui.system.renderer.nvg.NvgRenderer)5