PDA

Click to See Complete Forum and Search --> : passing surfacename to function


spandex44
Jul 28th, 2001, 05:29 PM
Hi,
I am developing a crude graphics engine in VB. I am currently writing code to load and display bitmaps. However, I am having troubles passing the name of a new surface to a function. Check out the code below:

----------
Sub Game_Loop()
Call Load_Bitmap(16, 16, Tile_Dirt, "/tile1.bmp")
Call Draw_Bitmap(100, 100, Tile_Dirt)
End Sub

Sub Load_Bitmap(Width As Integer, Height As Integer, Bitmap_Surface_Name As DirectDrawSurface7, Bitmap_Path As String)
Dim Bitmap_Surface_Name As DirectDrawSurface7
Set Bitmap_Surface_Name = Nothing
ddsd2.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH 'default flags
ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd2.lWidth = Width
ddsd2.lHeight = Height
'this is where the surface is created. You use the DDraw object to create a
'surface from the specified file name using the above description.
Set Bitmap_Surface_Name = dd.CreateSurfaceFromFile(App.Path & Bitmap_Path, ddsd2)
End Sub

Sub Draw_Bitmap(X_Coor As Integer, Y_Coor As Integer, Surface_Name As DirectDrawSurface7)
Dim ddrval As Long
rBack.Bottom = ddsd3.lHeight
rBack.Right = ddsd3.lWidth
ddrval = backbuffer.BltFast(X_Coor, Y_Coor, Surface_Name, rBack, DDBLTFAST_WAIT)
End Sub
----------

When the application launches I receive an error message saying "Variable not decfined" referring to Tile_Dirt from these lines of code:
Call Load_Bitmap(16, 16, Tile_Dirt, "/tile1.bmp")
Call Draw_Bitmap(100, 100, Tile_Dirt)

This is probably just a basic programming question, but I need to know how to pass the surface name to these functions. Thanks a lot!
Alexander

Zaei
Jul 29th, 2001, 01:52 AM
Sub Game_Loop()
Dim Tile_Dirt as DirectDrawSurface7
Call Load_Bitmap(16, 16, Tile_Dirt, "/tile1.bmp")
Call Draw_Bitmap(100, 100, Tile_Dirt)
End Sub

Sub Load_Bitmap(Width As Integer, Height As Integer, Bitmap_Surface_Name As DirectDrawSurface7, Bitmap_Path As String)
Set Bitmap_Surface_Name = Nothing
ddsd2.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH 'default flags
ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd2.lWidth = Width
ddsd2.lHeight = Height
'this is where the surface is created. You use the DDraw object to create a
'surface from the specified file name using the above description.
Set Bitmap_Surface_Name = dd.CreateSurfaceFromFile(App.Path & Bitmap_Path, ddsd2)
End Sub


You never defined the Tile_Dirt Surface in the calling function. Basically, what you are doing is defining a surface that you want to use in the calling function (Game_Loop()), and passing a reference to the function "Load_Bitmap". When "Load_Bitmap" is finished, Tile_Dirt, in the calling function is a loaded bitmap file.

If you dont already understand these concepts, you may want to consider getting really familiar with Visual Basic Itself, and how it works under the covers. I assume you are using Cut-and-Pasted code, and don't understand it fully. If you learn the basics first, you wont be confused by simple things later on.

I dont mean to put you down or anything, but it will save you much time when things get really complicated.

Z.

spandex44
Jul 30th, 2001, 04:35 PM
Thanks for your response.

I actually wrote the code myself. I wanted to create a function that I can use to create surfaces during runtime, so that I don't need predefined surfaces.

I'm learning everything there is to learn from www.vbexplorer.com/directx4vb because there dont seem to be ANY books that cover DirectX programming in Visual Basic. Do you know of any?

I appreciate your help.

Zaei
Jul 30th, 2001, 04:56 PM
I don't use VB much anymore, and I don't use DX7 at all =). I don't know of any books that teach DirectX programming with VB, but the site you are using is great.

Z.