Jump to content

SetRenderTarget (to texture) strange behavior?


Charrua
 Share

Recommended Posts

I was trying to render to a texture without success.

Texture shows always the same no matter the camera position/rotation...

 

I roll back to the RenderToTexture Lua example, wrote it for cpp and works ok, then i realize that:

 

 

1) If the texture is not applied to a material then the rendered texture is what the camera sees when at it's starting position/rotation : 0,0,0 / 0,0,0

 

2) if the texture is applied to a material, and this material is applied to an object, the rendered texture is ok if the object is visible by the camera, if not, then the rendered texture is again what the camera sees on the default position.

 

The documentation says:

 

" The texture can be used in a material and applied to an object, or drawn onscreen. "

 

but if not applied to a material, it does not render, and if applied to a material then it mus be applied to an object visible by the camera.

 

following is a cpp to test, with the commented lines (with //) the example do not work

if applied to the box works ok until you uncomment the line that moves it outside the view range of the camera.

 

perhaps this is the intended behavior and i am missing something obvious.

 

What I need is to render to a texture with the intention of draw it with context->DrawImage. I do no plan to place a visible object with the texture in front of the camera.

 

is it possible to render to a texture without applying it to an object with a materila with it?

 

thank's in advance

 

 

Juan

 

#include "App.h"
using namespace Leadwerks;
App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
App::~App() { delete world; delete window; }
Model* model = NULL;
Camera* camera2;
Pivot* pivot;
Material* mtl;
Texture* tex;

bool App::Start()
{
window = Window::Create("render to textue",0,0,1024,768);
context = Context::Create(window);
world = World::Create();
camera = Camera::Create();
camera->Move(0, 0, -3);
Map::Load("Maps/start.map");
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
camera2 = Camera::Create();
camera2->Move(0, 0, -4);
camera2->SetClearColor(1, 0, 0);

pivot = Pivot::Create();
camera2->SetParent(pivot);
pivot->SetPosition(-2, 2, 1);
tex = Texture::Create(256, 512);
mtl = Material::Create();
mtl->SetShader("Shaders/Model/Diffuse.shader");
mtl->SetTexture(tex);
camera2->SetRenderTarget(tex);
model = Model::Box();
//model->SetPosition(0, -4, 0); //if not visible: render texture gets freezed
//model->SetMaterial(mtl); //if material is not applied to a visible object render texture gets freezed
model = Model::Cylinder();
model->SetColor(0.0, 1.0, 0.0);
model->SetPosition(0, 0, 0);
model = Model::Cone();
model->SetColor(0.0, 0.0, 1.0);
model->SetPosition(2, 0, 0);
return true;
}
bool App::Loop()
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
pivot->Turn(0, Time::GetSpeed(), 0);
Time::Update();
world->Update();
world->Render();
context->DrawImage(tex, 10, 10);
context->Sync();
return true;
}

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

thank's

 

aside of another problems i have... now is working if and only if the boxes that has the textures are not hidden

 

if i hide a box, then it's texture isn't updated

 

based on the "intended behavior" (not so logical to me) sounds ok, because if the system do not update a texture of an object outside the view of the camera, then it will not render a texture of a hidden box.

 

the documentation refers that the texture "can" be used in a material and applied to an object, or draw on screen" i understand from that that "can" is not "must" (but my English is terrible).

 

any way, our language (english spanish etc) isn't so exact as computer languages :) so my problem is not with documentation, knowing what is possible to do and what isn't is what i need.

 

i was working with buffers, doing a world::render for each one and then getting the texture from the buffer, doing some handling on the texture (cropping it mostly) and then drawing each processed texture.

 

Started doing cropping by hand (memcpy) and reaching a 14 fps on my laptop

then as pointed by macklebee (thank's man) i starting to try a shader to do so

http://www.leadwerks.com/werkspace/topic/12537-drawing-a-section-of-a-2d-texture-setting-uv-coords/#entry90453

after some mistakes of mine (use to have lots) i make it work and fps rise up to 28

 

so, i starting to ask, what about render to a texture instead of render to a buffer...

well if i render to textures i'm having 12 fps (worse than using by hand texture copy, crop: handling) and i have to have in front of the camera boxes with those textures on it (not supposed to be)

 

probably i'm still doing something wrong, but for now i'll keep with buffers + shader

 

thank's for your help

 

Juan

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...