我用DX直接在页面上画点,为什么不能按我给出的颜色画出呢?(80分)

  • 主题发起人 主题发起人 fzqdfw
  • 开始时间 开始时间
F

fzqdfw

Unregistered / Unconfirmed
GUEST, unregistred user!
我用DX直接在页面上画点,为什么不能按我给出的颜色画出呢?那位大侠能够告知,先谢谢了!!!!
方法1
void WritePixel16( IDirectDrawSurface7* surface ,int x , int y , WORD color_value )
{
DDSURFACEDESC2 desc;

memset(&desc,0,sizeof(desc)); desc.dwSize = sizeof(desc);
if (SUCCEEDED(surface->Lock(NULL,&desc,
DDLOCK_NOSYSLOCK|DDLOCK_WAIT,NULL)))
{

char* address = (char*)desc.lpSurface;
address += (x*2) + (y*desc.lPitch);
*((WORD*)address) = color_value;
surface->Unlock(NULL);
}
}方法1 End

方法2
void PutPixel(int x, int y, DWORD dwCol) //在(x, y)画点dwCol
{
LPBYTE lpBitmap = (LPBYTE)ddsd.lpSurface;
DWORD dw = ddsd.ddpfPixelFormat.dwRGBBitCount;
lpBitmap += y * ddsd.lPitch + x * (dw >> 3);
*(DWORD*)lpBitmap &amp;= ~((1 << dw) - 1); // 把该填色的位清除
*(DWORD*)lpBitmap |= dwCol; // OR填上颜色了
}方法2 End

方法3
USHORT _RGB16BIT (int r , int g, int b)
{
// the return value
USHORT retval = 0;

// max value has to be either 32 or 64,
// depending on the number of bits of the channel:
if (redbits == 6) r >>= 2; else r >>= 3;
if (greenbits == 6) g >>= 2; else g >>= 3;
if (bluebits == 6) b >>= 2; else b >>= 3;

// as I said, I don't know how many modes there are. If you do, shorten
// the function by removing unnessessary lines above.
// And please tell me! ;-)

// now build a word of the three channels by shifting them by the
// _correct_ number of bits:
retval = (USHORT) (b + (g << bluebits) + (r << (bluebits + greenbits)));
// return the color:
return(retval);
}
方法3 End

BOOL UpdateFrame()
{
HDC hdc; //设备环境句柄
//输出文字
if ( lpDDSPrimary->GetDC(&amp;hdc) != DD_OK) return FALSE;
OutputDebugString("dfdfsdf");
SetBkColor( hdc, RGB( 0, 0, 255 ) );
SetTextColor( hdc, RGB( 255, 255, 0 ) );
TextOut( hdc, 220, 200, szMsg1, lstrlen(szMsg1));
TextOut( hdc, 280, 240, szMsg2, lstrlen(szMsg2));
lpDDSPrimary->ReleaseDC(hdc);
OutputDebugString("dfdfsdf");

WritePixel16(lpDDSPrimary,10,10,RGB( 255, 0,0 ));
}
 
后退
顶部