Home    
Log In    
Share Code    
Join    

Navigation
 Skip Navigation Links.

Forums
Skip Navigation Links.

Search

 

Advertisement
 

VB.NET - game programming in vb.net using directx

View RSS Feeds
  Post By Time             Answer
  snehasoni 27/05/2009 13:58:08 Question
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
 
  Post By Time             Answer
  ptaylor 07/06/2009 12:19:02 Assist
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

 




 
 
Welcome Guest
 
  Log In Name
 
  Password
 
 
Statistics
Your Details: Not Logged In
  Join Date: N/A
  Last Logon: N/A
  Code Snippets: N/A
  Code Comments: N/A
  Forum Posts: N/A
  Forum Subjects: N/A

Site Wide
  Code Snippets: 32
  Code Comments: 2
  Forum Posts: 52
  Forum Subjects: 24
 
Random Code
Boolean Like Variables
When you type a Boolean you get a selection of Ans....

Language: VB.NET

 
Advertisement


All the Source Code and Tutorials on this site are free for you to use as you require.