Jump to content

  • Log In with Google      Sign In   
  • Create Account

DDraw


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Gabriel   Members   -  Reputation: 122

Like
Likes
Like

Posted 03 January 2000 - 11:53 AM

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???

Sponsor:

#2 blaze   Members   -  Reputation: 122

Like
Likes
Like

Posted 03 January 2000 - 12:49 PM

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.

#3 Starfall   Members   -  Reputation: 122

Like
Likes
Like

Posted 03 January 2000 - 01:27 PM

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

#4 blaze   Members   -  Reputation: 122

Like
Likes
Like

Posted 03 January 2000 - 02:13 PM

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

--Shannon Schlomer, BLAZE Technologies, Inc.

#5 Drilian   Members   -  Reputation: 1025

Like
Likes
Like

Posted 03 January 2000 - 06:05 PM

I''ve only seen the need for DWORD pitch. (At least, DWord has always worked for ME)



Josh J

#6 alexmoura   Members   -  Reputation: 450

Like
Likes
Like

Posted 03 January 2000 - 11:27 PM

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.

#7 Starfall   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 January 2000 - 12:50 AM

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

#8 alexmoura   Members   -  Reputation: 450

Like
Likes
Like

Posted 04 January 2000 - 02:20 AM

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.

#9 Starfall   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 January 2000 - 04:25 PM

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

#10 alexmoura   Members   -  Reputation: 450

Like
Likes
Like

Posted 04 January 2000 - 09:29 PM

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?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS