@Override public FrameBufferCubemap build () { return new FrameBufferCubemap(this); } }
/** Bind the side, making it active to render on. Should be called in between a call to {@link #begin()} and {@link #end()}. * @param side The side to bind */ protected void bindSide (final Cubemap.CubemapSide side) { Gdx.gl20.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, getColorBufferTexture().getTextureObjectHandle(), 0); }
/** Bind the next side of cubemap and return false if no more side. Should be called in between a call to {@link #begin()} and * #end to cycle to each side of the cubemap to render on. */ public boolean nextSide () { if (currentSide > 5) { throw new GdxRuntimeException("No remaining sides."); } else if (currentSide == 5) { return false; } currentSide++; bindSide(getSide()); return true; }
public void renderScene() { Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); // Render scene to screen super.render(); // Render scene to cubemap camFb.position.set(cam.position); camFb.near = cam.near; camFb.far = cam.far; fb.begin(); while( fb.nextSide() ) { fb.getSide().getUp(camFb.up); fb.getSide().getDirection(camFb.direction); camFb.update(); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); modelBatch.begin(camFb); for (ModelInstance instance : instances) modelBatch.render(instance, lights); if (space != null) modelBatch.render(space); modelBatch.end(); } fb.end(); }
@Override public void create () { super.create(); camFb = new PerspectiveCamera(90, 800, 800); camFb.position.set(10f, 10f, 10f); camFb.lookAt(0, 0, 0); camFb.near = 0.1f; camFb.far = 1000f; camFb.update(); fb = new FrameBufferCubemap(Format.RGBA8888, 800, 800, true); cubemap = fb.getColorBufferTexture(); ObjLoader objLoader = new ObjLoader(); cubeMesh = objLoader.loadModel(Gdx.files.internal("data/cube.obj")); cubeInstance = new ModelInstance(cubeMesh); cubeBatch = new ModelBatch(Gdx.files.internal("data/shaders/cubemap-vert.glsl"), Gdx.files.internal("data/shaders/cubemap-frag.glsl")); cubeInstance.materials.get(0).set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap)); camCube = new PerspectiveCamera(67, Gdx.graphics.getWidth()*0.5f, Gdx.graphics.getHeight()*0.5f); camCube.position.set(0f, 2f, 2f); camCube.lookAt(0, 0, 0); camCube.near = 1f; camCube.far = 300f; camCube.update(); }
/** Creates a new FrameBuffer having the given dimensions and potentially a depth and a stencil buffer attached. * * @param format the format of the color buffer; according to the OpenGL ES 2.0 spec, only RGB565, RGBA4444 and RGB5_A1 are * color-renderable * @param width the width of the cubemap in pixels * @param height the height of the cubemap in pixels * @param hasDepth whether to attach a depth buffer * @param hasStencil whether to attach a stencil buffer * @throws com.badlogic.gdx.utils.GdxRuntimeException in case the FrameBuffer could not be created */ public FrameBufferCubemap (Pixmap.Format format, int width, int height, boolean hasDepth, boolean hasStencil) { FrameBufferCubemapBuilder frameBufferBuilder = new FrameBufferCubemapBuilder(width, height); frameBufferBuilder.addBasicColorTextureAttachment(format); if (hasDepth) frameBufferBuilder.addBasicDepthRenderBuffer(); if (hasStencil) frameBufferBuilder.addBasicStencilRenderBuffer(); this.bufferBuilder = frameBufferBuilder; build(); }
/** Creates a new FrameBuffer having the given dimensions and potentially a depth and a stencil buffer attached. * * @param format the format of the color buffer; according to the OpenGL ES 2.0 spec, only RGB565, RGBA4444 and RGB5_A1 are * color-renderable * @param width the width of the cubemap in pixels * @param height the height of the cubemap in pixels * @param hasDepth whether to attach a depth buffer * @param hasStencil whether to attach a stencil buffer * @throws com.badlogic.gdx.utils.GdxRuntimeException in case the FrameBuffer could not be created */ public FrameBufferCubemap (Pixmap.Format format, int width, int height, boolean hasDepth, boolean hasStencil) { FrameBufferCubemapBuilder frameBufferBuilder = new FrameBufferCubemapBuilder(width, height); frameBufferBuilder.addBasicColorTextureAttachment(format); if (hasDepth) frameBufferBuilder.addBasicDepthRenderBuffer(); if (hasStencil) frameBufferBuilder.addBasicStencilRenderBuffer(); this.bufferBuilder = frameBufferBuilder; build(); }
/** Bind the next side of cubemap and return false if no more side. Should be called in between a call to {@link #begin()} and * #end to cycle to each side of the cubemap to render on. */ public boolean nextSide () { if (currentSide > 5) { throw new GdxRuntimeException("No remaining sides."); } else if (currentSide == 5) { return false; } currentSide++; bindSide(getSide()); return true; }
@Override public FrameBufferCubemap build () { return new FrameBufferCubemap(this); } }
/** Bind the side, making it active to render on. Should be called in between a call to {@link #begin()} and {@link #end()}. * @param side The side to bind */ protected void bindSide (final Cubemap.CubemapSide side) { Gdx.gl20.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, getColorBufferTexture().getTextureObjectHandle(), 0); }
/** Creates a new FrameBuffer having the given dimensions and potentially a depth and a stencil buffer attached. * * @param format the format of the color buffer; according to the OpenGL ES 2.0 spec, only RGB565, RGBA4444 and RGB5_A1 are * color-renderable * @param width the width of the cubemap in pixels * @param height the height of the cubemap in pixels * @param hasDepth whether to attach a depth buffer * @param hasStencil whether to attach a stencil buffer * @throws com.badlogic.gdx.utils.GdxRuntimeException in case the FrameBuffer could not be created */ public FrameBufferCubemap (Pixmap.Format format, int width, int height, boolean hasDepth, boolean hasStencil) { FrameBufferCubemapBuilder frameBufferBuilder = new FrameBufferCubemapBuilder(width, height); frameBufferBuilder.addBasicColorTextureAttachment(format); if (hasDepth) frameBufferBuilder.addBasicDepthRenderBuffer(); if (hasStencil) frameBufferBuilder.addBasicStencilRenderBuffer(); this.bufferBuilder = frameBufferBuilder; build(); }
/** Bind the next side of cubemap and return false if no more side. Should be called in between a call to {@link #begin()} and * #end to cycle to each side of the cubemap to render on. */ public boolean nextSide () { if (currentSide > 5) { throw new GdxRuntimeException("No remaining sides."); } else if (currentSide == 5) { return false; } currentSide++; bindSide(getSide()); return true; }
@Override public FrameBufferCubemap build () { return new FrameBufferCubemap(this); } }
/** Bind the side, making it active to render on. Should be called in between a call to {@link #begin()} and {@link #end()}. * @param side The side to bind */ protected void bindSide (final Cubemap.CubemapSide side) { Gdx.gl20.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, side.glEnum, getColorBufferTexture().getTextureObjectHandle(), 0); }