Example #1
0
  /**
   * Initialize this ProjectedDepthTexture with the renderer
   *
   * @param r
   */
  public void init(final Renderer r) {
    // already initialized ?
    if (textureRenderer != null) {
      return;
    }

    textureRenderer = ImageUtil.createTextureRenderer(0, 0, r, true);
    if (isParallel) {
      textureRenderer.getCamera().setProjectionMode(Camera.ProjectionMode.Parallel);
    }

    // Enforce performance enhancing states on the renderer.
    // No textures or colors are required since we're only
    // interested in recording depth.
    // Also only need front faces when rendering the shadow maps

    // turn off clipping
    ClipState noClip = new ClipState();
    noClip.setEnabled(false);
    textureRenderer.enforceState(noClip);

    // turn off texturing
    TextureState noTexture = new TextureState();
    noTexture.setEnabled(false);
    textureRenderer.enforceState(noTexture);

    // turn off colors
    ColorMaskState colorDisabled = new ColorMaskState();
    colorDisabled.setAll(false);
    textureRenderer.enforceState(colorDisabled);

    // cull back faces
    CullState cullFace = new CullState();
    cullFace.setEnabled(true);
    cullFace.setCullFace(CullState.Face.Back);
    textureRenderer.enforceState(cullFace);

    // turn off lights
    LightState noLights = new LightState();
    noLights.setEnabled(false);
    textureRenderer.enforceState(noLights);

    // use flat shading
    ShadingState flat = new ShadingState();
    flat.setShadingMode(ShadingMode.Flat);
    textureRenderer.enforceState(flat);

    // disable GLSLShaderObjectsState
    GLSLShaderObjectsState glsl = new GLSLShaderObjectsState();
    glsl.setEnabled(false);
    textureRenderer.enforceState(glsl);

    // enforce the shadow offset parameters
    textureRenderer.enforceState(offsetState);

    if (texture == null) {
      createTexture();
    }
    textureRenderer.setupTexture(texture);
  }
  public static void apply(final JoglRenderer renderer, final ColorMaskState state) {
    final GL gl = GLU.getCurrentGL();

    // ask for the current state record
    final RenderContext context = ContextManager.getCurrentContext();
    final ColorMaskStateRecord record =
        (ColorMaskStateRecord) context.getStateRecord(StateType.ColorMask);
    context.setCurrentState(StateType.ColorMask, state);

    if (state.isEnabled()) {
      if (!record.isValid()
          || !record.is(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha())) {
        gl.glColorMask(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha());
        record.set(state.getRed(), state.getGreen(), state.getBlue(), state.getAlpha());
      }
    } else if (!record.isValid() || !record.is(true, true, true, true)) {
      gl.glColorMask(true, true, true, true);
      record.set(true, true, true, true);
    }

    if (!record.isValid()) {
      record.validate();
    }
  }