Direct3D/DirectX Scene Background Image in VB 2005

Last post 02-14-2008, 2:17 AM by The ZMan. 5 replies.
Sort Posts: Previous Next
  •  02-12-2008, 8:29 PM

    Direct3D/DirectX Scene Background Image in VB 2005

    Ladies, Gentlemen, I apologize again if this is in the wrong place. I am still learning the whole forum ideology.

    I have created a scene that I am happy for my space game, however I am having the greatest difficulty in adding a simple JPG, BMP, PNG, or TGA image to the background. I can load the image as the following example:

    bgtext = TextureLoader.FromFile(myDevice, "galaxy.jpg")

    bgtext being my texture

    However, I cannot seem to display the image on the device or the scene.  How can this be done?

    Any help, I would greatly appreciate. I can read c++ or c# code, but the game I am building is in VB 2005. Any suggestions in VB would help imensly.

    Thank you.

    M
  •  02-12-2008, 10:53 PM

    Re: Direct3D/DirectX Scene Background Image in VB 2005

    You are in the right forum... the MS guys want all non XNA GS topic in the C++ forum... yes it makes no sense to me either.

    Firstly if you didn't know  Managed DirectX is in legacy support only mode these days. If this is a new project you would be better off using XNA, even from VB its more future proof than MDX is.

    But to your problem - to draw anything with DirectX you need to draw triangles. The full screen can be represented with a quad(rilateral) or 2 triangles. This is so common that D3DX provides a Sprite API which draws textured quads. So you should be able to draw a single sprite full screen of the texture that you loaded. There is a Sprite sample in the SDK if I remember correctly.



    The ZBuffer - News and information for XNA and Managed DirectX
  •  02-13-2008, 7:09 PM

    Re: Direct3D/DirectX Scene Background Image in VB 2005

    ZMan, thank you for your reply. I am in the process of learning the XNA framework within VB. All documentation is currently in C# and the VB samples are good, but I am still learning how all fits. For example I am still attempting to understand the ContentPipeline. The learning curve might be a while.

    In the meantime, is your suggestion that I create a sprite quad and apply the texture?  My intent for the background is as follow:

    1) The scene starts with the tracking of a probe launched.
    2) The probe does a flyby on a planet.
    3) The Camera's main focuss changes to the planet as the tracking of the probe by the camera stops
    4) The background should be independent and circular to allow for the camera flowing as the probe does the flyby.

    Is this possible? Are you familiar with the game "HomeWorld 2".  I am attempting to achieve a similar environment where the camera can be panned in a circle and the background image is a long file in circular form where you do not see any "edges" similar to other sample I've seen. Here's an XNA sample, http://www.alanphipps.com/VisualBasicdotNET-XNA-3DSkyBox.html, however when you track the camera back far enough, or pan left or right far enough, you see corners.

    Any help would be greatly appreciated.

    Thank you all again.

    M
  •  02-13-2008, 7:24 PM

    Re: Direct3D/DirectX Scene Background Image in VB 2005

    Check out this blog for more VB samples http://ilovevb.net/Web/blogs/vbxna/default.aspx

    It would seem like you do need a skybox - in general the quality of the skybox is what determines  if you can see the corners. Especially in space you should be able to find a skybox that works well for you.

    If you know you are only panning left and right then you can just use several large images (usually best not to go over 2k x 2k for compatbility with all GPUs) and tile them using sprites. It might be tough to map the 3d camera to the 2d images though.

     

     



    The ZBuffer - News and information for XNA and Managed DirectX
  •  02-13-2008, 9:27 PM

    Re: Direct3D/DirectX Scene Background Image in VB 2005

    I have successfully rendered the background using the following

    at the device init routine:

    ...
                bgtext = TextureLoader.FromFile(moDevice, bgfilename)
                bgtextinfo = TextureLoader.ImageInformationFromFile(bgfilename)
                mysurf = moDevice.CreateOffscreenPlainSurface(bgtextinfo.Width, bgtextinfo.Height,_ Manager.Adapters.Default.CurrentDisplayMode.Format, Pool.Default)
                SurfaceLoader.FromFile(mysurf, bgfilename, Filter.None, 0)

    ...

    During the scene render
    ..
            moDevice.BeginScene()
            surf = moDevice.GetBackBuffer(0, 0, BackBufferType.Mono)
            moDevice.StretchRectangle(mysurf, New Rectangle(0, 0, bgtextinfo.Width, bgtextinfo.Height), surf, New Rectangle(0, 0, Manager.Adapters.Default.CurrentDisplayMode.Width, Manager.Adapters.Default.CurrentDisplayMode.Height), TextureFilter.None)
    ...

    It does the nice job of rendering a static background; however, as the camera pans I would like to have the background also pan a bit, to create the illusion of space where the stars also rotate slightly in the distance.

    Am I going about it the wrong way?

    Thanks again for your patience and help.

    M
  •  02-14-2008, 2:17 AM

    Re: Direct3D/DirectX Scene Background Image in VB 2005

    Can you not just vary the positions you draw the rectangle at? If you want real 3d rotation though you are going to have to make a quad yourself and apply a world transform to it.



    The ZBuffer - News and information for XNA and Managed DirectX
View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback