hii

how can i create a surface from the device context of the screen . and if i cant do that . how can i read from the screen and draw to him with direct x ?


bye

eko

EDIT:when i create a surface is it allways all the screen ?
Posted on 2001-12-22 17:01:23 by eko
Surfaces are DirectX Objects, they are created by a calling a Method of a IDirectDraw object.

You can call IdirectDrawSurface::GetDC after you create the surface to get a standard GDI like DC for a given surface... but this is somehow slow (GDI operations on a DX surface).

Dx Surfaces can be created in system memory or in video memory, and they can have allmost any dimensions (not all suport big widths and win9x limits dy to 32768) your memory can buy ...

I do not think you can create a surface from a GDI DC...but i am not sure... after all why?

The Primary surface IS the Screen either full screen exclusive mode or in non exclusive mode.

Asimple way or reading/writeing to the screen (after DX initializations of course) is to ::Lock the Primary surface and so get a pointer to screen pixels. you can then use memory operations on screen.
Take care:
-screen Dx versus Pitch problems
-curent resolution pixelformat
-::UnLock as fast as you can

PS. have you read the DirectX SDK tutorials? There are also some DX examples on Iczelion's site and in the latest release of Hutch's MASM32 package at www.movsd.com
Bizzare Creations, Test Department and many others have DX examples (and OpenGL) in ASM on their sites... search the game developement forum (older messages also) for other examples/sites
Posted on 2001-12-22 17:25:58 by BogdanOntanu
hii
thanks for the fast reply


after i lock the surface can i copy it to another memory block just for saving or do i need to create another surface for that ?

bye

eko

EDIT: when i use DDSCL_NORMAL in SetCooperativeLevel what is the differnt than DDSCL_FULLSCREEN and DDSCL_EXCLUSIVE
?
Posted on 2001-12-22 17:31:13 by eko
i have some other questions .. (hope to get answers on the others as well)

1. i want to get screen picture . when i create a surface will it destory screen picture ??
2. can i create surface with 2 backbuffers?
Posted on 2001-12-22 17:42:57 by eko
Answers

Yes you can copy the surface contents to a private memory area after you ::Lock it...that is the whole ideea ...

Never try to read from a video memory surface unless you really have to... because is too much slow (10fps)

If you use Full screen exclusive mode, yes you will loose the screen, but if you go non exclusive mode then you can copy the whole windows GDI screen at will...eh and write over it also so take care ;)

Yes you can create a Primary surface with 2 or more backbuffers. Depends on how much memory your video card has...

Exclusive means you want to use the screen for yourself, only one application can have exclusive acces to the screen (ie Primary surface) at a time, this flag usualy goes with Full Screen for obvious reasons, it also allows you to stop users from pressing Ctrl+Alt+Del, use Flip to switch backbuffers, ... etc
Posted on 2001-12-22 17:51:52 by BogdanOntanu
i must say again thanks for the fast replys


antoher questions :
if i use DDSCL_NORMAL it wont destroy the screen picture?

how can i get the the pointers of the two backbuffers?


i found the source
 mov ddscaps.dwCaps, DDSCAPS_BACKBUFFER  ; specifythe back buffer

lea eax, lpDDSBack ; the pointer you get is stored here
push eax
lea eax, ddscaps
push eax
mov eax,[lpDDSPrimary] ; the surface the back buffer is attached to
push eax
mov eax,[eax]
call DWORD PTR [eax + DDGETATTACHEDSURFACE] ; GetAttachedSurface


and ok i understood that . and lpDDSBack will point the my backbuffer . how can i get he 2nd back buffer?
Posted on 2001-12-22 17:57:19 by eko
You only get a pointer to the last backbuffer, this is the one you write/read data to, intermediate backbuffers are handled internaly by DX on the ::Flip method

however you can also read/write directly to the Primary buffer

multiple backbuffers are used only for speed optimisations or avoiding tear artefacts
Posted on 2001-12-22 18:31:31 by BogdanOntanu
hi
i have aproblem i want the screen to be un change when i create asurface i try to use

DDINVOKE SetCooperativeLevel, lpDD, hWnd, DDSCL_NORMAL; and the call works but then the createsurface doesnt work .

when i use DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN it works

bye

eko
Posted on 2001-12-23 12:41:09 by eko
What kind of surface are you creating,
and with what parameters?
Posted on 2001-12-23 13:18:57 by BogdanOntanu


