Java Code Examples for org.lwjgl.opengl.GL11#glViewport()
The following examples show how to use
org.lwjgl.opengl.GL11#glViewport() .
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: LwJglRenderingEngine.java From Gaalop with GNU Lesser General Public License v3.0 | 7 votes |
/** * Changes the size of the lwjgl window * @param w The new width of the lwjgl window * @param h The new height of the lwjgl window */ private void changeSize(float w, float h) { // Prevent a division by zero, when window is too short if (h == 0) { h = 1; } float wRatio = 1.0f * w / h; // Reset the coordinate system before modifying GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // Set the viewport to be the entire window GL11.glViewport(0, 0, (int) w, (int) h); // Set the correct perspective. GLU.gluPerspective(45.0f, wRatio, (float) near, (float) far); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GLU.gluLookAt(camPos.x, camPos.y, camPos.z, // Position camPos.x + camDir.x, camPos.y + camDir.y, camPos.z + camDir.z, // Lookat camUp.x, camUp.y, camUp.z); // Up-direction} }
Example 2
Source File: vboWithIndices.java From ldparteditor with MIT License | 6 votes |
@Override public void drawScene(float mouseX, float mouseY) { final GLCanvas canvas = cp.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(cp.getCapabilities()); } GL11.glColorMask(true, true, true, true); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); Rectangle bounds = cp.getBounds(); GL11.glViewport(0, 0, bounds.width, bounds.height); shaderProgram.use(); GL30.glBindVertexArray(VAO); // GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0); // GL20.glDisableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL30.glBindVertexArray(0); canvas.swapBuffers(); }
Example 3
Source File: vboWithRGBA.java From ldparteditor with MIT License | 6 votes |
@Override public void drawScene(float mouseX, float mouseY) { final GLCanvas canvas = cp.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(cp.getCapabilities()); } GL11.glColorMask(true, true, true, true); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); Rectangle bounds = cp.getBounds(); GL11.glViewport(0, 0, bounds.width, bounds.height); shaderProgram.use(); GL30.glBindVertexArray(VAO); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); GL30.glBindVertexArray(0); canvas.swapBuffers(); }
Example 4
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 6 votes |
private void setupOpenGL() { // Setup an OpenGL context with API version 3.2 try { PixelFormat pixelFormat = new PixelFormat(); ContextAttribs contextAtrributes = new ContextAttribs(3, 2) .withForwardCompatible(true) .withProfileCore(true); Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.setTitle(WINDOW_TITLE); Display.create(pixelFormat, contextAtrributes); GL11.glViewport(0, 0, WIDTH, HEIGHT); } catch (LWJGLException e) { e.printStackTrace(); System.exit(-1); } // Setup an XNA like background color GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f); // Map the internal OpenGL coordinate system to the entire screen GL11.glViewport(0, 0, WIDTH, HEIGHT); this.exitOnGLError("setupOpenGL"); }
Example 5
Source File: PBufferGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the GL context */ protected void initGL() { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0,0,screenWidth,screenHeight); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); enterOrtho(); }
Example 6
Source File: PerspectiveCalculator.java From ldparteditor with MIT License | 6 votes |
/** * Initializes the viewport and perspective */ public void initializeViewportPerspective() { if (c3d.getRenderer() instanceof OpenGLRenderer20) { // MARK OpenGL Viewport and Perspective Rectangle bounds = c3d.getBounds(); Rectangle scaledBounds = c3d.getScaledBounds(); GL11.glViewport(0, 0, scaledBounds.width, scaledBounds.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float viewport_width = bounds.width / View.PIXEL_PER_LDU / 2.0f; float viewport_height = bounds.height / View.PIXEL_PER_LDU / 2.0f; GL11.glOrtho(-viewport_width, viewport_width, -viewport_height, viewport_height, c3d.getzNear() * c3d.getZoom(), c3d.getzFar() * c3d.getZoom()); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); } calculateOriginData(); }
Example 7
Source File: DisplayManager.java From OpenGL-Animation with The Unlicense | 6 votes |
public static void createDisplay() { try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true); Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs); Display.setTitle(TITLE); Display.setInitialBackground(1, 1, 1); GL11.glEnable(GL13.GL_MULTISAMPLE); } catch (LWJGLException e) { e.printStackTrace(); System.err.println("Couldn't create display!"); System.exit(-1); } GL11.glViewport(0, 0, WIDTH, HEIGHT); lastFrameTime = getCurrentTime(); }
Example 8
Source File: FBOGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the GL context */ protected void initGL() { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0,0,screenWidth,screenHeight); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); enterOrtho(); }
Example 9
Source File: Overlay.java From The-5zig-Mod with MIT License | 6 votes |
private void updateScale() { GL11.glViewport(0, 0, mc.d, mc.e); GLUtil.matrixMode(GL11.GL_PROJECTION); GLUtil.loadIdentity(); GLUtil.matrixMode(GL11.GL_MODELVIEW); GLUtil.loadIdentity(); this.width = this.mc.d; this.height = this.mc.e; bca scaledResolution = new bca(this.mc, mc.d, mc.e); this.width = scaledResolution.a(); this.height = scaledResolution.b(); GLUtil.clear(256); GLUtil.matrixMode(GL11.GL_PROJECTION); GLUtil.loadIdentity(); GL11.glOrtho(0.0D, (double) width, (double) height, 0.0D, 1000.0D, 3000.0D); GLUtil.matrixMode(GL11.GL_MODELVIEW); GLUtil.loadIdentity(); GLUtil.translate(0.0F, 0.0F, -2000.0F); }
Example 10
Source File: PBufferUniqueGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the GL context */ protected void initGL() { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0,0,screenWidth,screenHeight); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); enterOrtho(); }
Example 11
Source File: TestUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Initialise the GL display * * @param width The width of the display * @param height The height of the display */ private void initGL(int width, int height) { try { Display.setDisplayMode(new DisplayMode(width,height)); Display.create(); Display.setVSyncEnabled(true); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0,0,width,height); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, width, height, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); }
Example 12
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 13
Source File: DrawOnDemandTest.java From lwjgl3-awt with MIT License | 4 votes |
public static void main(String[] args) { AWTGLCanvas canvas = new AWTGLCanvas() { private static final long serialVersionUID = 1L; @Override public void initGL() { GL.createCapabilities(); glClearColor(0.3f, 0.4f, 0.5f, 1); } @Override public void paintGL() { int w = getWidth(); int h = getHeight(); if (w == 0 || h == 0) { return; } float aspect = (float) w / h; GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glViewport(0, 0, w, h); GL11.glBegin(GL11.GL_QUADS); GL11.glColor3f(quadColor.getRed()/255f, quadColor.getGreen()/255f, quadColor.getBlue()/255f); GL11.glVertex2f(-0.75f / aspect, 0.0f); GL11.glVertex2f(0, -0.75f); GL11.glVertex2f(+0.75f / aspect, 0); GL11.glVertex2f(0, +0.75f); GL11.glEnd(); swapBuffers(); } @Override public void repaint() { if (SwingUtilities.isEventDispatchThread()) { render(); } else { SwingUtilities.invokeLater(() -> render()); } } }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(canvas, BorderLayout.CENTER); canvas.setPreferredSize(new Dimension(200, 200)); canvas.addComponentListener(new ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent e) { canvas.repaint(); }; }); JColorChooser colorChooser = new JColorChooser(quadColor); frame.getContentPane().add(colorChooser, BorderLayout.SOUTH); colorChooser.getSelectionModel().addChangeListener((e)->{ quadColor = colorChooser.getColor(); canvas.repaint(); }); SwingUtilities.invokeLater(() -> { frame.pack(); frame.setVisible(true); }); }
Example 14
Source File: CurveRenderState.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
/** * Draw a curve to the screen that's tinted with `color`. The first time * this is called this caches the image result of the curve and on subsequent * runs it just draws the cached copy to the screen. * @param color tint of the curve * @param borderColor the curve border color * @param from index to draw from * @param to index to draw to (exclusive) */ public void draw(Color color, Color borderColor, int from, int to) { float alpha = color.a; if (fbo == null) { // this should not be null, but issue #106 claims it is possible, at least 3 people had this... // debugging shows that the draw was called after discardGeometry was, which does not really make sense initFBO(); } if (lastPointDrawn != to || firstPointDrawn != from) { int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); //glGetInteger requires a buffer of size 16, even though just 4 //values are returned in this specific case IntBuffer oldViewport = BufferUtils.createIntBuffer(16); GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID()); GL11.glViewport(0, 0, fbo.width, fbo.height); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); this.renderCurve(color, borderColor, from, to, firstPointDrawn != from); lastPointDrawn = to; firstPointDrawn = from; color.a = 1f; GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb); GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3)); } // draw a fullscreen quad with the texture that contains the curve GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_TEXTURE_1D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID()); GL11.glBegin(GL11.GL_QUADS); GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha); GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex2i(fbo.width, 0); GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex2i(0, 0); GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex2i(0, fbo.height); GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex2i(fbo.width, fbo.height); GL11.glEnd(); }
Example 15
Source File: LwjglRasteriser.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void setViewport(final int x, final int y, final int width, final int height) { GL11.glViewport(x, y, width, height); }
Example 16
Source File: OffscreenRenderer.java From tribaltrouble with GNU General Public License v2.0 | 4 votes |
protected final void init() { Renderer.initGL(); GL11.glViewport(0, 0, width, height); GL11.glMatrixMode(GL11.GL_MODELVIEW); }
Example 17
Source File: OffscreenBuffer.java From LWJGUI with MIT License | 4 votes |
public void render(Context context, int x, int y, int w, int h) { if (quadShader == null) { quadShader = new GenericShader(); } float pixelRatio = LWJGUI.getThreadWindow().getPixelRatio(); x *= pixelRatio; y *= pixelRatio; GL11.glViewport(x, y,(int) (w*pixelRatio),(int) (h*pixelRatio)); quadShader.bind(); quadShader.projectOrtho(0, 0, w, h); if (quadDirty) { quadDirty = false; if (quad != null) { quad.cleanup(); } quad = new TexturedQuad(0, 0, w, h, texId); } if ( context.isCoreOpenGL() ) { if ( quad != null ) { quad.render(); } } else { GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); GL11.glBegin(GL11.GL_QUADS); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(0, 0); GL11.glVertex2f(0, 0); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(1, 0); GL11.glVertex2f(w, 0); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(1, 1); GL11.glVertex2f(w, h); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(0, 1); GL11.glVertex2f(0, h); GL11.glEnd(); } }
Example 18
Source File: OpenGLPane.java From LWJGUI with MIT License | 4 votes |
@Override public void render(Context context) { if ( !isVisible() ) return; // Check for resize Vector2i newDims = new Vector2i((int)getWidth(),(int)getHeight()); if ( !newDims.equals(oldSize) || nanoImage == -1 ) { oldSize.set(newDims); resizeBuffer(); } // FBO Rendering if ( renderer != null && nanoImage != -1 ) { NanoVG.nvgSave(context.getNVG()); //NanoVG.nvgEndFrame(context.getNVG()); { // Bind & render to FBO this.buffer.bind(); { // Background fill if ( this.internalBackground != null && isAutoClear() ) { float r = internalBackground.getRed()/255f; float g = internalBackground.getGreen()/255f; float b = internalBackground.getBlue()/255f; GL11.glClearColor(r, g, b, 1); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT); } // Viewport GL11.glViewport(0, 0, (int)getWidth(), (int)getHeight()); // Drawing NanoVG.nvgBeginFrame(internalContext.getNVG(), (int)getWidth(), (int)getHeight(), window.getPixelRatio()); //internalContext.refresh(context); renderer.render(internalContext, (int)getWidth(), (int)getHeight()); NanoVG.nvgEndFrame(internalContext.getNVG()); } this.buffer.unbind(); } // Restore nanovg NanoVG.nvgRestore(context.getNVG()); context.refresh(); // Restore glViewport // Render FBO to screen long nanovg = context.getNVG(); float x = (int)this.getX(); float y = (int)this.getY(); float w = (int)this.getWidth(); float h = (int)this.getHeight(); if ( flipY ) { y = y + h; h = -h; } try (MemoryStack stack = stackPush()) { NVGPaint imagePaint = NanoVG.nvgImagePattern(nanovg, x, y, w, h, 0, nanoImage, 1, NVGPaint.callocStack(stack)); NanoVG.nvgBeginPath(nanovg); NanoVG.nvgRect(nanovg, x, y, w, h); NanoVG.nvgFillPaint(nanovg, imagePaint); NanoVG.nvgFill(nanovg); } } // Render children super.render(context); }
Example 19
Source File: BlurPane.java From LWJGUI with MIT License | 4 votes |
@Override public void render(Context context, int x, int y, int w, int h) { if ( !isVisible() ) return; if ( this.quad == null || quadDirty ) { if ( this.quad != null ) { this.quad.cleanup(); } quad = new TexturedQuad(0, 0, w, h, source.getTexId()); } GL11.glViewport(x, y, w, h); this.quadDirty = false; quadShader.bind(); quadShader.projectOrtho(0, h, w, -h); // bind stuff GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId()); if ( internalBackground instanceof BackgroundSolid ) { BackgroundSolid bg = (BackgroundSolid)internalBackground; GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uColor"), bg.getColor().getRed()/255f-0.5f, bg.getColor().getGreen()/255f-0.5f, bg.getColor().getBlue()/255f-0.5f, bg.getColor().getAlpha()/255f); } GL20.glUniform1f(GL20.glGetUniformLocation(quadShader.getProgram(), "uBlurSize"), blurRadius); GL20.glUniform2f(GL20.glGetUniformLocation(quadShader.getProgram(), "uTexelSize"), 1.0f/(float)w, 1.0f/(float)h); GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uCornerRadii"), (float)Math.max(BlurPane.this.getBorderRadii()[0], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[1], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[2], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[3], 0.1)); // Draw quad if ( context.isCoreOpenGL() ) { if ( quad != null ) { quad.render(); } } else { GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId()); GL11.glBegin(GL11.GL_QUADS); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(0, 0); GL11.glVertex2f(0, 0); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(1, 0); GL11.glVertex2f(w, 0); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(1, 1); GL11.glVertex2f(w, h); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glTexCoord2f(0, 1); GL11.glVertex2f(0, h); GL11.glEnd(); } }
Example 20
Source File: Fbo.java From LowPolyWater with The Unlicense | 3 votes |
/** * Bind the FBO so that it can be rendered to. Anything rendered while the * FBO is bound will be rendered to the FBO. * * @param colourIndex * - The index of the colour buffer that should be drawn to. */ public void bindForRender(int colourIndex) { // should add support for binding multiple colour attachments GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0 + colourIndex); GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, fboId); GL11.glViewport(0, 0, width, height); }