Rendering on a part of the screen

Started by Yerst, August 14, 2013, 05:57:00 PM

Previous topic - Next topic

Yerst

Hey!
Is there a way of rendering only on a part of the screen?
I have a blitted game menu and i would like to show a preview of the current selected item (in 3D) on it.

EgonOlsen

You could render it into a texture and blit that.

Yerst

#2
So, this is the code i'm using:
fb.blit(this.submenu_background, 0, 0, 0, 0, 512, 256, width, height, -1, false);
fb.blit(this.preview, 0, 0, 300, 50, preview_width, preview_height, preview_width, preview_height, -1, false);
fb.setRenderTarget(preview);
fb.display();
fb.removeRenderTarget();

It works for a size of 512*256, but at 512*257 i get a "Can't render into a texture larger than the current framebuffer!" exception.
I tried resizing the framebuffer without success.

Where should i render the world?

EgonOlsen

512*257 isn't a valid texture size anyway. You seem to be using OpenGL ES 1.x, which is limited when it some to render targets. Consider to switch to ES 2.0 and maximum size restrictions will go away (they still should be powers of two unless you are using NPOTTexture, which i would try to avoid if possible).

Yerst

#4
How do i switch to OpenGL ES 2.0 ?

//EDIT: Ok, i think i will just use a 128*128 Texture and scale it up to my needs.
But i have still problems with rendering the world.
When i render it after i set the render target, everything gets bigger. Looks like it would zoom in.

fb.blit(this.submenu_background, 0, 0, 0, 0, 512, 256, width, height, -1, false);
fb.blit(this.preview, 0, 0, (int)(width/1.72), (int)(height/11), preview_width, preview_height, (int)(width/2.53), (int)(height/1.5), -1, false);
fb.setRenderTarget(preview);
//world.renderScene(fb); When i enable this, everything gets bigger
fb.display();
fb.removeRenderTarget();

EgonOlsen

That's most likely because the render target is square and your screen isn't and the fov adjusts itself accordingly. You can try to play around with the fov settings and/or the virtual dimension settings in FrameBuffer.

Yerst

To be honest, i have no idea what setVirtualDimensions does. I just set it to my screen size and it doesn't zoom in anymore.
But i have still problems with my render target. I tried rendering a skybox (just to test it) when my render target is set to my texture, but it doesn't show the result it wanted.

fb.blit(this.submenu_background, 0, 0, 0, 0, 512, 256, width, height, -1, false);
fb.setVirtualDimensions(width,height);
fb.setRenderTarget(preview);
skyBox.render(world, fb);
world.renderScene(fb);
fb.display();
fb.removeRenderTarget();
fb.blit(this.preview, 0, 0, (int)(width/1.72), (int)(height/11), preview_width, preview_height, (int)(width/2.53) , (int)(height/1.5), -1, false);

Screenshot (i think you know where it should be):

EgonOlsen

I'm not sure what i'm seeing there...however, i'm missing some clear calls. After setting the render target, shouldn't there be some call to clear to start with an empty texture?

Yerst

You see the Skybox i rendered in the upper left corner, but it should be on the window at the right.
I did this now:

fb.setVirtualDimensions(width,height);
fb.setRenderTarget(preview);
fb.clear();
skyBox.render(world, fb);
world.renderScene(fb);
fb.removeRenderTarget();
fb.blit(this.submenu_background, 0, 0, 0, 0, 512, 256, width, height, -1, false);
fb.blit(this.preview, 0, 0, (int)(width/1.72), (int)(height/11), preview_width, preview_height, (int)(width/2.53) , (int)(height/1.5), -1, false);

And the skybox is gone.
The texture is where it should be, it is just black (like it wouldn't render at the texture at all.
Even if i clear it with another color, it is black...

EgonOlsen

When using OpenGL ES 1.x, render to texture is done via an indirection. It will be rendered into the framebuffer and then copied into the texture. That's why your skybox appears in the upper left corner. The order should be something like this:


...
fb.setRenderTarget(preview);
fb.clear();
skyBox.render(world, fb);
fb.removeRenderTarget();
fb.clear();
world.renderScene(fb);
world.draw(fb);
"blit preview"