Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

I have continued to play around with loading embeded resource data files and have come up with a alternative way to create a D3DTexture from an embeded resource image. This new method seems more apropreate. (To me at least :p )

If you are wondering why I am loading embeded resource images rather than simply loading and creating a D3D texture from a file, it is because external files can be lost and can result in you app not being able to run. Not that I will be doing this for every app I write!

    Protected Friend Function LoadResource(ByVal ResourceName As String) As IO.MemoryStream
        Dim ResourceStream As IO.Stream

        ResourceStream = Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(ResourceName)

        If ResourceStream Is Nothing Then Return Nothing
        Dim byts(CInt(ResourceStream.Length - 1)) As Byte
        Dim Len As Integer = ResourceStream.Read(byts, 0, CInt(ResourceStream.Length))

        Dim MemStream As New IO.MemoryStream(byts, 0, Len)
        Return MemStream
    End Function

    Protected Friend Function LoadResourceImage(ByVal ResourceImageName As String) As Direct3D.Texture
        Dim Mem As IO.MemoryStream
        Mem = LoadResource(ResourceImageName)       

        ' attempt to load/create image we saved to memory stream
        Dim Tex As Direct3D.Texture
        Tex = Direct3D.TextureLoader.FromStream(mobjGraphics.Device, Mem)
 
        ' done with varibles
        Mem.Close()
        Mem = Nothing  

        ' return reference to texture
        Return Tex
    End Function

Add comment



biuquote
  • Comment
  • Preview
Loading






Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume