Archived

This topic is now archived and is closed to further replies.

Mike Lue

Pallete trouble

Recommended Posts

Mike Lue    122
I have been playing with pallete for a while now, but having some troubles. Here is the code i haveI am expecting the whole surface set to be green but the result is that there is one seventh of the surface on the top are white and the rest is black. Can anyone tell why?): //here I changed my pallete LPDIRECTDRAWPALETTE m_lpDDPal; // the palette object PALETTEENTRY m_mypal[256]; // stores palette stuff m_mypal[255].peRed = 0; m_mypal[255].peGreen = 255; m_mypal[255].peBlue = 0; m_lpDD->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256, m_mypal, &m_lpDDPal, NULL); m_lpDDPrimary->SetPalette(m_lpDDPal); //here i changed the color of the whole surface DDSURFACEDESC ddsd2; ddsd2.dwSize = sizeof(ddsd2); m_lpDDBack->GetSurfaceDesc(&ddsd2); int width = ddsd2.lPitch; int height = ddsd2.dwHeight; double_buffer = Lock_Back_Buffer(); for(int i = 0; i < width * height; i++) { double_buffer = 255; } m_lpDDBack->Unlock(NULL); m_lpDDPrimary->Flip(NULL,0); Thanks in advance

Share this post


Link to post
Share on other sites
Mike Lue    122
Here is the code to init all my pallete:

int index = 0;
for (index=95;index<200;index++)
{
m_mypal[index].peRed = index+70;
m_mypal[index].peGreen = index+30;
m_mypal[index].peBlue = rand()%10;
}
for (index = 1; index < 35; index++)
{
m_mypal[index].peRed = index+25;
m_mypal[index].peGreen = rand()%10;
m_mypal[index].peBlue = rand()%10;
}
for (index = 35; index < 55; index++)
{
m_mypal[index].peRed = index+25;
m_mypal[index].peGreen = index-25;
m_mypal[index].peBlue = rand()%10;
}
for (index = 55; index < 95; index++)
{
m_mypal[index].peRed = index+75;
m_mypal[index].peGreen = index;
m_mypal[index].peBlue = rand()%5;
}
for(index = 200; index < 255; index++)
{
m_mypal[index].peRed = index;
m_mypal[index].peGreen = index-rand()%25;
m_mypal[index].peBlue = rand()%5;
}

I am sorry that I am alittle confused about the concept of pallete. Here is the point where I am confused:

if I only use color 255''s as what I did in my code(I want the 255th color to be green), is it nesessary for me to initialize other pallete colors?

Thanks

Share this post


Link to post
Share on other sites
Mike Lue    122
Here is the code to init all my pallete:

int index = 0;
for (index=95;index<200;index++)
{
m_mypal[index].peRed = index+70;
m_mypal[index].peGreen = index+30;
m_mypal[index].peBlue = rand()%10;
}
for (index = 1; index < 35; index++)
{
m_mypal[index].peRed = index+25;
m_mypal[index].peGreen = rand()%10;
m_mypal[index].peBlue = rand()%10;
}
for (index = 35; index < 55; index++)
{
m_mypal[index].peRed = index+25;
m_mypal[index].peGreen = index-25;
m_mypal[index].peBlue = rand()%10;
}
for (index = 55; index < 95; index++)
{
m_mypal[index].peRed = index+75;
m_mypal[index].peGreen = index;
m_mypal[index].peBlue = rand()%5;
}
for(index = 200; index < 255; index++)
{
m_mypal[index].peRed = index;
m_mypal[index].peGreen = index-rand()%25;
m_mypal[index].peBlue = rand()%5;
}

I am sorry that I am alittle confused about the concept of pallete. Here is the point where I am confused:

if I only use color 255''s as what I did in my code(I want the 255th color to be green), is it nesessary for me to initialize other pallete colors?

Thanks

Share this post


Link to post
Share on other sites
Mike Lue    122
I am just a newbie to directx so I am not so sure how you can set a surface 8bit per pixel. I guess here is what you mean:

m_lpDD->SetDisplayMode( 800, 600, 8/*(8 bit per pixel)*/);

Share this post


Link to post
Share on other sites
Jason Zelos    211
int width = ddsd2.lPitch;
int height = ddsd2.dwHeight;

Try:

int width = ddsd2.dwWidth;
int height = ddsd2.dwHeight;

pitch is the ratio of pixels to metres (or similar).

Also if that does not work then perhaps using ''&''.

m_lpDD->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256, &m_mypal, &m_lpDDPal, NULL);

and/or

m_lpDDPrimary->SetPalette(&m_lpDDPal);

Never used the pallette, so can''t say for sure.

,Jay

Share this post


Link to post
Share on other sites
merlin9x9    174
Pitch is the distance between row 0 of each column in the frame buffer. When you draw to the surface by directly manipulating its contents, make sure you use the surface''s pitch rather than its width in your calculation from a coordinate to an address, as in address = (y * pitch) + x.

Share this post


Link to post
Share on other sites