private GTexture getTexture() { if (_texture == null) { _texture = initializeTexture(); if ((_texture == null) || !_texture.hasGLTexture()) { return null; } _textureWidth = _texture.getWidth(); _textureHeight = _texture.getHeight(); } return _texture; }
@Override public void render(final DrawContext dc) { // _lastDC = dc; runFrameWorkers(); final GTexture texture = getTexture(); if ((texture == null) || !texture.hasGLTexture()) { return; } final GL gl = dc.getGL(); gl.glPushAttrib( GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_TEXTURE_BIT | GL.GL_TRANSFORM_BIT | GL.GL_VIEWPORT_BIT | GL.GL_CURRENT_BIT); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glDisable(GL.GL_DEPTH_TEST); // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight) // into the GL projection matrix. final Rectangle viewport = dc.getView().getViewport(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); final double maxwh = Math.max(_textureWidth, _textureHeight); gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); // Translate and scale final float scale = computeScale(viewport); final Vec4 locationSW = computeLocation(viewport, scale); gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z()); // Scale to 0..1 space gl.glScalef(scale, scale, 1f); gl.glScaled(_textureWidth, _textureHeight, 1d); _lastScreenBounds = calculateScreenBounds(viewport, locationSW, scale); texture.enable(); texture.bind(); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); gl.glColor4f(1, 1, 1, calculateOpacity()); dc.drawUnitQuad(texture.getImageTexCoords()); texture.disable(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); gl.glPopAttrib(); }