DDraw

Started by
8 comments, last by Gabriel 24 years, 3 months ago
I have heard from numerous people that to blend 2 surfaces, you just add increased /decreased values together. Well, I did that to get a crude alpha blending function. the only thing that''s wrong is that it does half the screen. here''s the func: void TransAlpha( LPDIRECTDRAWSURFACE7 dest) { BYTE* lpSurf; BYTE* lpDest; DDSURFACEDESC2 srcDDSD, destDDSD; RECT rect; rect.top = 0; rect.left = 0; rect.right = 319; rect.bottom = 239; // Lock down both surfaces for read and write ZeroMemory(&srcDDSD, sizeof(srcDDSD)); srcDDSD.dwSize = sizeof(srcDDSD); g_pDDSPrimary->Lock(&rect, &srcDDSD, DDLOCK_WAIT, NULL); ZeroMemory(&destDDSD, sizeof(destDDSD)); destDDSD.dwSize = sizeof(destDDSD); dest->Lock(&rect, &destDDSD, DDLOCK_WAIT, NULL); // Initialize the pointers to the upper left hand corner of surface lpSurf = (BYTE*)srcDDSD.lpSurface; lpDest = (BYTE*)destDDSD.lpSurface; for(double ALPHA = 1.0; ALPHA > 0.0; ALPHA -=0.05) { for (int y = 0; y != 239; y++) { for (int x = 0; x != 319; x++) { lpSurf[x + srcDDSD.lPitch * y] = lpSurf[x + srcDDSD.lPitch * y] * ALPHA + lpDest[x + destDDSD.lPitch * y] * (1-ALPHA); } } } dest->Unlock(&rect); g_pDDSPrimary->Unlock(&rect); } I heard that the solution was to make the surface pointers a WORD instead of a BYTE, so I did so: WORD lpSurf; WORD lpDest; lpSurf = (WORD*)srcDDSD.lpSurface; lpDest = (WORD*)destDDSD.lpSurface; now it does the whole screen, but skips lines. why???
Advertisement
1) If you''re using 16bit surfaces, divide the pitch by 2.
pitch = srcDDSD.lPitch >> 1;
Your pointers have to be WORD*

2) If you''re using 32bit surfaces, divide the pitch by 4.
pitch = srcDDSD.lPitch >> 2;
Your pointers have to be DWORD*


--Shannon Schlomer, BLAZE Technologies, Inc.
--Shannon Schlomer, BLAZE Technologies, Inc.
Does anyone know whether the pitch is ever an odd number in 16-bit mode, on any video card? Seems this would break the code, which is why I''ve never divided the pitch, preferring to get around the problem another way. There is a small performance gain from dividing the pitch, but can we assume that it''s safe to do so?

Regards

Starfall
According to the SDK, the pitch has to be a QWORD (8byte) multiple.

--Shannon Schlomer, BLAZE Technologies, Inc.
--Shannon Schlomer, BLAZE Technologies, Inc.
I''ve only seen the need for DWORD pitch. (At least, DWord has always worked for ME)



Josh J
I think 16 bit and 32 bit modes are alligned (allways start at a 16 or 32 multiple addresses (2 or 4 multiples, in terms of address values)) wich would implicate non-odd pitch numbers (each address has allways an even number of bytes between them)
As allways, should anyone know that i''m wrong in any way, may they write now or allow us to write bugged programs for ever.
Interesting. I guess the best thing to do if you are going to divide the pitch, is write a bit of code in your startup routine to check that the pitch of the primary surface is aligned, and if not drop the user out with a message. Of course, you''d want to be reasonably sure that it wasn''t going to happen on 99.9% of video cards, but it''d probably be a better thing than attempting to run the game like that.

Regards

Starfall
You''re probably right. But anyway, if someone knows wether words or dwords can not be alligned, or are allways alligned, (by the way, when you cast a byte * to a dword * in C, does it return a aligned pointer?)
please let the unilluminated know.
by the way, when you cast a byte * to a dword * in C, does it return a aligned pointer?

No, it only returns an aligned pointer if the byte pointer was aligned to whatever alignment you are talking about (4 byte I assume). The reason is that it still has to point to exactly the same spot as the byte, be it aligned or not.

Regards

Starfall
Ok, thanks (I had a suspition it would work that way, but it''s better to be sure)
Well the main question still stands; does DirectDraw (or graphics boards) keep they dword and word alligned?

This topic is closed to new replies.

Advertisement