游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1542|回复: 1

lPitch问题求教

[复制链接]

1

主题

4

帖子

20

积分

注册会员

Rank: 2

积分
20
发表于 2011-4-9 14:15:00 | 显示全部楼层 |阅读模式
int lpitch16 = (int)(ddsd.lPitch >> 1);
USHORT *video_buffer = (USHORT *)ddsd.lpSurface;

// plot 1000 random pixels with random colors on the
// primary surface, they will be instantly visible
for (int index=0; index < 1000; index++)
    {
    // select random position and color for 640x480x16
    int red   = rand()%256;
    int green = rand()%256;
    int blue  = rand()%256;
    int x = rand()%800;
    int y = rand()%600;

    // plot the pixel
    Plot_Pixel_Faster16(x,y,red,green,blue,video_buffer,lpitch16);      

    } // end for index

inline void Plot_Pixel_Faster16(int x, int y,
                                int red, int green, int blue,
                                USHORT *video_buffer, int lpitch16)
{
// this function plots a pixel in 16-bit color mode
// assuming that the caller already locked the surface
// and is sending a pointer and byte pitch to it

// first build up color WORD
USHORT pixel = _RGB16BIT565(red,green,blue);

// write the data
video_buffer[x + y*lpitch16] = pixel;

} // end Plot_Pixel_Faster16
//======================================分割线=============================================
int mempitch        = (int)ddsd.lPitch;
USHORT *video_buffer = (USHORT *)ddsd.lpSurface;

// plot 1000 random pixels with random colors on the
// primary surface, they will be instantly visible
for (int index=0; index < 1000; index++)
    {
    // select random position and color for 640x480x16
    USHORT color = rand()%256;
    int x = rand()%800;
    int y = rand()%600;

    // plot the pixel
    video_buffer[x+y*mempitch>>1] = color;        

    } // end for index
///////////////////////////////////==========================================================================
我知道问题应该是出现在lPitch上,但是想不通,在相同的视频模式下,第一个可以全屏填充像素,但是第二个只能填充全屏的一半:左边,另外一边为空,希望大家能帮我解决下,谢谢。
注:
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned char  UCHAR;
typedef unsigned char  BYTE;

1

主题

4

帖子

20

积分

注册会员

Rank: 2

积分
20
 楼主| 发表于 2011-4-11 07:19:00 | 显示全部楼层

Re:lPitch问题求教

我已经知道问题所在了,原来是16位的问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-6-8 06:05

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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