Charrua Posted June 11, 2014 Share Posted June 11, 2014 as the topic say. render, clears any 2d graphics already drawn. in blitz, this is done with: CameraClsMode Camera, 0, 1 is there any way/technique in LE of doing this? thank's Juan Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
Ma-Shell Posted June 11, 2014 Share Posted June 11, 2014 Sadly, there doesn't seem to be any official way for doing so. This has been discussed in http://www.leadwerks.com/werkspace/topic/9676-camera-layers/ and http://www.leadwerks.com/werkspace/topic/9464-rendering-backgroundsforegrounds/ where the latter one shows a work-around, but I would definitely be interested in an official statement from Josh to this, since in my opinion it was a great strength of LE2.5 that you could say something like: world1->Render(); world2->Render(); context->RenderLighting(); And having the lighting calculated in screenspace only ONCE (not for both render-calls), since this is the way a deferred renderer works (http://www.leadwerks.com/files/Deferred_Rendering_in_Leadwerks_Engine.pdf) Quote Link to comment Share on other sites More sharing options...
Charrua Posted June 11, 2014 Author Share Posted June 11, 2014 thank's for your fast response. i'll read carefully the other threads and see what happens, but being watched them on the fly i guess that there is no solution, atm. i need this feature, guess it will be implemented soon. Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
Ma-Shell Posted June 11, 2014 Share Posted June 11, 2014 I hope so, too. The workaround presented in my second link has some serious drawbacks, as the lighting is calculated multiple times and some antialiasing-artifacts can be seen, but it works (kind of). Quote Link to comment Share on other sites More sharing options...
Charrua Posted June 11, 2014 Author Share Posted June 11, 2014 well, i get what i was looking for! i made simple changes on the code posted by Shadmar (thxs! http://www.leadwerks.com/werkspace/topic/9464-rendering-backgroundsforegrounds/#entry72636 i need just a photograph behind and the capability of render 3d objects over it. here is the code: #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Vec3 camerarotation; #if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS) bool freelookmode = true; #else bool freelookmode = false; #endif World* backworld = NULL; Buffer* foreground = NULL; Buffer* background = NULL; Texture* backtex = NULL; Texture* fortex = NULL; Texture* backImg = NULL; bool App::Start() { //Initialize Steamworks (optional) /*if (!Steamworks::Initialize()) { System::Print("Error: Failed to initialize Steam."); return false; }*/ //Create a window window = Leadwerks::Window::Create("cpp_worlds"); //Create a context context = Context::Create(window); //Create a world world = World::Create(); backworld = World::Create(); //create buffer for background background = Buffer::Create(context->GetWidth(), context->GetHeight(), 1, 0, 0); backtex = Texture::Create(context->GetWidth(), context->GetHeight(), Texture::RGBA, 0, 1, 0); //create buffer for foreground foreground = Buffer::Create(context->GetWidth(), context->GetHeight(), 1, 1, 0); fortex = Texture::Create(context->GetWidth(), context->GetHeight(), Texture::RGBA, 0, 1, 0); //create camera for the foreground World::SetCurrent(world); camera = Camera::Create(); camera->Move(0, 2, -5); //Hide the mouse cursor window->HideMouse(); //Load the map std::string mapname = System::GetProperty("map", "Maps/start.map"); Map::Load(mapname); //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth() / 2, context->GetHeight() / 2); //load the background image backImg = Texture::Load("Materials/backgrounds/backImg.tex"); return true; } bool App::Loop() { //Close the window to end the program if (window->Closed()) return false; //Press escape to end freelook mode if (window->KeyHit(Key::Escape)) { if (!freelookmode) return false; freelookmode = false; window->ShowMouse(); } if (freelookmode) { //Keyboard movement float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Leadwerks::Time::GetSpeed() * 0.05; float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Leadwerks::Time::GetSpeed() * 0.05; camera->Move(strafe, 0, move); //Get the mouse movement float sx = context->GetWidth() / 2; float sy = context->GetHeight() / 2; Vec3 mouseposition = window->GetMousePosition(); float dx = mouseposition.x - sx; float dy = mouseposition.y - sy; //Adjust and set the camera rotation camerarotation.x += dy / 10.0; camerarotation.y += dx / 10.0; camera->SetRotation(camerarotation); //Move the mouse to the center of the screen window->SetMousePosition(sx, sy); } Leadwerks::Time::Update(); background->Enable(); // draw the background image context->DrawImage(backImg, 0, 0); background->Disable(); //Render foreground foreground->Enable(); world->Update(); world->Render(); foreground->Disable(); //Draw both worlds. context->Enable(); context->SetBlendMode(Blend::Alpha); context->DrawImage(background->GetColorTexture(), 0, 0); context->DrawImage(foreground->GetColorTexture(), 0, 0); context->SetBlendMode(Blend::Solid); context->Sync(false); return true; } and the result: ok, nothing but a box on it, but this feature is what i was looking for thank's again Juan 1 Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
gamecreator Posted June 12, 2014 Share Posted June 12, 2014 Thank you for sharing the code! Quote Link to comment Share on other sites More sharing options...
Rick Posted June 12, 2014 Share Posted June 12, 2014 Yeah, was just thinking what you are asking for is kinda just like a skybox Quote Link to comment Share on other sites More sharing options...
Charrua Posted June 12, 2014 Author Share Posted June 12, 2014 i realize that 2 worlds aren't needed. i already have an image for background, so i don't need a background world to render. i simplify the code above (with no mouse look) and with only one world basically what is needed is a buffer to render 3d objects and a background image, the magic is done combining the 2 images with //Draw image, then foreground context->Enable(); context->SetBlendMode(Blend::Alpha); context->DrawImage(backImg, 0, 0); context->DrawImage(foreground->GetColorTexture(), 0, 0); context->SetBlendMode(Blend::Solid); here the code: #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Buffer* foreground = NULL; Texture* backImg = NULL; bool App::Start() { //Create a window window = Leadwerks::Window::Create("cpp_worlds"); //Create a context context = Context::Create(window); //Create a world world = World::Create(); //create buffer for foreground foreground = Buffer::Create(context->GetWidth(), context->GetHeight(), 1, 1, 0); //create camera for the foreground World::SetCurrent(world); camera = Camera::Create(); camera->Move(0, 2, -5); //Hide the mouse cursor //window->HideMouse(); //Load the map std::string mapname = System::GetProperty("map", "Maps/start.map"); Map::Load(mapname); //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth() / 2, context->GetHeight() / 2); //load the background image backImg = Texture::Load("Materials/backgrounds/backImg.tex"); return true; } bool App::Loop() { //Close the window to end the program if (window->Closed()) return false; //Render foreground foreground->Enable(); world->Update(); world->Render(); foreground->Disable(); //Draw image, then foreground context->Enable(); context->SetBlendMode(Blend::Alpha); context->DrawImage(backImg, 0, 0); context->DrawImage(foreground->GetColorTexture(), 0, 0); context->SetBlendMode(Blend::Solid); context->Sync(false); return true; } btw, where is the buffer documentation? i understand what is happening but i wish to read/know wich other functions/methods are available for buffers 1 Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
shadmar Posted June 12, 2014 Share Posted June 12, 2014 You can look in classes/buffer.h Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Charrua Posted June 12, 2014 Author Share Posted June 12, 2014 ha!, that's the hard way, i was looking for an easier one but's better than nothing! thxs Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
Recommended Posts
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.