XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

tile-based rendering ?

Last post 7/9/2009 5:16 PM by Winterhell. 3 replies.
  • 7/9/2009 2:46 PM

    tile-based rendering ?

      Hi,my game is in 3D and i'm running in some memory shortages due to my render targets, and i'd like to render in several passes different parts of the screen (similar to split-screen ).
     
      The problem is i'm not very experienced with  viewports and projection matrices,and I need tips how to modify them.
     
       So, can anyone shed some light ? Even if just for the easiest version,equal split in 4 quadrants and render one at a time.
     
      I dont care that much if it'll be slow or whatever, I may use it just for high resolution screenshots for prints .
  • 7/9/2009 4:08 PM In reply to

    Re: tile-based rendering ?

    go into game studio express. press F1. look for the split screen example provided.
  • 7/9/2009 4:17 PM In reply to

    Re: tile-based rendering ?

    Hi

    I'm not sure if I understand you right, but what your're trying to do is something like splitscreen or a minimap? In that case what you have to do is render the scene to a texture and then display that texture on the screen.

    // Global definitions  
    Texture 2D tex;                   // the texture to render to  
    RenderTarget2D target;            // the render target  
    const int texturesize = 512;      // the size of the texture; change this for a higher resolution, but a too high resolution only uses more performance and if your render the texture onto the screen then it's useless to have a texture that has a higher resolution than the screen.  
     
    // Initialize game  
    // ...  
    target = new RenderTarget2D(GraphicsDevice, texturesize, texturesize, 0, SurfaceFormat.Color);      // create a new render target  
    // ...  
     
    // Draw game  
    // ...  
    using (RenderTarget2D oldrendertarget = (RenderTarget2D)GraphicsDevice.GetRenderTarget(0))   // save the old render target, if you don't render normally at all (= only with textures) it's not really needed  
    {  
       GraphicsDevice.SetRenderTarget(0, target);  // change the target  
     
       // Your draw code for the first texture here  
     
       GraphicsDevice.ResolveRenderTarget(0);  // save the drawn image to the target  
       GraphicsDevice.SetRenderTarget(0, oldrendertarget);  // sets the target back to the old one  
    }  
    tex = target.GetTexture();
     
    spriteBatch.Begin();  
    spriteBatch.Draw(tex, new Rectangle(x, y, width, height), Color.White) // render the image in the tex-variable directly to the screen  
    spriteBatch.End(); 

    You could also make a special keypress function and only then render the scene to the texture, instead of doing it every frame (example: Screenshot).
    If you call "target.GetTexture()" before you call "GraphicsDevice.ResolveRenderTarget(...)" you will get an error.

    If you want to make four different tiles (= 4 different textures) then just repeat the same as above for 3 more and change the coordinates in the "spriteBatch.Draw(...)" function.
    Do you want to know what I'm working on? Click here
  • 7/9/2009 5:16 PM In reply to

    Re: tile-based rendering ?

    No no,thats not it.
    I know how render targets work,and split screen .
     My problem is that i want to render portions of the screen.
    Say the video card supports rendering to 4k * 2k textures,
     but I need a 8 k * 4 k screenshot , I need to render the 4 parts of the scene .
    Then I'll output them to file and in some program will combine them.
    The problem lies with perspective corrections, If I use orthogonal projection the new image will look exactly as if it were
    natively rendered in 8k * 4k .  But my game uses perspective, so there'll be a problem with the vanishing points,
    they'll be at the center of the tiles,not a the center of the bigger image.
Page 1 of 1 (4 items) Previous Next