Jump to content

is it possible to draw an image as background and render over it?


Charrua
 Share

Recommended Posts

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)

Link to comment
Share on other sites

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.

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

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:

background.png

 

ok, nothing but a box on it, but this feature is what i was looking for

 

thank's again

 

Juan

  • Upvote 1

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

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

  • Upvote 1

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...