Java Code Examples for com.jme3.renderer.ViewPort#setOutputFrameBuffer()

The following examples show how to use com.jme3.renderer.ViewPort#setOutputFrameBuffer() . 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: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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.");
  	}  
}
 
Example 2
Source File: AwtPanel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void reshapeInThread(int width, int height) {
        byteBuf = BufferUtils.ensureLargeEnough(byteBuf, width * height * 4);
        intBuf = byteBuf.asIntBuffer();
        
        fb = new FrameBuffer(width, height, 1);
        fb.setDepthBuffer(Format.Depth);
        fb.setColorBuffer(Format.RGB8);
        
        if (attachAsMain){
            rm.getRenderer().setMainFrameBufferOverride(fb);
        }
        
        synchronized (lock){
            img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        }
        
//        synchronized (lock){
//            img = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(width, height);
//        }
        
        AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
        tx.translate(0, -img.getHeight());
        transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        
        for (ViewPort vp : viewPorts){
            if (!attachAsMain){
                vp.setOutputFrameBuffer(fb);
            }
            vp.getCamera().resize(width, height, true);
            
            // NOTE: Hack alert. This is done ONLY for custom framebuffers.
            // Main framebuffer should use RenderManager.notifyReshape().
            for (SceneProcessor sp : vp.getProcessors()){
                sp.reshape(vp, width, height);
            }
        }
    }
 
Example 3
Source File: AwtPanel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void attachTo(boolean overrideMainFramebuffer, ViewPort ... vps){
    if (viewPorts.size() > 0){
        for (ViewPort vp : viewPorts){
            vp.setOutputFrameBuffer(null);
        }
        viewPorts.get(viewPorts.size()-1).removeProcessor(this);
    }
    
    viewPorts.addAll(Arrays.asList(vps));
    viewPorts.get(viewPorts.size()-1).addProcessor(this);
    
    this.attachAsMain = overrideMainFramebuffer;
}
 
Example 4
Source File: SimpleWaterProcessor.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void createPreViews() {
    reflectionCam = new Camera(renderWidth, renderHeight);
    refractionCam = new Camera(renderWidth, renderHeight);

    // create a pre-view. a view that is rendered before the main view
    reflectionView = new ViewPort("Reflection View", reflectionCam);
    reflectionView.setClearFlags(true, true, true);
    reflectionView.setBackgroundColor(ColorRGBA.Black);
    // create offscreen framebuffer
    reflectionBuffer = new FrameBuffer(renderWidth, renderHeight, 1);
    //setup framebuffer to use texture
    reflectionBuffer.setDepthBuffer(Format.Depth);
    reflectionBuffer.setColorTexture(reflectionTexture);

    //set viewport to render to offscreen framebuffer
    reflectionView.setOutputFrameBuffer(reflectionBuffer);
    reflectionView.addProcessor(new ReflectionProcessor(reflectionCam, reflectionBuffer, reflectionClipPlane));
    // attach the scene to the viewport to be rendered
    reflectionView.attachScene(reflectionScene);

    // create a pre-view. a view that is rendered before the main view
    refractionView = new ViewPort("Refraction View", refractionCam);
    refractionView.setClearFlags(true, true, true);
    refractionView.setBackgroundColor(ColorRGBA.Black);
    // create offscreen framebuffer
    refractionBuffer = new FrameBuffer(renderWidth, renderHeight, 1);
    //setup framebuffer to use texture
    refractionBuffer.setDepthBuffer(Format.Depth);
    refractionBuffer.setColorTexture(refractionTexture);
    refractionBuffer.setDepthTexture(depthTexture);
    //set viewport to render to offscreen framebuffer
    refractionView.setOutputFrameBuffer(refractionBuffer);
    refractionView.addProcessor(new RefractionProcessor());
    // attach the scene to the viewport to be rendered
    refractionView.attachScene(reflectionScene);
}
 
