游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1987|回复: 2

我用DX直接在页面上画点,为什么不能按我给出的颜色画

[复制链接]

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2004-4-30 23:15:00 | 显示全部楼层 |阅读模式
我用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 &= ~((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(&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 ));
}

1万

主题

1万

帖子

2万

积分

管理员

中级会员

Rank: 9Rank: 9Rank: 9

积分
20527
发表于 2004-5-1 10:07:00 | 显示全部楼层

Re:我用DX直接在页面上画点,为什么不能按我给出的颜色

是色彩不对?还是根本就没绘制出来?

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2004-5-1 10:28:00 | 显示全部楼层

Re:我用DX直接在页面上画点,为什么不能按我给出的颜色

已经绘制出来了,只是色彩不对。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-30 16:41

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表