Help the Idiot Out (newbie)

Soupof1812
01-27-2002, 10:37 PM
Just to start off...I am a complete idiot when it comes to DirectX and DirectDraw7. I have tried some online tutorials but they confused me. I am trying to build a Game Engine.

Anyways, all this BackBuffer, Primary, Surfaces, Mainloop stuff confused me since its all modular and i am an ASP developer (we like spaghetti code).

Is there an online tutorial that goes step by step on how to use DX and really idoit-saavy commenting.

Thanks

Flyguy
01-28-2002, 02:31 AM
Have a look at this (http://visualbasicforum.com/showthread.php?s=&threadid=16901) post for some links to get you started

Soupof1812
01-28-2002, 03:07 PM
Do you have to Dim variables before u use them, that is tedious and takes too much time.

Also, does anybody have a shortcut to drawing stuff in directdraw. Like a sub to draw a picture from file to the screen with specified path, x, y, height, and width and maybe a sub that will automatically flips the primary and backbuffer and stuff.

Thanks

Soupof1812
01-28-2002, 03:09 PM
Basically something so that all i have to do is code my main loop and let the code handle all the directx stuff

reboot
01-28-2002, 03:20 PM
Do you have to Dim variables before u use them, that is tedious and takes too much time.

Anyone that doesn't dim their variables should not be allowed to own a compiler....

Squirm
01-28-2002, 05:21 PM
Originally posted by Soupof1812
Basically something so that all i have to do is code my main loop and let the code handle all the directx stuff

So you want other people to do all the hard stuff for you? Heh :rolleyes: aint gonna happen.

Soupof1812
01-28-2002, 05:45 PM
Yeah, hehe i figured

This code dont work it says Object Variable or With block not set, any ideas? I am terrible at DirectX, i know:

Dim DirectX As DirectX7
Dim DirectDraw As DirectDraw7
Dim Primary As DirectDrawSurface7
Dim Backbuffer As DirectDrawSurface7
Dim Tiles(31, 31) As DirectDrawSurface7
Dim Running As Boolean
Dim Pointer As Integer

Private Sub Form_Load()
Me.Show
InitDirectDraw
CreatePrimarySurface
CreateBackbufferSurface
LoadLvl
End Sub

Public Sub InitDirectDraw()
Set DirectDraw = DirectX.DirectDrawCreate("")
Call DirectDraw.SetCooperativeLevel(Form1.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT)
End Sub

Public Sub CreatePrimarySurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS
ddsd.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Set Primary = DirectDraw.CreateSurface(ddsd)
End Sub

Public Sub CreateBackbufferSurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
ddsd.lWidth = 640
ddsd.lHeight = 480
Set Backbuffer = DirectDraw.CreateSurface(ddsd)
End Sub

Public Sub LoadLvl()
Open "C:\Program Files\Microsoft Visual Studio\VB98\Game\start.map" For Input As #1
Pointer = 0
For Rows = 0 To 31
Input #1, TileLine
For Cols = 0 To 31
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.lWidth = 16
ddsd.lHeight = 16
TileNumber = CInt(Mid$(TileLine, Pointer + 1, 3))
Set Tiles(Cols, Rows) = DirectDraw.CreateSurfaceFromFile("C:\Program Files\Microsoft Visual Studio\VB98\Game\TileSet\" & TileNumber & ".bmp", ddsd)
Next Cols
Pointer = 0
Next Rows
End Sub

Squirm
01-28-2002, 07:04 PM
Please please please use the [/b]][/code] tags when posting code.....

My guess is your error occurs on this line:

[code]Set DirectDraw = DirectX.DirectDrawCreate("")

I suggest putting the following line right before it:

Set DirectX = New DirectX7

hotrodx
01-29-2002, 02:28 AM
Don't forget to Reference DirectX 7!

Squirm
01-29-2002, 03:39 AM
Dim Tiles(31, 31) As DirectDrawSurface7

Ouch! 1024 DirectDrawSurface7 objects. Be prepared to say bye-bye to your system RAM as this eats it up (if it will even let you). Plus I dont know if you forgot to paste it, but you need to freeup your used resources in Form_QueryUnload or something.

Soupof1812
01-29-2002, 04:13 AM
Thanks, the Tiles(31,31) is all my tiles for the game, they are only 16x16 and thats the only way i knew how to do it

Squirm
01-29-2002, 04:20 AM
Make one large surface with all the tiles on it, you can then Blt or BltFast portions of it when you require.

Soupof1812
01-29-2002, 01:02 PM
Dim DirectX As DirectX7
Dim DirectDraw As DirectDraw7
Dim Primary As DirectDrawSurface7
Dim Backbuffer As DirectDrawSurface7
Dim Tiles(31, 31) As DirectDrawSurface7
Dim Running As Boolean
Dim Pointer As Integer
Dim myRect As RECT

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
Set DirectDraw = Nothing
Set DirectX = Nothing
Unload Me
End
End If
End Sub

Private Sub Form_Load()
Me.Show
InitDirectDraw
CreatePrimarySurface
CreateBackbufferSurface
LoadLvl
End Sub

Public Sub InitDirectDraw()
Set DirectX = New DirectX7
Set DirectDraw = DirectX.DirectDrawCreate("")
Call DirectDraw.SetCooperativeLevel(Form1.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT)
End Sub

Public Sub CreatePrimarySurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS
ddsd.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Set Primary = DirectDraw.CreateSurface(ddsd)
End Sub

Public Sub CreateBackbufferSurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
ddsd.lWidth = 640
ddsd.lHeight = 480
Set Backbuffer = DirectDraw.CreateSurface(ddsd)
End Sub

Public Sub LoadLvl()
Open "C:\Program Files\Microsoft Visual Studio\VB98\Game\start.map" For Input As #1
Pointer = 0
For Rows = 0 To 31
Input #1, TileLine
For Cols = 0 To 31
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.lWidth = 16
ddsd.lHeight = 16
TileNumber = CInt(Mid$(TileLine, Pointer + 1, 3))
Set Tiles(Cols, Rows) = DirectDraw.CreateSurfaceFromFile("C:\Program Files\Microsoft Visual Studio\VB98\Game\TileSet\" & TileNumber & ".bmp", ddsd)
myRect.Top = Rows * 16
myRect.Bottom = myRect.Top + 16
myRect.Left = Cols * 16
myRect.Right = myRect.Left + 16
TileObj = Backbuffer.BltFast(myRect.Left, myRect.Top, Tiles(Cols, Rows), myRect, DDBLTFAST_WAIT)
Next Cols
Pointer = 0
Next Rows
Backbuffer.Flip
End Sub


It's not working argh! i am totally not understanding this, stupid me :mad: and how would i do that, make one large surfacE?

Thanks

Squirm
01-29-2002, 03:32 PM
Where to begin? Oh where to begin?


There is no render loop
The backbuffer is not attached to the primary
You are trying to flip the backbuffer instead of the primary
Memory is still being eaten up by those DDSurfaces
Cooperative level is set but not display mode
The primary surface has not been set up to flip
The program is not being shut down properly


Okay, time to get cracking....... :)

Before we start, can I ask you where you got this code?


A render loop

You want your game to continue to run until the user decides to quit. You use a render loop which before each render it checks to see whether it is time to end or not, using your Running flag I suppose. This could be your Form_Load event:

Private Sub Form_Load()
Me.Show
InitDirectDraw
CreatePrimarySurface
CreateBackbufferSurface
LoadLvl
Running = True

Do While Running
Render
Loop

'Put your close down code here
Unload Me
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then Running = False
End Sub


You would then create another sub called Render which would draw the stuff. You would also modify your LoadLvl sub so that it wont draw anything. Just remove the BltFast calls and the stuff about the RECT.

The backbuffer is not attached to the primary

I dont really want to explain, its best you learn things at your own pace. Basically you need to modify your CreatePrimarySurface sub:

Public Sub CreatePrimarySurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_BACKBUFFERCOUNT Or DDSD_CAPS
ddsd.ddsCaps.lCaps = DDSCAPS_COMPLEX Or DDSCAPS_FLIP Or DDSCAPS_PRIMARYSURFACE
ddsd.lBackBufferCount = 1
Set Primary = DirectDraw.CreateSurface(ddsd)
End Sub

You are trying to flip the backbuffer instead of the primary

Dont use Backbuffer.Flip and instead use Primary.Flip

Memory is still being eaten up by those DDSurfaces

You best fix to this is, as above, to place all your 'tiles' onto one surface. Basically rather than having lots of little 16x16 images, have one large 256x256 image and put all the tiles on it. One large image of this kind could hold 256 small images.

Create your bmp 256x256 and put all your little pics inside it, in rows and columns. Then just load that image into one surface.

To then draw the images, you find the row and the column of the image you want and then adjust the coordinates of the RECT variable to suit, then just BltFast or Blt as normal.

Cooperative level is set but not display mode

In your InitDirectDraw sub you need to add this line:

DirectDraw.SetDisplayMode 640, 480, 16, 0, DDSDM_DEFAULT

Change the first 3 numbers as required, of course.

The primary surface has not been set up to flip

This has been corrected above, by adding the DDSCAPS_FLIP flag

The program is not being shut down properly

First thing you need to do is restore display mode:

DirectDraw.RestoreDisplayMode
DirectDraw.SetCooperativeLevel Form1.hWnd, DDSCL_NORMAL

Next you need to set DirectDraw and DirectX = Nothing, which you have done, but also any DDSurfaces you have used, such as Primary, Backbuffer, and all your little tiles:

Set Backbuffer = Nothing
Set Primary = Nothing
Set DirectDraw = Nothing
Set DirectX = Nothing

Unload Form1



Sheesh...... :rolleyes:

Soupof1812
01-29-2002, 03:52 PM
Thank you so so much. You have helped extremely. I am just more of a kinosthetic person, i like to do things and i cant learn just by seeing the code, i need to have errors to teach me lol.

And this switch to Modular programming is hard. Plus my brain is not developed yet, i am 15 i thinks its growing slow :D

Oh and i am still confused about the Loading all the little images onto one big one. Brain not working right.

Thanks again

Squirm
01-29-2002, 04:30 PM
Close VB
Open up MSPaint
Make a new image 256x256
Open up another MSPaint
Open one of your tile images
Edit -> Select All
Edit -> Copy
Go into large MSPaint
Edit -> Paste
Repeat steps E to I until you have either filled the whole 256x256 image or have run out of tiles
Save new large image

Soupof1812
01-29-2002, 04:57 PM
That would take forever to do and each level would have to be designed in MSPaint, which wouldn't allow me to do any collision detection.

Squirm
01-29-2002, 05:09 PM
You're loading a level from a bitmap?
If so, you are approaching it from the wrong direction completely.
The idea is to have an image which contains all the possible tiles.
This image is called a tileset.
The the level files merely say which tile (by number) goes where.
Thus a change in the appearance of 1 tile is reflected automatically throughout all the levels
Plus it makes the levels easier to edit and smaller in filesize, meaning you can have larger levels.

Soupof1812
01-29-2002, 05:31 PM
here is my code:

Dim DirectX As DirectX7
Dim DirectDraw As DirectDraw7
Dim Primary As DirectDrawSurface7
Dim Backbuffer As DirectDrawSurface7
Dim TileSet As DirectDrawSurface7
Dim arrTiles(31, 31, 2) As Integer '<-- 0= X in tileset 1= y in tileset 2=boundstype
Dim Running As Boolean
Dim Pointer As Integer
Dim myRect As RECT

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then Running = False
End Sub

Private Sub Form_Load()
Me.Show
InitDirectDraw
CreatePrimarySurface
CreateBackbufferSurface
CreateTileSet
LoadLvl '<-- Makes an array of all the tilenumbers and bounds
Running = True

Do While Running
Render
Loop

DirectDraw.RestoreDisplayMode
DirectDraw.SetCooperativeLevel Form1.hWnd, DDSCL_NORMAL

Set Backbuffer = Nothing
Set Primary = Nothing
Set DirectDraw = Nothing
Set DirectX = Nothing

Unload Form1
End Sub
Public Sub LoadLvl()
Open "C:\Program Files\Microsoft Visual Studio\VB98\GAME\Start.map" For Input As #1
Pointer = 0
For Rows = 0 To 31
Input #1, TileLine
For Cols = 0 To 31
arrTiles(Cols, Rows, 0) = CInt(Mid$(TileLine, Pointer + 1, 2))
arrTiles(Cols, Rows, 1) = CInt(Mid$(TileLine, Pointer + 3, 2))
Pointer = Pointer + 5
Next Cols
Pointer = 0
Next Rows
Close #1
End Sub
Public Sub CreateTileSet()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_COMPLEX
ddsd.lWidth = 2048
ddsd.lHeight = 512
Set TileSet = DirectDraw.CreateSurfaceFromFile("C:\graal2001\pics1.bmp", ddsd)
End Sub

Public Sub InitDirectDraw()
Set DirectX = New DirectX7
Set DirectDraw = DirectX.DirectDrawCreate("")
Call DirectDraw.SetCooperativeLevel(Form1.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT)
DirectDraw.SetDisplayMode 640, 480, 16, 0, DDSDM_DEFAULT
End Sub

Public Sub CreatePrimarySurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_BACKBUFFERCOUNT Or DDSD_CAPS
ddsd.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
ddsd.lBackBufferCount = 1
Set Primary = DirectDraw.CreateSurface(ddsd)
End Sub

Public Sub CreateBackbufferSurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
ddsd.lWidth = 640
ddsd.lHeight = 480
Set Backbuffer = DirectDraw.CreateSurface(ddsd)
End Sub


Public Sub Render()
For Rows = 0 To 31
For Cols = 0 To 31
DestX = Cols * 16
DestY = Rows * 16
myRect.Top = arrTiles(Cols, Rows, 1) * 16
myRect.Left = arrTiles(Cols, Rows, 0) * 16
myRect.Bottom = myRect.Top + 16
myRect.Right = myRect.Left + 16
retVal = TileSet.BltFast(DestX, DestY, Backbuffer, myRect, DDBLTFAST_WAIT)
Next Cols
Next Rows
Primary.Flip
End Sub


It gives me an error with the CreatTileSet sub. I am using a tileset from a game called graal until i have time to design my own. Ich wiss nicht.

This is my Start.map file. Each line is a line of tiles. Each tile is 4 numbers. First two are the x in the tileset and next two are the y:

"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"
"0000000100000001000000010000000100000001000000010000000100000001000000 0100000001000000010000000100000001000000010000000100000001000000010000 00010000000100000001"

Squirm
01-29-2002, 06:08 PM
Originally posted by Soupof1812

It gives me an error with the CreatTileSet sub. I am using a tileset from a game called graal until i have time to design my own. Ich wiss nicht.

That is because the size of the surface you are trying to 'create' is 2048x512. When dealing with textures loaded from file a lot of graphics hardware only support square textures and/or textures no bigger than 256x256.

In regards to the tileset thingy and you 'map file' that is a much better approach you seem to be getting the idea. :)

