Advertisement

Need some help in this code

Started by December 09, 2000 10:43 AM
5 comments, last by caesarweb 24 years, 1 month ago
I have a picture tiles.bmp. It displays a blank screen. Please help me, it doesn''t work, I don''t know what to do: Dim odirectx As New DirectX7 Dim oDDSDPrimary As DDSURFACEDESC2 Dim oPrimary As DirectDrawSurface7 Dim caps As DDSCAPS2 Dim oSprite As DirectDrawSurface7 Dim oDDSD As DDSURFACEDESC2 Dim aColorKey As DDCOLORKEY Dim oBackBuffer As DirectDrawSurface7 Dim SrcRect As RECT Dim ClearRect As RECT Dim DestRect As RECT Dim map As DirectDrawSurface7 Dim dmap As DDSURFACEDESC2 Dim bgrect As RECT Dim grrect As RECT Dim bltrect As RECT Dim x As Integer Dim y As Integer Dim f As Integer Dim odirectdraw As DirectDraw7 Private Sub Form_Click() endsub End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyEscape Then endsub End Sub Private Sub Form_Load() Me.Show Set odirectdraw = odirectx.DirectDrawCreate("") Call odirectdraw.SetCooperativeLevel(Me.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT) Call odirectdraw.SetDisplayMode(1024, 768, 16, 0, DDSDM_DEFAULT) oDDSDPrimary.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT oDDSDPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX oDDSDPrimary.lBackBufferCount = 1 Set oPrimary = odirectdraw.CreateSurface(oDDSDPrimary) caps.lCaps = DDSCAPS_BACKBUFFER Set oBackBuffer = oPrimary.GetAttachedSurface(caps) oDDSD.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT oDDSD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN oDDSD.lWidth = 50 oDDSD.lHeight = 600 Set oSprite = odirectdraw.CreateSurfaceFromFile(App.Path & "\maps\tiles.bmp", oDDSD) dmap.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH dmap.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN dmap.lWidth = 2048 dmap.lHeight = 1536 Set map = odirectdraw.CreateSurface(dmap) With grrect .Top = 300 .Bottom = 350 .Left = 0 .Right = 50 End With With SrcRect .Top = 0 .Bottom = 768 .Left = 0 .Right = 0 End With With ClearRect ClearRect.Top = 0 ClearRect.Bottom = 768 ClearRect.Right = 0 ClearRect.Left = 1024 End With With DestRect .Top = 0 .Bottom = 768 .Left = 0 .Right = 1024 End With With bltrect .Left = 0 .Top = 0 .Right = 0 + 50 .Bottom = 0 + 50 End With y = 0 f = 0 oBackBuffer.BltColorFill DestRect, RGB(0, 0, 0) For j = 1 To 40 For i = 1 To 30 bltrect.Top = x bltrect.Bottom = x + 50 map.Blt bltrect, oSprite, grrect, DDBLT_WAIT bltrect.Top = x + 50 x = x + 50 bltrect.Bottom = x + 50 bltrect.Left = f bltrect.Right = f + 50 Next f = f + 48 x = 0 Next oBackBuffer.Blt DestRect, map, SrcRect, DDBLT_WAIT oPrimary.Flip Nothing, DDFLIP_WAIT End Sub Sub endsub() Me.Show Set oBackBuffer = Nothing Set oPrimary = Nothing Call odirectdraw.RestoreDisplayMode Call odirectdraw.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL) End End Sub
A young man with lots of talents
Hey dude, when you put source code in a post, put it directly in the field, and just enclose it with
    
tags. Gamedev will automatically format it for you. Granted, the color formating is for C/C++, but it will give you a nice, legible table.

----------------------------------------
Implementation is everything. Period.
Particle Toast
----------------------------------------Implementation is everything. Period.
Advertisement
No offense but what was the point in that if you still can''t see the tags? I actually have no clue how to make my code show up all pretty like that so would someone please say how (use [] instead of angle brackets so it doesn''t do that).

-Goku
SANE Productions Homepage
Enclosing code in source tags does work, but you can only do it once. Multiple source tags screw things up.

To use the source tags do this:

[source]
// Your code here...
#include <stdio.h>

//...etc...

[/source]

Note: The above was not converted into a code block because I used HTML to display the square and angle brackets. If I'd type the above directly into my message it would have looked like this:

    // Your code here...#include <stdio.h>//...etc...  


Edited by - Moot on December 12, 2000 10:42:53 AM
So the code that ceasarweb wanted help with looks something like this:



Dim odirectx As New DirectX7
Dim oDDSDPrimary As DDSURFACEDESC2
Dim oPrimary As DirectDrawSurface7
Dim caps As DDSCAPS2
Dim oSprite As DirectDrawSurface7
Dim oDDSD As DDSURFACEDESC2
Dim aColorKey As DDCOLORKEY
Dim oBackBuffer As DirectDrawSurface7
Dim SrcRect As RECT
Dim ClearRect As RECT
Dim DestRect As RECT
Dim map As DirectDrawSurface7
Dim dmap As DDSURFACEDESC2
Dim bgrect As RECT
Dim grrect As RECT
Dim bltrect As RECT
Dim x As Integer
Dim y As Integer
Dim f As Integer
Dim odirectdraw As DirectDraw7
Private Sub Form_Click()
endsub

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then endsub

End Sub

Private Sub Form_Load()
Me.Show
Set odirectdraw = odirectx.DirectDrawCreate("")
Call odirectdraw.SetCooperativeLevel(Me.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT)
Call odirectdraw.SetDisplayMode(1024, 768, 16, 0, DDSDM_DEFAULT)
oDDSDPrimary.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
oDDSDPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
oDDSDPrimary.lBackBufferCount = 1
Set oPrimary = odirectdraw.CreateSurface(oDDSDPrimary)
caps.lCaps = DDSCAPS_BACKBUFFER
Set oBackBuffer = oPrimary.GetAttachedSurface(caps)
oDDSD.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
oDDSD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
oDDSD.lWidth = 50
oDDSD.lHeight = 600
Set oSprite = odirectdraw.CreateSurfaceFromFile(App.Path & "\maps\tiles.bmp", oDDSD)
dmap.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH

dmap.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
dmap.lWidth = 2048
dmap.lHeight = 1536
Set map = odirectdraw.CreateSurface(dmap)
With grrect
.Top = 300
.Bottom = 350
.Left = 0
.Right = 50
End With
With SrcRect
.Top = 0
.Bottom = 768
.Left = 0
.Right = 0
End With
With ClearRect
ClearRect.Top = 0
ClearRect.Bottom = 768
ClearRect.Right = 0
ClearRect.Left = 1024
End With
With DestRect
.Top = 0
.Bottom = 768
.Left = 0
.Right = 1024
End With
With bltrect
.Left = 0
.Top = 0
.Right = 0 + 50
.Bottom = 0 + 50
End With
y = 0
f = 0

oBackBuffer.BltColorFill DestRect, RGB(0, 0, 0)

For j = 1 To 40

For i = 1 To 30
bltrect.Top = x
bltrect.Bottom = x + 50
map.Blt bltrect, oSprite, grrect, DDBLT_WAIT
bltrect.Top = x + 50
x = x + 50
bltrect.Bottom = x + 50
bltrect.Left = f
bltrect.Right = f + 50
Next

f = f + 48
x = 0
Next


oBackBuffer.Blt DestRect, map, SrcRect, DDBLT_WAIT




oPrimary.Flip Nothing, DDFLIP_WAIT

End Sub

Sub endsub()
Me.Show

Set oBackBuffer = Nothing
Set oPrimary = Nothing
Call odirectdraw.RestoreDisplayMode
Call odirectdraw.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)

End
End Sub

here is his code a little cleaner..

  Dim odirectx As New DirectX7 Dim oDDSDPrimary As DDSURFACEDESC2Dim oPrimary As DirectDrawSurface7Dim caps As DDSCAPS2Dim oSprite As DirectDrawSurface7Dim oDDSD As DDSURFACEDESC2Dim aColorKey As DDCOLORKEYDim oBackBuffer As DirectDrawSurface7Dim SrcRect As RECTDim ClearRect As RECTDim DestRect As RECTDim map As DirectDrawSurface7Dim dmap As DDSURFACEDESC2Dim bgrect As RECTDim grrect As RECTDim bltrect As RECTDim x As IntegerDim y As IntegerDim f As IntegerDim odirectdraw As DirectDraw7Private Sub Form_Click()endsubEnd SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = vbKeyEscape Then endsubEnd SubPrivate Sub Form_Load()Me.ShowSet odirectdraw = odirectx.DirectDrawCreate("")Call odirectdraw.SetCooperativeLevel(Me.hWnd, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT)Call odirectdraw.SetDisplayMode(1024, 768, 16, 0, DDSDM_DEFAULT)oDDSDPrimary.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNToDDSDPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEXoDDSDPrimary.lBackBufferCount = 1Set oPrimary = odirectdraw.CreateSurface(oDDSDPrimary)caps.lCaps = DDSCAPS_BACKBUFFERSet oBackBuffer = oPrimary.GetAttachedSurface(caps)oDDSD.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHToDDSD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAINoDDSD.lWidth = 50oDDSD.lHeight = 600Set oSprite = odirectdraw.CreateSurfaceFromFile(App.Path & "\maps\tiles.bmp", oDDSD)dmap.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTHdmap.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAINdmap.lWidth = 2048dmap.lHeight = 1536Set map = odirectdraw.CreateSurface(dmap)With grrect.Top = 300.Bottom = 350.Left = 0.Right = 50End WithWith SrcRect.Top = 0.Bottom = 768.Left = 0.Right = 0End WithWith ClearRectClearRect.Top = 0ClearRect.Bottom = 768ClearRect.Right = 0ClearRect.Left = 1024End WithWith DestRect.Top = 0.Bottom = 768.Left = 0.Right = 1024End WithWith bltrect.Left = 0.Top = 0.Right = 0 + 50.Bottom = 0 + 50End Withy = 0f = 0oBackBuffer.BltColorFill DestRect, RGB(0, 0, 0)For j = 1 To 40For i = 1 To 30bltrect.Top = xbltrect.Bottom = x + 50map.Blt bltrect, oSprite, grrect, DDBLT_WAITbltrect.Top = x + 50x = x + 50bltrect.Bottom = x + 50bltrect.Left = fbltrect.Right = f + 50Nextf = f + 48x = 0NextoBackBuffer.Blt DestRect, map, SrcRect, DDBLT_WAIToPrimary.Flip Nothing, DDFLIP_WAITEnd SubSub endsub()Me.ShowSet oBackBuffer = NothingSet oPrimary = NothingCall odirectdraw.RestoreDisplayModeCall odirectdraw.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)EndEnd Sub  



-Coleco

~ c o l ec o ~



Rock the cradle of love!
You stupid WANKER!

mmmmmmmmmmkay

--HASBRO SUCKS--
Rock the cradle of love! You stupid WANKER!
Advertisement
After a couple of days after I''ve posted this message , I''ve figured out the problem. If you look carefully at these lines, you can see that there are some rectangle dimension mistakes:

With SrcRect
.Top = 0
.Bottom = 768
.Left = 0.
Right = 0
End With
With ClearRect
ClearRect.Top = 0
ClearRect.Bottom = 768
ClearRect.Right = 0
ClearRect.Left = 1024
End With

The problem is that srcrect should have had the right property 1024 and that clearrect has the left and right values reversed. I have developed this engine quite a lot, I have added a moving character on the screen too, it looks very good. I''ll put the newest version on my site soon(I mean the version with the character).

Caesar Studios
A young man with lots of talents

This topic is closed to new replies.

Advertisement