mov [ddsd.dwSize], sizeof DDSURFACEDESC
mov [ddsd.dwFlags], DDSD_CAPS+DDSD_BACKBUFFERCOUNT ; create backbuffer
mov [ddsd.ddsCaps.dwCaps], DDSCAPS_PRIMARYSURFACE OR\
DDSCAPS_FLIP OR\
DDSCAPS_COMPLEX OR\
DDSCAPS_VIDEOMEMORY
mov [ddsd.dwBackBufferCount], BUFFERS
DDINVOKE CreateSurface, lpDD, ADDR ddsd, ADDR lpDDSPrimary, NULL
.IF eax != DD_OK
FATAL "Couldn't create primary surface"
.ENDIF


like i said before i want to create asurface with out doing any change in the screen picture. the user wont notice that a surface has been created
and i need help . it doesnt work

bye

eko
Posted on 2001-12-23 13:43:07 by eko
You can NOT use FLIP if you are not in exclusive mode ;)

and the only flags you need are:
DDSD_CAPS and
DDSCAPS_PRIMARYSURFACE
Posted on 2001-12-23 14:28:09 by BogdanOntanu
ok it works
so far so good

another question :

what is the fastest way to save a surface (for later use)?

i create another surface (DDSCAPS_OFFSCREENPLAIN) just for tempory use . i tried to blt from the main surface to the tempone
but it doesnt work :(

i tired bltfast and blt .:confused:


bye

eko
Posted on 2001-12-24 12:52:28 by eko
Surfaces are never lost, unless they are in video memory. Video memory surfaces may/may not be lost on Alt+TAB, Ctrl_Esc etc

For video memory, you must recreate from original bitmaps after you ::Restore them

To save a surface just ::BLT the source onto destination (not BitBlt unless you ::GetDC first). Take care at DDBLTFX and parameters :) ... Also avoid stretch (is slow) and never BLT outside the dest surface unless you have a Clipper installed...eh attached...

Avoid OFFSCREENPLAIN, its buggy, some drivers place half of the surface in video and half in system if they have not enough video memory, allways use SYSTEMMEMORY or VIDEOMEMORY FLAGS

i must see the offending code for more info ...
Posted on 2001-12-24 21:56:02 by BogdanOntanu
hi



mov rcdraw.left,0
mov rcdraw.top,0
mov rcdraw.right,800
mov rcdraw.bottom,600
mov ddbltfx.dwSize, SIZE ddbltfx

i tried both
;DDSINVOKE BltFast,lpDDSscreen, 0,0,addr lpDDSPrimary,addr cdraw,DDBLT_WAIT
;DDSINVOKE Blt,lpDDSscreen,addr rcdraw,addr lpDDSPrimary,addr rcdraw,DDBLT_WAIT ,addr ddbltfx
;or eax,eax
;jz @F


what else do i need to set in DDBLTFX?

what should i use instead OFFSCREENPLAIN?
thanks
bye



eko
Posted on 2001-12-25 08:25:38 by eko
1. It's for sure that you must not pass ADDR of lpDDSPrimary but it's value instead..
2. Instead of OFFSCREENPLAIN you must use :
-SYSTEMMEMORY if you want your surface to be in system memory
-VIDEOMEMORY if you want your surface to be in video memory

This flag must be set when you create the surface

3. You dont need to set anything else in ddbltfx structure for your call

Eugen
Posted on 2001-12-25 15:37:54 by Eugen
THANKS YOU BogdanOntanu and Eugen it works !! :grin:
i realy appreciate your help !!!!!!


bye

:alright:

eko
Posted on 2001-12-26 10:36:20 by eko
hi

is there a chance to use flip in DDSCAPS_NORMAL?

bye

eko
Posted on 2001-12-27 15:59:44 by eko
Using DirectX?

Nope ... anyway video to video memory BLIT is very very fast ...so why use FLIP?

But i guess you can try and use the video driver, i suspect windows uses hardware acceleration when it moves the windows (with contents) on screen (plain GDI) i mean and with menus. later win2k,Xp 2D alpha blending functions should use hardware accel also... or 2Ghz micros :P or ASM

But this will require advanced drivers knowledge and will not be portable ... so you better do not unless you have a very very very good reason for it....
Posted on 2001-12-30 06:47:21 by BogdanOntanu
how much complicated will it be ? do you have any example of using the video driver?


bye

thanks


eko
Posted on 2001-12-30 07:49:36 by eko