Soupof1812
01-29-2002, 07:55 PM
Well i am going to have a pretty big tileset and 256x256 wont be enough. Any idears? Seperating it into quadrants?

Thanks, i am getting it :D

Oh and i tried reducing the size t o256x256 and it didnt work still

Squirm
01-30-2002, 05:37 PM
Where did you get this code?
Have you checked out DirectX 4 VB (http://64.23.12.52//TUT_DX7_DD.asp)?
Have you been to Lucky's VB DirectX (http://www.rookscape.com/vbgaming/tutorials.php)? (scroll down to DirectDraw)
Have you seen my DirectDraw tutorial (http://www.visualbasicforum.com/showthread.php?s=&threadid=12195)? (sorry about the small code)


Not giving up on you here, but you look like you're trying to run before you can walk, or even crawl :p

Soupof1812
01-30-2002, 05:41 PM
Yup, i checked em all out, i just dont understand them, as i said i learn by doing. And i am fairly experienced with VB its just this DirectX stuff that is confusing, hopefully they'll make DirectX easier in the next VB, like have the option of creating a DX application and have it visual where you create surfaces and position em and stuff, that'd be cool

Anyways, i just cant figure out what my error is. It says Automation Error

Squirm
01-30-2002, 06:10 PM
Okay, let me get this straight.....

You find you can't learn by reading, you have to learn by doing, so therefore you don't bother to learn how to do stuff and then come asking when things go wrong so others can patch up the pieces?

'I got this error'
'Do this'
'I got another error'
'Do that'

Eventually its all my own code and the result is you still havent learnt anything so will be asking for help for longer than is necessary.

:mad:

Okay, I'm telling you now, for your own good, you are jumping in at the deep end. Start with something smaller, have you even got ANYTHING to work yet? Something simple? Like just drawing a picture on screen and keeping it there until the user wants to quit? I really don't like having to say things like this, especially when dealing with DirectX, I love DirectX, but playing debugger is not my job.

And for the record, Automation Errors tend to be hardware specific. Somewhere in that code you have something that your hardware doesnt like.

Rant over...... :rolleyes:

Soupof1812
01-30-2002, 07:37 PM
Please, i am sorry :( . I fixed all the automation errors and the array is setup and everything all i need is some help on how to flip the backbuffer and primary. It just flashes the messed up image and crashes my comp please i beg of you, once i get all this fixed i wont need much help anymore since i'd know how to do everything (flipping etc).


Dim DirectX As DirectX7
Dim DirectDraw As DirectDraw7
Dim Primary As DirectDrawSurface7
Dim Backbuffer As DirectDrawSurface7
Dim TileSet As DirectDrawSurface7
Dim arrTiles(49, 29, 2) As Integer '<-- 0= X in tileset 1= y in tileset 2=boundstype
Dim Running As Boolean
Dim Pointer As Integer
Dim myRect As RECT

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then Running = False
End Sub

Private Sub Form_Load()
Me.Show
InitDirectDraw
CreatePrimarySurface
CreateBackbufferSurface
CreateTileSet
LoadLvl '<-- Makes an array of all the tilenumbers and bounds
Running = True

Do While Running
Render
Loop

DirectDraw.RestoreDisplayMode
DirectDraw.SetCooperativeLevel Form1.hWnd, DDSCL_NORMAL

Set Backbuffer = Nothing
Set Primary = Nothing
Set DirectDraw = Nothing
Set DirectX = Nothing

Unload Form1
End Sub
Public Sub LoadLvl()
Open "C:\Program Files\Microsoft Visual Studio\VB98\GAME\testdx.map" For Input As #1
Pointer = 1
For Rows = 0 To 29
Input #1, TileLine
For Cols = 0 To 49
arrTiles(Cols, Rows, 0) = CInt(Mid$(TileLine, Pointer, 2))
arrTiles(Cols, Rows, 1) = CInt(Mid$(TileLine, Pointer + 2, 2))
Pointer = Pointer + 4
Next Cols
Pointer = 1
Next Rows
Close #1
End Sub
Public Sub CreateTileSet()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd.lWidth = 256
ddsd.lHeight = 256
Set TileSet = DirectDraw.CreateSurfaceFromFile("C:\graal2001\pics3.bmp", ddsd)
End Sub

Public Sub InitDirectDraw()
Set DirectX = New DirectX7
Set DirectDraw = DirectX.DirectDrawCreate("")
Call DirectDraw.SetCooperativeLevel(Form1.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT)
DirectDraw.SetDisplayMode 640, 480, 16, 0, DDSDM_DEFAULT
End Sub

Public Sub CreatePrimarySurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_BACKBUFFERCOUNT Or DDSD_CAPS
ddsd.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
ddsd.lBackBufferCount = 1
Set Primary = DirectDraw.CreateSurface(ddsd)
End Sub

Public Sub CreateBackbufferSurface()
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
ddsd.lWidth = 640
ddsd.lHeight = 480
Set Backbuffer = DirectDraw.CreateSurface(ddsd)
End Sub


Public Sub Render()
For Rows = 0 To 29
For Cols = 0 To 49
DestX = Cols * 16
DestY = Rows * 16
myRect.Top = arrTiles(Cols, Rows, 1) * 16
myRect.Left = arrTiles(Cols, Rows, 0) * 16
myRect.Bottom = myRect.Top + 16
myRect.Right = myRect.Left + 16
retVal = Backbuffer.BltFast(DestX, DestY, TileSet, myRect, DDBLTFAST_WAIT)
Next Cols
Next Rows
Primary.Flip Nothing, DDFLIP_WAIT
myRect.Top = 0 : myRect.Left = 0
myRect.Bottom = 640 : myRect.Right = 480
Backbuffer.BltColourFill myRect, 0
End Sub

Squirm
01-31-2002, 03:04 AM
Still the backbuffer has not been setup properly. This is all incorrect:

Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
ddsd.lWidth = 640
ddsd.lHeight = 480
Set Backbuffer = DirectDraw.CreateSurface(ddsd)

Instead, this should be used:

Dim caps As DDSCAPS2
caps.lCaps = DDSCAPS_BACKBUFFER
Set Backbuffer = Primary.GetAttachedSurface(caps)

Here is a tutorial on flipping (http://64.23.12.52//Tutorials/DirectX7/DD_Flipping.asp)

Soupof1812
01-31-2002, 04:17 AM
It WORKS!!

I cant tell you how happy i am the tiles displayed just as they should.

Thank you so much. :)

Squirm
01-31-2002, 04:26 AM
Well that sure was fun :rolleyes:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum