Can anyone tell me with an example that after drawing a sprite onto a primary and invisible surfaces, how to clear the surfaces before drawing more sprites?:)
Posted on 2002-06-10 07:28:37 by Wonder Mage
You might not want to clear the primary surface every time because you will get visual artifacts on screen (do it only once at the start) instead just redraw whole image each time (if on primary)



;***********************************************
; Clear the video flip chain
; back buffer to black using
; blit with color fill
;***********************************************
.data
align 4
szClearBackFail db "Clear Video Flip Chain Back Buffer Fail!",0
.code

ClearBack:

; first fill the ddbltfx structure with required values
;----------------------------------------------------------------
mov ddbltfx.dwSize, SIZE ddbltfx
mov ddbltfx.dwFillColor, 0 ; colorfill 0=black

;----------------------------------
; params for the blit
;----------------------------------
mov eax, offset ddbltfx ; the colour from above
push eax

mov eax, DDBLT_COLORFILL + DDBLT_WAIT ; specify the blit we want
push eax

mov eax,0
push eax ;src rect

mov eax,0 ;src surf=null=myself
push eax

mov eax,0
push eax ; dest rect NULL=all

mov eax,[lpDDSBack] ; the pointer to the object instance - the back buffer -
push eax ; is the last parameter... (unknown to C :)

mov eax,[eax] ; get vtable address
call [eax + DDS_Blt] ; call the Blt method

;--------------------------------------
; error checking
;--------------------------------------
.IF eax != DD_OK
mov eax,offset szClearBackFail
call OutputDebugStringA
jmp end_loop
.ENDIF

mov eax,0
ret
Posted on 2002-06-10 08:29:17 by BogdanOntanu
Hi BogdanOntanu, You are very nice and helping, thanks for the code. Well i also need to know that i write the direct draw code for windows me but when i run it on windows xp. ohhh it did'nt work! can you tell me what's the problem?:)
Posted on 2002-06-10 08:44:41 by Wonder Mage
Depends on your code...

But usually is that Win9x is much tolerant with register preservations than XP/2k/NT OSes

So save ecx,ebx,esi,edi,ebp is your callbacks or window procedures ;)

Also check parameter differences between Win9x <->XP some are not the same

Also we have had some problems with XP/2k in getting the video board memory, refresh rate and performace counters you will have to check that i guess
Posted on 2002-06-10 08:53:53 by BogdanOntanu
I tried integrated your code to my code. The surface got cleared as you said! But now... There is a new problem. There is a constant flicker in the sprite animation. I first draw the sprite to offscreen and than call blt to paint the backbuffer 1 from the source offscreen. The problem is not being solved! please help me. also i need to know that when i call directinputcreate with appropirate variables. the variable IDirectDraw8w causes errors. I am using calebs directx 8 filez. Please help with these two problems:confused:
Posted on 2002-06-12 09:08:11 by Wonder Mage
Well please do not respect me ;)

I still suspect you are writeing directly to the primary surface, hence the flicker. Or try to use the Wait parameter to the Blt() or Flip()


to avoid flicker game programmers designed a scheme that is called backfuffering: you do all your drawing to a backbuffer surface and when all is finished... bang you fastcopy all to the primary surface (video memory)

With DirectX you can either create a hardware accelerated backbuffer in a flip chain and use the ::Flip() method to very fast (hardware driven) switch between the 2 surfaces or use your own software backbuffer and just copy or Blt it to the primary surface at the end.

Why use a software buffer...hmmm well you will learn pretty fast that reading from video memory is very slow and unless you are going 3D ...2D directDraw has no support for alpha blending (even if most video boards have support in hardware for 2D and 3D) ...

if you must make alpha blending routines in software and you must read from surfaces ....



Directx8 has no support for 2D only for 3D...
For 2D you must still use DirectX7 includes.

start to init directinput like this:
(not all the code but it might give you the general ideea)



;********************************
; Direct Input Init
; and CORE functions
;********************************

.data
ALIGN 4

;==========================================
; static guids for expected devices
;==========================================
GUID_SysMouse dd 06F1D2B60h
dw 0D5A0h
dw 011CFh
db 0BFh
db 0C7h
db 044h
db 045h
db 053h
db 054h
db 000h
db 000h

GUID_SysKeyboard dd 06F1D2B61h
dw 0D5A0h
dw 011CFh
db 0BFh
db 0C7h
db 044h
db 045h
db 053h
db 054h
db 000h
db 000h

.code



extern DirectInputCreateA:PROC



;***************************************
; Main Initialization sequence
;****************************************
Direct_Input_Init:

Call Create_Direct_Input_Object

call Create_Direct_Input_Device_Mouse
call Set_Data_Format_Mouse
call Set_Cooperative_Level_Mouse
call Acquire_Mouse


call Create_Direct_Input_Device_Keyboard
call Set_Data_Format_Keyboard
call Set_Cooperative_Level_Keyboard
call Acquire_Keyboard


; call Release_Direct_Input_Object
ret


;============================

.data
ALIGN 4
;
lp_di_main_object dd 0

szDirectInputCreateFail db ' Direct Input Create Failed! ',0

DI_object_OK db 'DI CREATE OBJECT OK!',0
.code

Create_Direct_Input_Object:


mov eax,0 ;null not used
push eax

mov eax,offset lp_di_main_object
push eax

mov eax,DirectInputVersion3
; mov eax,DirectInputVersion5
push eax

mov eax,[hinstmain]
push eax

call DirectInputCreateA

.IF eax!=DI_OK
Call OutputDebugValue,eax
Call OutputDebugStringA,offset szDirectInputCreateFail
call Fail, hwndmain, offset szDirectInputCreateFail
jmp end_loop
.ENDIF

Call OutputDebugStringA,offset DI_object_OK

ret


......


Posted on 2002-06-12 17:12:02 by BogdanOntanu
Why can't i respect you? you are respected by all the programmers here.:) I am testing your code now, i will reply to you as quickly as possible. Please be not irretated.
Posted on 2002-06-13 07:27:07 by Wonder Mage
Hi,
i have successfully cleared off the sprite flikering problem!. your code was correct but the code which i wrote was also correct. there was only a minor mistake. in the sprite loop i forgot to add 1 res id for a sprite and i wrote 0 instead this gave blackout problems. thanks very much for the help bogdantanu. you are very helping.:)
Posted on 2002-06-14 08:59:20 by Wonder Mage