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

[.net] Loading textures

Started by Mr_Fhqwhgads May 27, 2006 at 1:40 AM 4 replies 750+ views
Original Post
Mr_Fhqwhgads
Mr_Fhqwhgads
I don't understand why I get errors on this line...

Texture characters = new Texture(graphics.Device, Bitmap.FromFile("graphics/wee.bmp"), Usage.DepthStencil, Pool.Default);
Error 1 The best overloaded method match for 'Microsoft.DirectX.Direct3D.Texture.Texture(Microsoft.DirectX.Direct3D.Device, System.Drawing.Bitmap, Microsoft.DirectX.Direct3D.Usage, Microsoft.DirectX.Direct3D.Pool)' has some invalid arguments C:\Documents and Settings\ryan\Desktop\RCade\frmGame.cs 21 34 RCade Error 2 Argument '2': cannot convert from 'System.Drawing.Image' to 'System.Drawing.Bitmap' C:\Documents and Settings\ryan\Desktop\RCade\frmGame.cs 21 63 RCade
Blupix Games
Mr_Fhqwhgads
Mr_Fhqwhgads
hmm...maby its becuase my device isn't being created :D. I have a picturebox, which I pass the handle to my class which initalizes Direct3D.

EXCEPTION:
Microsoft.DirectX.Direct3D.InvalidCallException was caught  Message="Error in the application."  Source="Microsoft.DirectX"  AdditionalInformation=""  ErrorCode=-2005530516  ErrorString="D3DERR_INVALIDCALL"  StackTrace:       at Microsoft.DirectX.Direct3D.Device..ctor(Int32 adapter, DeviceType deviceType, IntPtr renderWindowHandle, CreateFlags behaviorFlags, PresentParameters[] presentationParameters)       at RCade.cRenderer.initDevice() in C:\Documents and Settings\ryan\Desktop\RCade\cRenderer.cs:line 56


my params
        /// <summary>        /// Builds the PresentParameters        /// </summary>        /// <returns>True if the parameters were successfully created</returns>        private bool buildPresentParams()        {            _presentParams = new PresentParameters();            Format adaptorFormat = ( _windowed ) ? _displayMode.Format : Format.X8R8G8B8;            if(Manager.CheckDeviceFormat(0, DeviceType.Hardware, adaptorFormat, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D24S8))            {                _presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;            }            else if(Manager.CheckDeviceFormat(0, DeviceType.Hardware , adaptorFormat, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D24S8))            {                _presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;            }            else if(Manager.CheckDeviceFormat(0, DeviceType.Hardware, adaptorFormat, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D16))            {                _presentParams.AutoDepthStencilFormat = DepthFormat.D16;            }            else            {                return false;            }            _presentParams.BackBufferWidth = ( _windowed ) ? 0 : _displayMode.Width;            _presentParams.BackBufferHeight = ( _windowed ) ? 0 : _displayMode.Height;            _presentParams.BackBufferCount = 1;            _presentParams.MultiSampleType = MultiSampleType.None;            _presentParams.MultiSampleQuality = 0;            _presentParams.SwapEffect = SwapEffect.Discard;            _presentParams.DeviceWindowHandle = _windowHandle;            _presentParams.IsWindowed = _windowed;            _presentParams.EnableAutoDepthStencil = false;            _presentParams.PresentFlag = PresentFlag.DiscardDepthStencil;            _presentParams.FullScreenRefreshRateInHz = ( _windowed ) ? 0 : _displayMode.RefreshRate;            _presentParams.PresentationInterval = PresentInterval.Immediate;            return true;        }
Blupix Games
alex_myrpg
alex_myrpg
Try using TextureLoader if it's from a file. Won't solve the error probably, but it will sure speed up things.
alex_myrpg
alex_myrpg
Try using TextureLoader if it's from a file. Won't solve the error probably, but it will sure speed things up.
RipTorn
RipTorn
in your project properties, enable unmanaged debugging.
Also, go into the control panel and into the directX page, then set direct3d to the debug runtime and full debugging.
Now, when the error occurs you should get a detailed explaination in the output window.
Telastyn
Telastyn
Ugh, read the messages. System.Drawing.Bitmap.FromFile does not return a Bitmap. Thus you're trying to pass Not a Bitmap to something that expects a Bitmap and it fails.

As Alex says, TextureLoader.FromFile is a bit nicer to deal with.

Topic Locked

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

Sign in to reply to this topic.