Search in sources :

Example 36 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOpenVR method setupViewBuffers.

private ViewPort setupViewBuffers(Camera cam, String viewName) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // create offscreen framebuffer
            FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
            //offBufferLeft.setSrgb(true);
            //setup framebuffer's texture
            Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
            offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
            offTex.setMagFilter(Texture.MagFilter.Bilinear);
            //setup framebuffer to use texture
            offBufferLeft.setDepthBuffer(Image.Format.Depth);
            offBufferLeft.setColorTexture(offTex);
            ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                viewPort.attachScene(spatialIter.next());
            }
            //set viewport to render to offscreen framebuffer
            viewPort.setOutputFrameBuffer(offBufferLeft);
            return viewPort;
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Spatial(com.jme3.scene.Spatial) ViewPort(com.jme3.renderer.ViewPort) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 37 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class LegacyApplication method initCamera.

/**
     * Creates the camera to use for rendering. Default values are perspective
     * projection with 45° field of view, with near and far values 1 and 1000
     * units respectively.
     */
private void initCamera() {
    cam = new Camera(settings.getWidth(), settings.getHeight());
    cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(), 1f, 1000f);
    cam.setLocation(new Vector3f(0f, 0f, 10f));
    cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
    renderManager = new RenderManager(renderer);
    //Remy - 09/14/2010 setted the timer in the renderManager
    renderManager.setTimer(timer);
    if (prof != null) {
        renderManager.setAppProfiler(prof);
    }
    viewPort = renderManager.createMainView("Default", cam);
    viewPort.setClearFlags(true, true, true);
    // Create a new cam for the gui
    Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());
    guiViewPort = renderManager.createPostView("Gui Default", guiCam);
    guiViewPort.setClearFlags(false, false, false);
}
Also used : Vector3f(com.jme3.math.Vector3f) Camera(com.jme3.renderer.Camera) RenderManager(com.jme3.renderer.RenderManager)

Example 38 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class RootNodeAppState method initialize.

@Override
public void initialize(AppStateManager stateManager, Application app) {
    if (rootNode == null) {
        rootNode = new Node("Root Node");
    }
    if (viewPort == null) {
        viewPort = app.getViewPort();
    }
    viewPort.attachScene(rootNode);
    super.initialize(stateManager, app);
}
Also used : Node(com.jme3.scene.Node)

Example 39 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class ScreenshotAppState method initialize.

@Override
public void initialize(AppStateManager stateManager, Application app) {
    if (!super.isInitialized()) {
        InputManager inputManager = app.getInputManager();
        inputManager.addMapping("ScreenShot", new KeyTrigger(KeyInput.KEY_SYSRQ));
        inputManager.addListener(this, "ScreenShot");
        List<ViewPort> vps = app.getRenderManager().getPostViews();
        ViewPort last = vps.get(vps.size() - 1);
        last.addProcessor(this);
        if (shotName == null) {
            shotName = app.getClass().getSimpleName();
        }
    }
    super.initialize(stateManager, app);
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) ViewPort(com.jme3.renderer.ViewPort) InputManager(com.jme3.input.InputManager)

Example 40 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class FilterPostProcessor method initFilter.

/**
     * init the given filter
     * @param filter
     * @param vp 
     */
private void initFilter(Filter filter, ViewPort vp) {
    filter.setProcessor(this);
    if (filter.isRequiresDepthTexture()) {
        if (!computeDepth && renderFrameBuffer != null) {
            depthTexture = new Texture2D(width, height, Format.Depth24);
            renderFrameBuffer.setDepthTexture(depthTexture);
        }
        computeDepth = true;
        filter.init(assetManager, renderManager, vp, width, height);
        filter.setDepthTexture(depthTexture);
    } else {
        filter.init(assetManager, renderManager, vp, width, height);
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Aggregations

Material (com.jme3.material.Material)29 Camera (com.jme3.renderer.Camera)19 FrameBuffer (com.jme3.texture.FrameBuffer)19 Geometry (com.jme3.scene.Geometry)18 Texture2D (com.jme3.texture.Texture2D)17 ViewPort (com.jme3.renderer.ViewPort)16 Vector3f (com.jme3.math.Vector3f)14 Spatial (com.jme3.scene.Spatial)12 Box (com.jme3.scene.shape.Box)9 Node (com.jme3.scene.Node)8 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 Renderer (com.jme3.renderer.Renderer)7 Picture (com.jme3.ui.Picture)6 KeyTrigger (com.jme3.input.controls.KeyTrigger)5 Quaternion (com.jme3.math.Quaternion)5 DirectionalLight (com.jme3.light.DirectionalLight)4 SceneProcessor (com.jme3.post.SceneProcessor)4 Sphere (com.jme3.scene.shape.Sphere)4 ActionListener (com.jme3.input.controls.ActionListener)3 Vector2f (com.jme3.math.Vector2f)3