Horde3D

Next-Generation Graphics Engine
It is currently 13.05.2024, 05:04

All times are UTC + 1 hour




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: 21.05.2008, 12:02 
Offline

Joined: 14.04.2008, 15:06
Posts: 183
Location: Germany
I hadn't tested this, yet - just thought it should work that way.
But you are right, I get now the same results here with split screen. :(

no tests, so far:
The solution is probably rendering the views to different textures and displaying these at the appropriate locations.
Another idea: It should be possible to create "subwindows" with their own (but shared) OpenGL context. That way you are using different windows with separate buffers and it should work.


Top
 Profile  
Reply with quote  
PostPosted: 21.05.2008, 19:58 
Offline

Joined: 14.04.2008, 15:06
Posts: 183
Location: Germany
I've tested a splitscreen approach with one window subdivided into two viewports. It's a "bit" ugly...
So the idea is the following. Create three cameras for two viewports. The second camera will render the left viewport, the third camera the right viewport. These two cameras render into special texture resources which will be rendered by the first camera using overlays.
This solution is probably far from being optimal...

add resource function:
Code:
self._h3dres.splitscreen1 = h3d.createTexture2D('splitscreen-1', 0, 400, 600, True)
self._h3dres.splitscreen2 = h3d.createTexture2D('splitscreen-2', 0, 400, 600, True)
self._h3dres.splitscreen1Mat = h3d.addResource(h3d.ResourceTypes.Material, 'splitscreen1.material.xml', 0)
self._h3dres.splitscreen1Mat = h3d.addResource(h3d.ResourceTypes.Material, 'splitscreen2.material.xml', 0)


splitscreenN.material.xml (with N=1,2):
Code:
<Material>
        <Shader source="overlay.shader.xml"/>

        <TexUnit unit="0" map="splitscreen-N" />
</Material>

The map name must be the name of the texture resource above. It would probably be better to generate this file inside your program to allow any number of viewports without having to create these files.

setup camera:
Code:
self.camera = h3d.addCameraNode(h3d.RootNode, name, pipeRes) # renders complete window
h3d.setNodeTransform(self.camera, 0, 0, -100, 0, 0, 0, 1, 1, 1)

self.camera1 = h3d.addCameraNode(h3d.RootNode, '%s-1' % name, pipeRes) # left view
h3d.setNodeTransform(self.camera1, 0, 0, -100, 0, 0, 0, 1, 1, 1)
h3d.setNodeParami(self.camera1, h3d.CameraNodeParams.OutputTex, self._app._h3dres.splitscreen1)
h3d.setupCameraView(self.camera1, 45, 400 / 600.0, 0.1, 1000)

self.camera2 = h3d.addCameraNode(h3d.RootNode, '%s-2' % name, pipeRes) # right view
h3d.setNodeTransform(self.camera2, 0, 0, -100, 0, 0, 0, 1, 1, 1)
h3d.setNodeParami(self.camera2, h3d.CameraNodeParams.OutputTex, self._app._h3dres.splitscreen2)
h3d.setupCameraView(self.camera2, 45, 400 / 600.0, 0.1, 1000)


rendering:
Code:
h3d.utils.showText('%s' % (self._fpsString), 0, 0.95, 0.03, 0, self._h3dres.fontMaterial) # only on left split screen
h3d.showOverlay(0.75, 0, 0, 0, 1, 0, 1, 0, 1, 0.2, 1, 1, 0.75, 0.2, 0, 1, 7, self._h3dres.logoMaterial)
h3d.render(w.camera1)
h3d.clearOverlays()

h3d.showOverlay(0.75, 0, 0, 0, 1, 0, 1, 0, 1, 0.2, 1, 1, 0.75, 0.2, 0, 1, 7, self._h3dres.logoMaterial)
h3d.render(w.camera2)
h3d.clearOverlays()

h3d.showOverlay(
                # x y u v
                0, 0, 0, 0, # lower left
                0.5, 0, 1, 0, # lower right
                0.5, 1, 1, 1, # upper right
                0, 1, 0, 1, # upper left
                6,
                self._h3dres.splitscreen1Mat)
h3d.showOverlay(
                # x y u v
                0.5 + 0, 0, 0, 0, # lower left
                0.5 + 0.5, 0, 1, 0, # lower right
                0.5 + 0.5, 1, 1, 1, # upper right
                0.5 + 0, 1, 0, 1, # upper left
                6,
                self._h3dres.splitscreen2Mat)
h3d.render(w.camera)

h3d.clearOverlays()


Top
 Profile  
Reply with quote  
PostPosted: 21.05.2008, 23:34 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
wobaa666 wrote:
Code:
   
Horde3D::resize( 0, 0, (float) _width / 2.0f, _height );
Horde3D::setupCameraView( _cam0, 45.0f, (float)_width / _height, 0.1f, 1000.0f ); // _width should be _width/2.0f

Horde3D::resize( (float) _width / 2.0f, 0, _width, _height ); // _width should be _width/2.0f
Horde3D::setupCameraView( _cam1, 45.0f, (float) _width / _height, 0.1f, 1000.0f ); // _width should be _width/2.0f

With this code, the left half of the render window is black, while the right is rendered correctly. If I swap code blocks its the other way round.

You have a few minor problems, though none of them are causing the black viewport. Horde3D::resize takes x, y, width, height - rather than a min/max pair, so divide the width by 2 for the second call as well. Similarly for the setupCameraView, or you will have a lot of distortion - check my comments in the code above.

The problem is instead a bug in Horde itself - or rather a lack of a feature nobody ever needed before. Horde3D::resize() results in a call to glViewport, which merely sets viewport transform - it doesn't clip to the viewport.

So when you try to render the second camera, and the pipeline executes the clear command, it clears the whole screen (not just the viewport). To allow this to work as you intend, we need to set the Scissor Rectangle to the same as the viewport, and then enable the scissor test.

I don't have time today, or I would submit a patch :(

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 23.05.2008, 11:15 
Offline

Joined: 14.04.2008, 15:06
Posts: 183
Location: Germany
swiftcoder wrote:
I don't have time today, or I would submit a patch :(

It would be great if you could write a patch in the near future.


Top
 Profile  
Reply with quote  
PostPosted: 13.06.2008, 11:14 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
The glClear should now consider the viewport settings. I just integrated a patch into the SVN trunk.


Top
 Profile  
Reply with quote  
PostPosted: 14.06.2008, 15:43 
Offline

Joined: 14.04.2008, 15:06
Posts: 183
Location: Germany
I've had some time to test it: It's working - even in combination with multiple windows.


Top
 Profile  
Reply with quote  
PostPosted: 11.08.2011, 23:58 
Offline

Joined: 11.08.2011, 23:52
Posts: 1
BUMP! has there been an implementation addressing the multiple view problem yet? What is the best way to achieve this now?


Top
 Profile  
Reply with quote  
PostPosted: 04.10.2011, 03:48 
Offline

Joined: 07.11.2009, 16:07
Posts: 5
Has there been any further work on multiple viewports done? Could someone please post some updates?


Top
 Profile  
Reply with quote  
PostPosted: 06.10.2011, 14:05 
Offline

Joined: 07.11.2009, 16:07
Posts: 5
I tried to add multiple viewports using something simple like the code below:
Code:
struct DWViewPort
{
   DWCamera* pCamera;
   int offset[2];
   int extents[2];
   bool isActive;
   
   DWViewPort()
   {
      pCamera = NULL;
      offset[0] = 0;
      offset[1] = 0;
      extents[0] = 0;
      extents[1] = 0;
      isActive = false;
   }   
};

class DWWindowManager
{   
   std::vector<DWViewPort*> m_viewPorts;      

public:
   DWWindowManager();
   ~DWWindowManager();
   int addViewport(DWCamera* camera, const int offset[2], const int extents[2]);
};

int DWWindowManager::addViewport(DWCamera* camera, const int offset[2], const int extents[2])
{
   DWViewPort* pNewViewport = new DWViewPort();
   pNewViewport->pCamera = camera;
   pNewViewport->offset[0] = offset[0];
   pNewViewport->offset[1] = offset[1];
   pNewViewport->extents[0] = extents[0];
   pNewViewport->extents[1] = extents[1];
   
   m_viewPorts.push_back(pNewViewport);
   int retIndex = m_viewPorts.size()-1;
   resizeViewport(retIndex, offset, extents);
   return retIndex;
}


void DWWindowManager::resizeViewport(const int indx, const int offsets[2], const int extents[2])      
{
   DWViewPort* pView = m_viewPorts[indx];
   DWCamera* pCamera = pView->pCamera;
   
   // Resize viewport
   h3dSetNodeParamI(pCamera->getHandle(), H3DCamera::ViewportXI, offsets[0]);
   h3dSetNodeParamI(pCamera->getHandle(), H3DCamera::ViewportYI, offsets[1]);
   h3dSetNodeParamI(pCamera->getHandle(), H3DCamera::ViewportWidthI,extents[0]);
   h3dSetNodeParamI(pCamera->getHandle(), H3DCamera::ViewportHeightI,extents[1]);      
}


void DWWindowManager::update()
{
        //Timer and event handling code
        ...
   
   std::vector<DWViewPort*>::iterator iter;
   for(iter=m_viewPorts.begin(); iter != m_viewPorts.end(); iter++)
   {
      // Render scene
      h3dRender((*iter)->pCamera->getHandle());      
   }
   
   // Finish rendering of frame
   h3dFinalizeFrame();      

   // Remove all overlays
   //h3dClearOverlays();
   
   // Write all messages to log file
   h3dutDumpMessages();   
   
   mp_sfmlWindow->Display();
}


The last viewport always gets drawn correctly.
Here's a screenshot of how it looks (note the second viewport at the right top corner):Image

It looks like some glitch in clearing the OpenGL buffers. Any ideas of how to get around this? Am I doing something in the wrong order?


Top
 Profile  
Reply with quote  
PostPosted: 06.10.2011, 20:40 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
Judging from the code, you are using SFML, right?
I don't know if this will help you, but JTippetts wrote here that using SFML with horde has some quirks. You should save OpenGL states before h3dInit (sf::Window::SaveGLStates()), because horde changes them the way it wants, and then
Quote:
call sf::Window::RestoreGLStates() preparatory to drawing anything in SFML. After you restore states, call sf::Window::SaveGLStates() one last time to push the state back onto the stack preparatory to the next iteration of the loop.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group