Author Topic: Rendering on a part of the screen  (Read 3012 times)

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Rendering on a part of the screen
« on: August 14, 2013, 05:57:00 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Rendering on a part of the screen
« Reply #1 on: August 14, 2013, 08:08:06 pm »
You could render it into a texture and blit that.

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Rendering on a part of the screen
« Reply #2 on: August 15, 2013, 12:42:32 pm »
So, this is the code i'm using:
Code: [Select]
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?
« Last Edit: August 15, 2013, 01:17:46 pm by Yerst »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Rendering on a part of the screen
« Reply #3 on: August 16, 2013, 04:41:42 pm »
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).

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Rendering on a part of the screen
« Reply #4 on: August 16, 2013, 06:14:33 pm »
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.
Code: [Select]
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();
« Last Edit: August 16, 2013, 07:01:00 pm by Yerst »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Rendering on a part of the screen
« Reply #5 on: August 16, 2013, 07:35:18 pm »
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.

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Rendering on a part of the screen
« Reply #6 on: August 18, 2013, 12:38:57 pm »
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.
Code: [Select]
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):

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Rendering on a part of the screen
« Reply #7 on: August 18, 2013, 07:53:46 pm »
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?

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Rendering on a part of the screen
« Reply #8 on: August 19, 2013, 01:33:32 pm »
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:
Code: [Select]
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Rendering on a part of the screen
« Reply #9 on: August 19, 2013, 01:48:07 pm »
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:

Code: [Select]
...
fb.setRenderTarget(preview);
fb.clear();
skyBox.render(world, fb);
fb.removeRenderTarget();
fb.clear();
world.renderScene(fb);
world.draw(fb);
"blit preview"