Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to load a mesh in two or more windows?

Started by ICUP Jan 24, 2012 at 9:33 AM 2 replies 1.5k views
Original Post
ICUP
ICUP
Can meshes not be loaded once and drawn in two viewports? How can meshes be shown in two or more viewports? I'm able to get a mesh drawn in one window, but if it tries to draw in a second, I get this error:

"Both a vertex shader and pixel shader must be set on the device before any draw operations may be performed."

If I only draw in one viewport, it works fine and the meshes show up.
Evil Steve
Evil Steve
For multiple viewports you should have a single device, whereas you appear to be creating one per viewport. You can choose what to render to by using the various parameters to Present().
ICUP
ICUP
Thanks Steve.

I'm new to C# and XNA (come from a C++, SDL background). Can you give me a little more detail on how to use it? I'm looking at the msdn documentation right now and I'm not sure how to use one of the three overloaded methods.
Starnick
Starnick
If you're going to be working with XNA, you should take a look at the XNA Winforms sample:

http://create.msdn.c...nforms_series_1

As Steve said, it's generally a good idea to have a "one device, multiple window" setup. So all your content (models, textures, etc - anything associated with the device) exist in one context. Its then a matter of drawing your geometry and presenting it to the appropriate window.

An example: You have a model editor with four views, each view is its own control that you're rendering to (and they're attached to a Form). You'll be drawing the same geometry four times, and each time presenting to a different view. An alternative way would be using a single window, and each time you render the scene, you're rendering to only a section of the window (the area of the surface you're rendering to doesn't actually have to be the whole surface, here's an XNA tutorial illustrating what I mean).

Now using XNA to render to different windows can get a little hairy (which is why I referred to the start of the Winform XNA tutorials). The graphics device also owns the "swapchain" (back/front buffer sequence) so it's going to be a shared resource between your windows which can be a problem for windows with different sizes. The XNA winforms example deals with this by resizing the backbuffer to the current largest window size, and each time you're presenting you're only using a subset of the backbuffer.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.