Skip to main content
gamedev.net
🔒 Locked

16bit pixel plotting work, 32bit doesn't

Started by Bleakcabal Jun 19, 2002 at 12:14 PM 2 replies 150+ views
Original Post
Bleakcabal
Bleakcabal
Hi, I have used code based on the Game Programming Genesis articles on gamedev found here : http://www.gamedev.net/reference/programming/features/gpgenesis4/ to do some DirectDraw 2d graphics. Whith this tutorial I was able to plot pixels in 16bits fullscreen and everything works a.ok. but when I try to do 32bits it doesn''t work... Actually I see a pixel on the screen, it seems to be of the right color, but it is not at the good place on the screen. If I plot a pixel on the middle of the screen at 16 bits it is on the middle, but at 32 bits it is not for the same resolution ? I have tried several different coordinates and got the same results everytime. here is my code which is currently in a class:

if (fullscreen == true)
	{
		if (scr_bpp == 32)
		{
			UINT *video_buffer;

			memset(&ddsd, 0, sizeof(ddsd));
			ddsd.dwSize = sizeof(ddsd);
			lpddsback->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
			video_buffer = (UINT *)ddsd.lpSurface;
			
			video_buffer[x + (y*ddsd.lPitch >> 1)] = (UINT)RGB_32BIT(red, green, blue);

			lpddsback->Unlock(ddsd.lpSurface);
		}

		if (scr_bpp == 16)
		{
			USHORT *video_buffer;

			memset(&ddsd, 0, sizeof(ddsd));
			ddsd.dwSize = sizeof(ddsd);
			lpddsback->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
			video_buffer = (USHORT *)ddsd.lpSurface;
			
			if (nPixelFormat == 16)
				video_buffer[y * (ddsd.lPitch>>1) + x] = (USHORT)RGB_16BIT565(red, green, blue);
			else
				video_buffer[y * (ddsd.lPitch>>1) + x] = (USHORT)RGB_16BIT555(red, green, blue);

			lpddsback->Unlock(ddsd.lpSurface);
		}
	}

 
I have also noticed that when you use this code in the windowed mode, the pixel display but the location on the screen isn''t right. Can anyone help me out with this ? Thanks in advance for any help you could give me. WHO DO THEY THINK THEY''RE FOOLING : YOU ?
WHO DO THEYTHINK THEY'REFOOLING : YOU ?
S1CA
S1CA
A nice big clue:

lPitch is the pitch of the surface in bytes

lPitch>>1 is the pitch of the surface in words

lPitch>>2 is the pitch of the surface in dwords



--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
DrunkenHyena
DrunkenHyena
It''s been way too long since I''ve looked at pixel plotting (or maybe not long enough!) but i think your problem is in how you handle the pitch.

The pitch is given in bytes, so to calculate the offset for 16-bit, you right shift by 1 (dividing by 2).

Since 32-bit is 4 bytes, you should be shifting your pitch by 2 (dividing by 4).

By the way, if you plan on plotting any significant number of pixels this way it will be SLOW. For faster pixel plotting, Lock the surface once, plot all your pixels, then Unlock.

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena</FON
Bleakcabal
Bleakcabal
Thanks guys, it was the >> 2.

I was surprised to have Drunken Hyena awnser me, I have read some of your tuts, they''re great !

As for locking for each pixel, I know about the fact that it is slow, but right now I concentrate on getting things to work ( and for me that''s a tough job ), I will worry about speed later.



WHO DO THEY
THINK THEY''RE
FOOLING : YOU ?



WHO DO THEYTHINK THEY'REFOOLING : YOU ?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.