Example 5
Source File: TestNiftyToMesh.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
   ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
   niftyView.setClearFlags(true, true, true);
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                      inputManager,
                                                      audioRenderer,
                                                      niftyView);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("all/intro.xml", "start");
    niftyView.addProcessor(niftyDisplay);

    Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
    FrameBuffer fb = new FrameBuffer(1024, 768, 1);
    fb.setDepthTexture(depthTex);

    Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);

    fb.setColorTexture(tex);
    niftyView.setClearFlags(true, true, true);
    niftyView.setOutputFrameBuffer(fb);

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
 
Example 6
Source File: HDRRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void reshape(ViewPort vp, int w, int h){
    if (mainSceneFB != null){
        renderer.deleteFrameBuffer(mainSceneFB);
    }

    mainSceneFB = new FrameBuffer(w, h, 1);
    mainScene = new Texture2D(w, h, bufFormat);
    mainSceneFB.setDepthBuffer(Format.Depth);
    mainSceneFB.setColorTexture(mainScene);
    mainScene.setMagFilter(fbMagFilter);
    mainScene.setMinFilter(fbMinFilter);

    if (msFB != null){
        renderer.deleteFrameBuffer(msFB);
    }

    tone.setTexture("Texture", mainScene);
    
    Collection<Caps> caps = renderer.getCaps();
    if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample)){
        msFB = new FrameBuffer(w, h, numSamples);
        msFB.setDepthBuffer(Format.Depth);
        msFB.setColorBuffer(bufFormat);
        vp.setOutputFrameBuffer(msFB);
    }else{
        if (numSamples > 1)
            logger.warning("FBO multisampling not supported on this GPU, request ignored.");

        vp.setOutputFrameBuffer(mainSceneFB);
    }

    createLumShaders();
}
 
Example 7
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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.");
	}  
}
 
Example 8
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {
	
	if (environment != null){
		if (environment.getApplication() != null){
			// create offscreen framebuffer
	        FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBuffer.setSrgb(true);

	        //setup framebuffer's texture
	        dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);

	        logger.config("Dual eye texture "+dualEyeTex.getName()+" ("+dualEyeTex.getImage().getId()+")");
	        logger.config("               Type: "+dualEyeTex.getType());
	        logger.config("               Size: "+dualEyeTex.getImage().getWidth()+"x"+dualEyeTex.getImage().getHeight());
	        logger.config("        Image depth: "+dualEyeTex.getImage().getDepth());
	        logger.config("       Image format: "+dualEyeTex.getImage().getFormat());
	        logger.config("  Image color space: "+dualEyeTex.getImage().getColorSpace());
	        
	        //setup framebuffer to use texture
	        out.setDepthBuffer(Image.Format.Depth);
	        out.setColorTexture(dualEyeTex);       

	        ViewPort viewPort = environment.getApplication().getViewPort();
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        viewPort.setOutputFrameBuffer(out);
		} 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.");
	}  
}
 
Example 9
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {     
	
	if (environment != null){
		if (environment.getApplication() != null){
			Camera clonecam = cam.clone();
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
	        clonecam.setParallelProjection(true);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        Picture pic = new Picture("fullscene");
	        pic.setLocalTranslation(-0.75f, -0.5f, 0f);
	        if( expand ) {
	            pic.setLocalScale(3f, 1f, 1f);
	        } else {
	            pic.setLocalScale(1.5f, 1f, 1f);            
	        }
	        pic.setQueueBucket(Bucket.Opaque);
	        pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, false);
	        viewPort.attachScene(pic);
	        viewPort.setOutputFrameBuffer(null);
	        
	        pic.updateGeometricState();
	        
	        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.");
	}  
}
 
Example 10
Source File: AwtPanel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void attachTo(boolean overrideMainFramebuffer, ViewPort... vps) {
    if (viewPorts.size() > 0) {
        for (ViewPort vp : viewPorts) {
            vp.setOutputFrameBuffer(null);
        }
        viewPorts.get(viewPorts.size() - 1).removeProcessor(this);
    }

    viewPorts.addAll(Arrays.asList(vps));
    viewPorts.get(viewPorts.size() - 1).addProcessor(this);

    this.attachAsMain = overrideMainFramebuffer;
}
 
Example 11
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {
	
	if (environment != null){
		if (environment.getApplication() != null){
	        // create offscreen framebuffer
	        FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBuffer.setSrgb(true);

	        //setup framebuffer's texture
	        dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);

	        logger.config("Dual eye texture "+dualEyeTex.getName()+" ("+dualEyeTex.getImage().getId()+")");
	        logger.config("               Type: "+dualEyeTex.getType());
	        logger.config("               Size: "+dualEyeTex.getImage().getWidth()+"x"+dualEyeTex.getImage().getHeight());
	        logger.config("        Image depth: "+dualEyeTex.getImage().getDepth());
	        logger.config("       Image format: "+dualEyeTex.getImage().getFormat());
	        logger.config("  Image color space: "+dualEyeTex.getImage().getColorSpace());
	        
	        //setup framebuffer to use texture
	        out.setDepthBuffer(Image.Format.Depth);
	        out.setColorTexture(dualEyeTex);       

	        ViewPort viewPort = environment.getApplication().getViewPort();
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        viewPort.setOutputFrameBuffer(out);
		} 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.");
  	}  
}
 
Example 12
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {   
	
	if (environment != null){
		if (environment.getApplication() != null){
	        Camera clonecam = cam.clone();
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
	        clonecam.setParallelProjection(true);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        Picture pic = new Picture("fullscene");
	        pic.setLocalTranslation(-0.75f, -0.5f, 0f);
	        if( expand ) {
	            pic.setLocalScale(3f, 1f, 1f);
	        } else {
	            pic.setLocalScale(1.5f, 1f, 1f);            
	        }
	        pic.setQueueBucket(Bucket.Opaque);
	        pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, false);
	        viewPort.attachScene(pic);
	        viewPort.setOutputFrameBuffer(null);
	        
	        pic.updateGeometricState();
	        
	        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.");
  	} 
}
 
Example 13
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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(Texture2D.MinFilter.BilinearNoMipMaps);
                offTex.setMagFilter(Texture2D.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.");
        }
    }
 
Example 14
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {

        if (environment != null) {
            if (environment.getApplication() != null) {
                // create offscreen framebuffer
                FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
                //offBuffer.setSrgb(true);

                //setup framebuffer's texture
                dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
                dualEyeTex.setMinFilter(Texture2D.MinFilter.BilinearNoMipMaps);
                dualEyeTex.setMagFilter(Texture2D.MagFilter.Bilinear);

                logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")");
                logger.config("               Type: " + dualEyeTex.getType());
                logger.config("               Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight());
                logger.config("        Image depth: " + dualEyeTex.getImage().getDepth());
                logger.config("       Image format: " + dualEyeTex.getImage().getFormat());
                logger.config("  Image color space: " + dualEyeTex.getImage().getColorSpace());

                //setup framebuffer to use texture
                out.setDepthBuffer(Image.Format.Depth);
                out.setColorTexture(dualEyeTex);

                ViewPort viewPort = environment.getApplication().getViewPort();
                viewPort.setClearFlags(true, true, true);
                viewPort.setBackgroundColor(ColorRGBA.Black);
                viewPort.setOutputFrameBuffer(out);
            } 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.");
        }
    }
 
Example 15
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupMirrorBuffers(Camera cam, Texture2D tex, boolean expand) {

        if (environment != null) {
            if (environment.getApplication() != null) {
                Camera clonecam = cam.clone();
                ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
                clonecam.setParallelProjection(true);
                viewPort.setClearFlags(true, true, true);
                viewPort.setBackgroundColor(ColorRGBA.Black);
                Picture pic = new Picture("fullscene");
                pic.setLocalTranslation(-0.75f, -0.5f, 0f);
                if (expand) {
                    pic.setLocalScale(3f, 1f, 1f);
                } else {
                    pic.setLocalScale(1.5f, 1f, 1f);
                }
                pic.setQueueBucket(Bucket.Opaque);
                pic.setTexture(environment.getApplication().getAssetManager(), tex, false);
                viewPort.attachScene(pic);
                viewPort.setOutputFrameBuffer(null);

                pic.updateGeometricState();

                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.");
        }
    }
 
Example 16
Source File: TestNiftyToMesh.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
   ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
   niftyView.setClearFlags(true, true, true);
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                      inputManager,
                                                      audioRenderer,
                                                      niftyView);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("all/intro.xml", "start");
    niftyView.addProcessor(niftyDisplay);

    Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
    FrameBuffer fb = new FrameBuffer(1024, 768, 1);
    fb.setDepthTexture(depthTex);

    Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);

    fb.setColorTexture(tex);
    niftyView.setClearFlags(true, true, true);
    niftyView.setOutputFrameBuffer(fb);

    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
 
Example 17
Source File: AWTFrameProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Reshape the current view port.
 *
 * @param width  the width.
 * @param height the height.
 */
protected void reshapeCurrentViewPort(int width, int height) {

	ViewPort viewPort = getViewPort();
	Camera camera = viewPort.getCamera();
	int cameraAngle = getCameraAngle();
	float aspect = (float) camera.getWidth() / camera.getHeight();

	if (isMain()) {
		getRenderManager().notifyReshape(width, height);
		camera.setFrustumPerspective(cameraAngle, aspect, 1f, 10000);
		return;
	}

	camera.resize(width, height, true);
	camera.setFrustumPerspective(cameraAngle, aspect, 1f, 10000);

	final List<SceneProcessor> processors = viewPort.getProcessors();

	boolean found = false;
	Iterator<SceneProcessor> iter = processors.iterator();
	while(!found && iter.hasNext()) {
		if (!(iter.next() instanceof AWTFrameProcessor)) {
			found = true;
		}
	}

	if (found) {

		FrameBuffer frameBuffer = new FrameBuffer(width, height, 1);
		frameBuffer.setDepthBuffer(Image.Format.Depth);
		frameBuffer.setColorBuffer(Image.Format.RGBA8);
		frameBuffer.setSrgb(true);

		viewPort.setOutputFrameBuffer(frameBuffer);
	}

	for (final SceneProcessor sceneProcessor : processors) {
		if (!sceneProcessor.isInitialized()) {
			sceneProcessor.initialize(renderManager, viewPort);
		} else {
			sceneProcessor.reshape(viewPort, width, height);
		}
	}
}
 
Example 18
Source File: AwtPanel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void reshapeInThread(int width, int height) {
        byteBuf = BufferUtils.ensureLargeEnough(byteBuf, width * height * 4);
        intBuf = byteBuf.asIntBuffer();

        if (fb != null) {
            fb.dispose();
            fb = null;
        }

        fb = new FrameBuffer(width, height, 1);
        fb.setDepthBuffer(Format.Depth);
        fb.setColorBuffer(Format.RGB8);
        fb.setSrgb(srgb);

        if (attachAsMain) {
            rm.getRenderer().setMainFrameBufferOverride(fb);
        }

        synchronized (lock) {
            img = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
        }

//        synchronized (lock){
//            img = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(width, height);
//        }
        AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
        tx.translate(0, -img.getHeight());
        transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

        for (ViewPort vp : viewPorts) {
            if (!attachAsMain) {
                vp.setOutputFrameBuffer(fb);
            }
            vp.getCamera().resize(width, height, true);

            // NOTE: Hack alert. This is done ONLY for custom framebuffers.
            // Main framebuffer should use RenderManager.notifyReshape().
            for (SceneProcessor sp : vp.getProcessors()) {
                sp.reshape(vp, width, height);
            }
        }
    }