protected void beginDrawAnnotations(DrawContext dc, OGLStackHandler stackHandler) { GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. int attributeMask = GL2.GL_COLOR_BUFFER_BIT // for alpha test func and ref, blend func | GL2.GL_CURRENT_BIT // for current color | GL2.GL_DEPTH_BUFFER_BIT // for depth test, depth mask, depth func | GL2.GL_ENABLE_BIT // for enable/disable changes | GL2.GL_HINT_BIT // for line smoothing hint | GL2.GL_LINE_BIT // for line width, line stipple | GL2.GL_TRANSFORM_BIT // for matrix mode | GL2.GL_VIEWPORT_BIT; // for viewport, depth range stackHandler.pushAttrib(gl, attributeMask); // Load a parallel projection with dimensions (viewportWidth, viewportHeight) stackHandler.pushProjectionIdentity(gl); gl.glOrtho(0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d); // Push identity matrices on the texture and modelview matrix stacks. Leave the matrix mode as modelview. stackHandler.pushTextureIdentity(gl); stackHandler.pushModelviewIdentity(gl); // Enable the alpha test. gl.glEnable(GL2.GL_ALPHA_TEST); gl.glAlphaFunc(GL2.GL_GREATER, 0.0f); // Apply the depth buffer but don't change it. if ((!dc.isDeepPickingEnabled())) { gl.glEnable(GL.GL_DEPTH_TEST); } gl.glDepthMask(false); // Disable lighting and backface culling. gl.glDisable(GL2.GL_LIGHTING); gl.glDisable(GL.GL_CULL_FACE); if (!dc.isPickingMode()) { // Enable blending in premultiplied color mode. gl.glEnable(GL.GL_BLEND); OGLUtil.applyBlending(gl, true); } else { this.pickSupport.beginPicking(dc); } }
/** * Configures the GL attached to the specified DrawContext for rendering a 2D model to a texture. The modelview * matrix is set to the identity, the projection matrix is set to an orthographic projection aligned with the * specified draw rectangle (x, y, width, height), the viewport and scissor boxes are set to the specified draw * rectangle, and the depth test and depth write flags are disabled. Because the viewport and scissor boxes are set * to the draw rectangle, only the texels intersecting the specified drawing rectangle (x, y, width, height) are * affected by GL commands. Once rendering is complete, this should always be followed with a call to {@link * #endRendering(gov.nasa.worldwind.render.DrawContext)}. * * @param dc the current DrawContext. * @param x the x-coordinate of the draw region's lower left corner. * @param y the y-coordinate of the draw region's lower left corner. * @param width the draw region width. * @param height the draw region height. * * @throws ArgumentException if the DrawContext is null. */ public void beginRendering(DrawContext dc, int x, int y, int width, int height) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. this.drawRegion = new java.awt.Rectangle(x, y, width, height); // Note: there is no attribute bit for framebuffer objects. The default framebuffer object state (object ID 0 // is bound as the current fbo) is restored in endRendering(). this.stackHandler.pushAttrib(gl, GL2.GL_COLOR_BUFFER_BIT // For clear color. | GL2.GL_DEPTH_BUFFER_BIT // For depth test and depth mask. | GL2.GL_SCISSOR_BIT // For scissor test and scissor box. | GL2.GL_TRANSFORM_BIT // For matrix mode. | GL2.GL_VIEWPORT_BIT); // For viewport state. this.stackHandler.pushTextureIdentity(gl); this.stackHandler.pushProjectionIdentity(gl); gl.glOrtho(x, x + width, y, y + height, -1, 1); this.stackHandler.pushModelviewIdentity(gl); // Disable the depth test and writing to the depth buffer. This provides consistent render to texture behavior // regardless of whether we are using copy-to-texture or framebuffer objects. For copy-to-texture, the depth // test and depth writing are explicitly disabled. For fbos there is no depth buffer components, so the depth // dest is implicitly disabled. gl.glDisable(GL.GL_DEPTH_TEST); gl.glDepthMask(false); // Enable the scissor test and set both the scissor box and the viewport to the specified region. This enables // the caller to set up rendering to a subset of the texture. Note that the scissor box defines the region // affected by a call to glClear(). gl.glEnable(GL.GL_SCISSOR_TEST); gl.glScissor(x, y, width, height); gl.glViewport(x, y, width, height); if (this.useFramebufferObject(dc)) { this.beginFramebufferObjectRendering(dc); } }