|
|
VB.NET - game programming in vb.net using directx
|
|
|
|
|
hey guys,,,i m new for this game programming stuff.......i m following a book " game programming for teens"...they have given code for loading bitmap image but its giving me an error "INVALIDDATAEXCEPTION" In this line--- SurfaceLoader.FromFile(image, " sky.bmp", Filter.None, BLACK)
here is complete code.i m using visual studio 2005 and directx9... plz help me out
Imports Microsoft.DirectX Imports Microsoft.DirectX.Direct3D
Public Class Form1 REM define some useful constants Const SCREENW As Integer = 800 Const SCREENH As Integer = 600 Dim BLACK As Integer = RGB(0, 0, 0) REM Direct3D device variable Dim device As Direct3D.Device REM create image from a Direct3D surface Dim image As Direct3D.Surface
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load REM resize the form Me.Size = New Size(SCREENW, SCREENH) Me.Text = "Bitmap Loading Demo" Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or _ ControlStyles.Opaque, True) REM get the desktop display mode Dim adapterNumber As Integer = Manager.Adapters.Default.Adapter Dim mode As DisplayMode mode = Manager.Adapters.Default.CurrentDisplayMode REM set up the presentation parameters Dim params As New PresentParameters params.Windowed = True params.SwapEffect = SwapEffect.Copy params.AutoDepthStencilFormat = DepthFormat.D16 params.EnableAutoDepthStencil = True params.MultiSample = MultiSampleType.None params.BackBufferCount = 1 params.BackBufferWidth = SCREENW params.BackBufferHeight = SCREENH REM check video card capabilities Dim flags As CreateFlags flags = CreateFlags.HardwareVertexProcessing flags += CreateFlags.PureDevice
REM create the Direct3D device device = New Device(adapterNumber, DeviceType.Hardware, Me, flags, params) REM load the bitmap file image = device.CreateOffscreenPlainSurface(SCREENW, SCREENH, Format.A8R8G8B8, Pool.Default) SurfaceLoader.FromFile(image, " sky.bmp", Filter.None, BLACK) End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) REM begin rendering device.BeginScene() REM clear the back buffer device.Clear(ClearFlags.Target + ClearFlags.ZBuffer, Color.Green, 1.0, 0) REM specify the drawing rectangles for the image Dim source_rect As New System.Drawing.Rectangle(0, 0, SCREENW, SCREENH) Dim dest_rect As New System.Drawing.Rectangle(0, 0, SCREENW, SCREENH) REM get reference to the back buffer Dim backbuffer As Direct3D.Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono) REM draw the image device.StretchRectangle(image, source_rect, backbuffer, dest_rect, 0) REM stop rendering device.EndScene() REM copy back buffer to the screen device.Present() End Sub
End Class
|
|
|
|
|
|
|
|
|
Hi snehasoni, I'm not an expert in game programming but have done some.
It looks like the path to the image has a space at the start of the file plus you might want to supply the full path to the image.
SurfaceLoader.FromFile(image, My.Application.Info.DirectoryPath & "\sky.bmp", Filter.None, BLACK) | And just to help if you can I would recommend using PNG image files as they have much better file sizes with the same quality as BMPs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Your Details: Not Logged In
Join Date: N/A
Last Logon: N/A
Code Snippets: N/A
Code Comments:
Forum Posts: N/A
Forum Subjects: N/A
Site Wide
Code Snippets: 32
Code Comments:
Forum Posts: 52
Forum Subjects: 24
|
|
|
|
|
|
|
|
|
|
|