Home » Community » Forums » Article Feedback » Game Programming Genesis Part V : Palettes and Pixels in DirectDraw
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Game Programming Genesis Part V : Palettes and Pixels in DirectDraw
Post New Topic  Post Reply 
Comments for the article Game Programming Genesis Part V : Palettes and Pixels in DirectDraw

 User Rating: 2088   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

While I am able to make his 16bpp pixel plotting work, when I try to use his technique for 32 bpp the color is right but the pixels are not at the right place ( in 800x600 I put a pixel at 400-300 and it is near the lower left corner ).

Here is the code I am using :
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);
		}
 


WHO DO THEY
THINK THEY'RE
FOOLING : YOU ?





[edited by - bleakcabal on June 19, 2002 11:41:35 AM]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Check yer pitch. It should be >> 2, not 1, in 32bit. This is because the pitch is given in bytes. When you want 16 bit each pixel takes up two bytes, so you >> 1 (divide by two). In 32 bit each pixel takes up 4 bytes, so you must >> 2 (divide by four).

[edited by - Alimonster on June 20, 2002 9:39:53 AM]

 User Rating: 1025   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hi I have just read this part of the tutorial and I'm wondering what's the proper setting for creating a color table for 256 and 16bits? As much as possible, I want it to grasp the whole set of colors. In Tricks of the Windows Game Programming Gurus 2nd ed. by Andre LaMothe, what he did there was to make a random function mod 256 for RGB and the first and last entries to be black and white, which I find not a good way because there are chances in random to have the exactly the same as some other entries and the color arrangement would be chaotic. So, anyone here has a good formula/way to make a good color table?

By the way, I made 16bits, and 32bits bitmap file containing all the possible colors I like? Is it possible to load these bitmaps and get their palettes so I can use them? How?

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: