hello.
Does anyone know why this does not seem to work?
I'm trying to make this DirectDraw 4 example work in windowed mode
i d ont like when it is DDSCL_FULLSCREEN or DDSCL_EXCLUSIVE.
the fullscreen version was posted by SLIVER,
in this thread

http://www.asmcommunity.net/board/showthread.php?threadid=1629&highlight=directdraw


Thanks in advance.
Posted on 2003-05-20 23:36:52 by vilik
i must be stupid;
Posted on 2003-05-23 08:18:00 by vilik
Have not downloaded your example ....but ...

Lately i have made HE map editor run ok in windowed mode,

I am also moving on to make HE run in windowed mode (for debugging reasons only) ...

so where exactly is the problem in your code, have you narrowed its location a little conceptualy?
Posted on 2003-05-23 12:29:00 by BogdanOntanu
SOme of my assumptions w/o too much checking:

1)Why do release the clipper ? -- you will need it for the rest of the application
2)Whay do not setup backbuffercount to zero for the primary surface
3)Why OFFSECREENPLAIN and SYSTEMMEMORY ? - use ONLY SYTEMMEMORY :P
4)You must deal with WM_PAINT and WM_SIZE
5)Both source and destination rectangles must be specifyed for the system to primary BLIT
6)you must convert Window coordinates from client coordinates to screen coordinates
Posted on 2003-05-23 13:00:18 by BogdanOntanu
ni paloutchitsa
***
Thank you for your sugestions
but ,that didn't help me actually.
this is what i have.
***

.386
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc
include ddraw.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\winmm.lib
includelib \masm32\lib\ddraw.lib

;******************************************************************************
;* Function prototypes
;******************************************************************************
RunGame proto :HWND
CleanUp proto
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
DestroyDirectDraw proto
TopXY PROTO :DWORD,:DWORD

;******************************************************************************
;* EQU's
;******************************************************************************
WINDOW_TOP EQU CW_USEDEFAULT
WINDOW_LEFT EQU CW_USEDEFAULT
WINDOW_WIDTH EQU 640;800 ;600 ; must specify a value (not CW_USEDEFAULT)
WINDOW_HEIGHT EQU 480;640;600 ;600 ; must specify a value (not CW_USEDEFAULT)

; -----------------------------------------------------------------------------
; Create a RGB value and store it in EAX
; -----------------------------------------------------------------------------
RGB MACRO red, green, blue
xor eax, eax
mov ah, blue
shl eax, 8
mov ah, green
mov al, red
endm

; -----------------------------------------------------------------------------
; Displays a message box with the text passed to the macro
; -----------------------------------------------------------------------------
FATAL MACRO msg
LOCAL @@msg
.DATA
@@msg db msg, 0
.CODE
invoke MessageBox, MainHWnd, ADDR @@msg, ADDR szAppName, MB_OK
ENDM

; -----------------------------------------------------------------------------
; Safely releases a DDraw surface from memory
; -----------------------------------------------------------------------------
SAFE_RELEASE_SURFACE MACRO lpDDSSurf
.IF lpDDSSurf != NULL
DDSINVOKE Release, lpDDSSurf
mov lpDDSSurf, NULL
.ENDIF
ENDM

.DATA
szClassName db "MyWinClass", 0
szAppName db "Generic FPS", 0

MainHWnd HWND 0
lpDD LPDIRECTDRAW 0
lpDDSPrimary LPDIRECTDRAWSURFACE 0
lpDDSBack LPDIRECTDRAWSURFACE 0
lpClipper LPDIRECTDRAWCLIPPER 0
ddscaps DDSCAPS <0>
ddsd DDSURFACEDESC <0>
ddck DDCOLORKEY <0>
rcWindow RECT <0>
rcDest RECT <0>

dwFrameTime DWORD 0 ; Time of the last frame.
dwFrames DWORD 0 ; The frame rate (frames/second).
dwFrameCount DWORD 0 ; Frames displayed.
outputBuffer DB 64 DUP(42)
formatString DB '%d fps',0 ; takes a decimal "input" - %d
dwLength DWORD 0


.DATA?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hBitmap HBITMAP ?
hdcImage HDC ?
hdc HDC ?
bm BITMAP <?>
hDC HDC ?

.CODE

start:

invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax

WinMain proc hInst : HINSTANCE,
hPrevInst : HINSTANCE,
CmdLine : LPSTR,
CmdShow : DWORD
LOCAL wc : WNDCLASSEX
LOCAL msg : MSG
LOCAL hwnd : HWND

mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
mov eax, hInstance
mov wc.hInstance, eax
invoke GetStockObject, BLACK_BRUSH;WHITE_BRUSH
mov wc.hbrBackground, eax
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET szClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL,IDC_ARROW
mov wc.hCursor, eax

invoke RegisterClassEx, ADDR wc
;===============
; Centre window
;===============

invoke GetSystemMetrics,SM_CXSCREEN
invoke TopXY,WINDOW_WIDTH,eax
push eax

invoke GetSystemMetrics,SM_CYSCREEN
invoke TopXY,WINDOW_HEIGHT,eax

push eax
pop edx
pop ebx

invoke CreateWindowEx,NULL,\
ADDR szClassName,\
ADDR szAppName,\
WS_OVERLAPPEDWINDOW,\
ebx,\;WINDOW_LEFT,\
edx,\;WINDOW_TOP,\
WINDOW_WIDTH,\
WINDOW_HEIGHT,\
NULL,\
NULL,\
hInst,\
NULL
mov MainHWnd, eax

invoke ShowWindow, MainHWnd, CmdShow
invoke UpdateWindow, MainHWnd

invoke DirectDrawCreate, NULL, ADDR lpDD, NULL
.IF eax != DD_OK
FATAL "Couldn't init DirectDraw"
jmp cdd_Failed
.ENDIF

DDINVOKE SetCooperativeLevel, lpDD, MainHWnd, DDSCL_NORMAL
.IF eax != DD_OK
FATAL "Couldn't set DirectDraw cooperative level"
jmp cdd_Failed
.ENDIF

mov , SIZEOF DDSURFACEDESC
mov , DDSD_CAPS
mov , DDSCAPS_PRIMARYSURFACE
DDINVOKE CreateSurface, lpDD, ADDR ddsd, ADDR lpDDSPrimary, NULL
.IF eax != DD_OK
FATAL "Couldn't create primary surface"
jmp cdd_Failed
.ENDIF

mov ddsd.dwSize, SIZEOF DDSURFACEDESC
mov ddsd.dwFlags, DDSD_CAPS or DDSD_WIDTH or DDSD_HEIGHT
mov ddsd.ddsCaps.dwCaps, DDSCAPS_SYSTEMMEMORY;DDSCAPS_OFFSCREENPLAIN or
mov eax, WINDOW_WIDTH;dwWidth
mov ddsd.dwWidth, eax
mov eax, WINDOW_HEIGHT;dwHeight
mov ddsd.dwHeight, eax

; Create the surface
DDINVOKE CreateSurface, lpDD, ADDR ddsd, ADDR lpDDSBack, NULL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DDINVOKE CreateClipper, lpDD, 0, ADDR lpClipper, NULL
.IF eax != DD_OK
FATAL "Couldn't create the clipper"
jmp cdd_Failed
.ENDIF

DDCINVOKE SetHWnd, lpClipper, 0, MainHWnd
.IF eax != DD_OK
FATAL "Couldn't set the hwnd for the clipper"
jmp cdd_Failed
.ENDIF

DDSINVOKE SetClipper, lpDDSPrimary, lpClipper
.IF eax != DD_OK
FATAL "Couldn't set the clipper for the primary surface"
jmp cdd_Failed
.ENDIF

.IF lpClipper != NULL
DDCINVOKE Release, lpClipper
mov lpClipper, NULL
.ENDIF


.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke RunGame, MainHWnd ;run FPS**********-**************
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret

cdd_Failed:
invoke DestroyDirectDraw
ret
WinMain endp



WndProc proc hwnd : HWND,\
uMsg : UINT,\
wParam : WPARAM,\
lParam : LPARAM
LOCAL ps : PAINTSTRUCT
LOCAL ptWindow : POINT
.IF uMsg == WM_DESTROY
invoke PostQuitMessage, NULL

.ELSEIF uMsg==WM_CREATE

.ELSEIF uMsg == WM_QUIT
invoke PostQuitMessage, NULL

.ELSEIF uMsg == WM_MOVE
; invoke UpdateBounds, hwnd

.ELSEIF uMsg==WM_SIZE
invoke GetClientRect, hwnd, addr ptWindow
.ELSEIF uMsg == WM_PAINT
invoke BeginPaint,hwnd,addr ps
;Invoke InvalidateRect, hwnd, NULL, TRUE
invoke EndPaint,hwnd,addr ps
.ELSE

invoke DefWindowProc, hwnd, uMsg, wParam, lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp

DestroyDirectDraw proc
.IF lpDD != NULL
; Release all the surfaces
SAFE_RELEASE_SURFACE lpDDSPrimary
SAFE_RELEASE_SURFACE lpDDSBack

DDINVOKE Release, lpDD
mov lpDD, NULL
.ENDIF
ret
DestroyDirectDraw endp

TopXY proc wDim:DWORD, sDim:DWORD
shr sDim, 1 ; divide screen dimension by 2
shr wDim, 1 ; divide window dimension by 2
mov eax, wDim ; copy window dimension into eax
sub sDim, eax ; sub half win dimension from half screen dimension
mov eax,sDim
ret
TopXY endp

; #################################
; #################################
RunGame proc hwnd : HWND

; Get a handle to the device context
lea ebx, hDC
DDSINVOKE GetDC, lpDDSBack, ebx
.if eax != DD_OK
jmp err
.endif
inc

invoke timeGetTime
sub eax, dwFrameTime
mov ecx,eax
.IF eax >= 1000
mov eax,
lea edx, DWORD PTR
lea eax, DWORD PTR
lea edx, DWORD PTR
lea eax, DWORD PTR
sub edx, edx
div ecx
mov ,eax

invoke timeGetTime
mov ,eax
mov ,0
.ENDIF

push
push offset formatString
push offset outputBuffer

call wsprintfA

add esp,12

invoke lstrlenA, offset outputBuffer ; API to get null terminated string length
mov ,eax

RGB 255, 255, 255
;------ use this to do some text manipulation/output
invoke SetTextColor,hDC,eax
invoke SetTextAlign,hDC,TA_CENTER
invoke SetBkMode, hDC, TRANSPARENT
invoke TextOutA,hDC,320,10,offset outputBuffer,

DDSINVOKE ReleaseDC, lpDDSBack, hDC
.if eax != DD_OK
jmp err
.endif


DDSINVOKE Blt, lpDDSPrimary, ADDR rcWindow, lpDDSBack, NULL, DDBLT_WAIT, NULL


mov eax, TRUE
ret



err:
;===================
; We didn't make it
;===================
mov eax, FALSE
ret
RunGame endp


end start
Posted on 2003-05-23 20:19:58 by vilik
Man once again i ask:
-have you narrowed the problem to a specific location?
-what works and what does not?
Posted on 2003-05-25 11:12:48 by BogdanOntanu
I have no idea, really...
JUST A BLACK WINDOWS
Posted on 2003-06-04 21:47:18 by vilik
Ok... there were several problems. The one which stopped anything being displayed was that the Blt was giving an error - it wasn't detected as there was no error checking here. The reason for the error was that the source and destination rects were not correctly set up. I don't know whats going on with the clipper, but i moved that around...

Once it was displaying the text, i noted that it overwrote itself, so thats changed a bit.

Heres what i edited it to... its still a bit of a mess, but i think it should work now

Ossa
Posted on 2003-06-05 07:54:21 by Ossa
Hi ! Ossa :)

Work very well :alright:

Friendly...Gges
Posted on 2003-06-14 08:00:24 by Asmgges