Java Code Examples for org.lwjgl.opengl.GL11#glScissor()
The following examples show how to use
org.lwjgl.opengl.GL11#glScissor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Scissors.java From LibGui with MIT License | 5 votes |
static void refreshScissors() { MinecraftClient mc = MinecraftClient.getInstance(); if (STACK.isEmpty()) { // Just use the full window framebuffer as a scissor GL11.glScissor(0, 0, mc.getWindow().getFramebufferWidth(), mc.getWindow().getFramebufferHeight()); return; } int x = Integer.MIN_VALUE; int y = Integer.MIN_VALUE; int width = -1; int height = -1; for (Frame frame : STACK) { if (x < frame.x) { x = frame.x; } if (y < frame.y) { y = frame.y; } if (width == -1 || x + width > frame.x + frame.width) { width = frame.width - (x - frame.x); } if (height == -1 || y + height > frame.y + frame.height) { height = frame.height - (y - frame.y); } } int windowHeight = mc.getWindow().getHeight(); double scale = mc.getWindow().getScaleFactor(); int scaledWidth = (int) (width * scale); int scaledHeight = (int) (height * scale); // Expression for Y coordinate adapted from vini2003's Spinnery (code snippet released under WTFPL) GL11.glScissor((int) (x * scale), (int) (windowHeight - (y * scale) - scaledHeight), scaledWidth, scaledHeight); }
Example 2
Source File: WorldSceneRenderer.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public static Vec2f setupCamera(int x, int y, int width, int height, int skyColor) { Minecraft mc = Minecraft.getMinecraft(); ScaledResolution resolution = new ScaledResolution(mc); GlStateManager.pushAttrib(); mc.entityRenderer.disableLightmap(); GlStateManager.disableLighting(); GlStateManager.enableDepth(); GlStateManager.enableBlend(); //compute window size from scaled width & height int windowWidth = (int) (width / (resolution.getScaledWidth() * 1.0) * mc.displayWidth); int windowHeight = (int) (height / (resolution.getScaledHeight() * 1.0) * mc.displayHeight); //translate gui coordinates to window's ones (y is inverted) int windowX = (int) (x / (resolution.getScaledWidth() * 1.0) * mc.displayWidth); int windowY = mc.displayHeight - (int) (y / (resolution.getScaledHeight() * 1.0) * mc.displayHeight) - windowHeight; int mouseX = Mouse.getX(); int mouseY = Mouse.getY(); Vec2f mousePosition = null; //compute mouse position only if inside viewport if (mouseX >= windowX && mouseY >= windowY && mouseX - windowX < windowWidth && mouseY - windowY < windowHeight) { mousePosition = new Vec2f(mouseX, mouseY); } //setup viewport and clear GL buffers GlStateManager.viewport(windowX, windowY, windowWidth, windowHeight); if (skyColor >= 0) { GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glScissor(windowX, windowY, windowWidth, windowHeight); RenderUtil.setGlClearColorFromInt(skyColor, 255); GlStateManager.clear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glDisable(GL11.GL_SCISSOR_TEST); } //setup projection matrix to perspective GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.pushMatrix(); GlStateManager.loadIdentity(); float aspectRatio = width / (height * 1.0f); GLU.gluPerspective(60.0f, aspectRatio, 0.1f, 10000.0f); //setup modelview matrix GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.pushMatrix(); GlStateManager.loadIdentity(); GLU.gluLookAt(0.0f, 0.0f, -10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); return mousePosition; }
Example 3
Source File: RenderUtil.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static void applyScissor(int x, int y, int w, int h) { //translate upper-left to bottom-left ScaledResolution r = ((GuiIngameForge) Minecraft.getMinecraft().ingameGUI).getResolution(); int s = r.getScaleFactor(); int translatedY = r.getScaledHeight() - y - h; GL11.glScissor(x*s, translatedY*s, w*s, h*s); }
Example 4
Source File: GuiWindowMod.java From ForgeHax with MIT License | 5 votes |
public void drawWindow(int mouseX, int mouseY) { super.drawWindow(mouseX, mouseY); windowY = headerY + 22; SurfaceHelper.drawOutlinedRectShaded( posX, windowY, width, height, Colors.GRAY.toBuffer(), 80, 3); int buttonY = windowY - buttonListOffset + 2; int scale = ClickGui.scaledRes.getScaleFactor(); GL11.glPushMatrix(); int scissorY = MC.displayHeight - (scale * windowY + scale * height - 3); GL11.glScissor(scale * posX, scissorY, scale * width, scale * height - 8); GL11.glEnable(GL11.GL_SCISSOR_TEST); for (GuiButton button : buttonList) { SurfaceHelper.drawRect(posX + 2, buttonY, width - 4, GuiButton.height, button.getColor()); SurfaceHelper.drawTextShadowCentered( button.getName(), (posX + 2) + width / 2f, buttonY + GuiButton.height / 2f, Colors.WHITE.toBuffer()); button.setCoords(posX + 2, buttonY); buttonY += GuiButton.height + 1; } GL11.glDisable(GL11.GL_SCISSOR_TEST); GL11.glPopMatrix(); // update variables bottomX = posX + width; // set the coords of the bottom right corner for mouse coord testing bottomY = windowY + height; }
Example 5
Source File: GuiSurgery.java From Cyberware with MIT License | 5 votes |
private void scissor(int x, int y, int xSize, int ySize) { ScaledResolution res = new ScaledResolution(mc); x = x * res.getScaleFactor(); ySize = ySize * res.getScaleFactor(); y = mc.displayHeight - (y * res.getScaleFactor()) - ySize; xSize = xSize * res.getScaleFactor(); GL11.glScissor(x, y, xSize, ySize); }
Example 6
Source File: SlytherClient.java From Slyther with MIT License | 5 votes |
private void setupDisplay() { int width = Display.getWidth(); int height = Display.getHeight(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glScissor(0, 0, width, height); GL11.glViewport(0, 0, width, height); renderHandler.init(); }
Example 7
Source File: ScrollingList.java From XRay-Mod with GNU General Public License v3.0 | 5 votes |
@Override // @mcp: func_230430_a_ = render public void func_230430_a_(MatrixStack stack, int mouseX, int mouseY, float partialTicks) { double scale = Minecraft.getInstance().getMainWindow().getGuiScaleFactor(); GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glScissor((int)(this.field_230675_l_ * scale), (int)(Minecraft.getInstance().getMainWindow().getFramebufferHeight() - ((this.field_230672_i_ + this.field_230671_e_) * scale)), (int)(this.field_230670_d_ * scale), (int)(this.field_230671_e_ * scale)); super.func_230430_a_(stack, mouseX, mouseY, partialTicks); GL11.glDisable(GL11.GL_SCISSOR_TEST); }
Example 8
Source File: GuiContext.java From WearableBackpacks with MIT License | 5 votes |
private void setScissor(ScissorRegion region) { if (region != null) { Minecraft mc = Minecraft.getMinecraft(); int scale = new ScaledResolution(mc).getScaleFactor(); GL11.glScissor(region.globalX * scale, mc.displayHeight - (region.globalY + region.height) * scale, region.width * scale, region.height * scale); GL11.glEnable(GL11.GL_SCISSOR_TEST); } else GL11.glDisable(GL11.GL_SCISSOR_TEST); }
Example 9
Source File: RenderUtil.java From seppuku with GNU General Public License v3.0 | 4 votes |
public static void glScissor(float x, float y, float x1, float y1, final ScaledResolution sr) { GL11.glScissor((int) (x * sr.getScaleFactor()), (int) (Minecraft.getMinecraft().displayHeight - (y1 * sr.getScaleFactor())), (int) ((x1 - x) * sr.getScaleFactor()), (int) ((y1 - y) * sr.getScaleFactor())); }
Example 10
Source File: TabGui.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
public void render(MatrixStack matrixStack, float partialTicks) { if(tabGuiOtf.isHidden()) return; GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glPushMatrix(); Window sr = WurstClient.MC.getWindow(); int x = 2; int y = 23; GL11.glTranslatef(x, y, 0); drawBox(0, 0, width, height); double factor = sr.getScaleFactor(); GL11.glScissor((int)(x * factor), (int)((sr.getScaledHeight() - height - y) * factor), (int)(width * factor), (int)(height * factor)); GL11.glEnable(GL11.GL_SCISSOR_TEST); int textY = 1; GL11.glEnable(GL11.GL_TEXTURE_2D); for(int i = 0; i < tabs.size(); i++) { String tabName = tabs.get(i).name; if(i == selected) tabName = (tabOpened ? "<" : ">") + tabName; WurstClient.MC.textRenderer.draw(matrixStack, tabName, 2, textY, 0xffffffff); textY += 10; } GL11.glEnable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_SCISSOR_TEST); if(tabOpened) { GL11.glPushMatrix(); GL11.glDisable(GL11.GL_TEXTURE_2D); Tab tab = tabs.get(selected); int tabX = x + width + 2; int tabY = y; GL11.glTranslatef(width + 2, 0, 0); drawBox(0, 0, tab.width, tab.height); GL11.glScissor((int)(tabX * factor), (int)((sr.getScaledHeight() - tab.height - tabY) * factor), (int)(tab.width * factor), (int)(tab.height * factor)); GL11.glEnable(GL11.GL_SCISSOR_TEST); int tabTextY = 1; GL11.glEnable(GL11.GL_TEXTURE_2D); for(int i = 0; i < tab.features.size(); i++) { Feature feature = tab.features.get(i); String fName = feature.getName(); if(feature.isEnabled()) fName = "\u00a7a" + fName + "\u00a7r"; if(i == tab.selected) fName = ">" + fName; WurstClient.MC.textRenderer.draw(matrixStack, fName, 2, tabTextY, 0xffffffff); tabTextY += 10; } GL11.glEnable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_SCISSOR_TEST); GL11.glPopMatrix(); } GL11.glPopMatrix(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_CULL_FACE); }
Example 11
Source File: GuiTextArea.java From pycode-minecraft with MIT License | 4 votes |
public void drawEditor() { String content = getString(); // first up, determine the scroll offset int xoff = textXOffset / SCROLL_SCALE; int yoff = textYOffset / SCROLL_SCALE; if (yoff > 0) { yoff = 0; textYOffset = 0; } else { int totHeight = -this.fontRenderer.FONT_HEIGHT * this.lines.length; if (totHeight < height && yoff < totHeight + height) { yoff = totHeight + height; textYOffset = yoff * SCROLL_SCALE; } } if (xoff < 0) { xoff = 0; textXOffset = 0; } else { int maxWidth = 0; for (String line : this.lines) { int w = this.fontRenderer.getStringWidth(line); if (w > maxWidth) maxWidth = w; } if (maxWidth > width && xoff > maxWidth - width) { xoff = maxWidth - width; textXOffset = xoff * SCROLL_SCALE; } } // offset rendering by the scroll offset GlStateManager.pushMatrix(); GlStateManager.translate(-xoff, yoff, 0); GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glScissor(xScissor, yScissor, wScissor, hScissor); // draw cursor int cursorPos; if (this.cursorRow == this.lines.length) { cursorPos = 0; // current line is empty } else { cursorPos = this.fontRenderer.getStringWidth(this.lines[this.cursorRow].substring(0, this.cursorColumn)); } int cursor_x = this.xPosition + cursorPos; int cursor_y = this.yPosition + this.cursorRow * this.fontRenderer.FONT_HEIGHT + 1; if (this.cursorCounter / 6 % 2 == 0) { this.fontRenderer.drawString("_", cursor_x, cursor_y, 0); } else { this.fontRenderer.drawString("_", cursor_x, cursor_y, 0x55000000); } // draw content int x = this.xPosition; int y = this.yPosition; for (String s : this.lines) { this.fontRenderer.drawString(s, x, y, 0); y += this.fontRenderer.FONT_HEIGHT; } // reset state GlStateManager.popMatrix(); GL11.glPopAttrib(); }
Example 12
Source File: ImmediateModeOGLRenderer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.opengl.renderer.SGL#glScissor(int, int, int, int) */ public void glScissor(int x, int y, int width, int height) { GL11.glScissor(x, y, width, height); }