游戏开发论坛

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

DirectDraw,求助! 使用自定义的surfaceMemory创建Surface时,返回

[复制链接]

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2011-6-5 07:33:00 | 显示全部楼层 |阅读模式
代码如下:
LPDIRECTDRAW lpDDraw;
struct
{
        int Width;
        int Height;
        int PixelPerLine; //
        LPVOID ScreenColorBits_Ptr;//
        RECT ScreenRect;//
} Context_Screen_Ptr;

void CreateSurfaceFromContextScreen (LPDIRECTDRAWSURFACE * lplpDDSurface)
{
        *lplpDDSurface= NULL;

        DDSURFACEDESC DDSurfaceDesc_temp;
        DDRAW_INIT_STRUCT( DDSurfaceDesc_temp);
        DDSurfaceDesc_temp.dwFlags|= DDSD_HEIGHT;
        DDSurfaceDesc_temp.dwFlags|= DDSD_WIDTH;
        DDSurfaceDesc_temp.dwFlags|= DDSD_PITCH;
        DDSurfaceDesc_temp.dwFlags|= DDSD_LPSURFACE;
        DDSurfaceDesc_temp.dwFlags|= DDSD_CAPS;

        DDSurfaceDesc_temp.dwHeight= Context_Screen_Ptr->Height;
        DDSurfaceDesc_temp.dwWidth= Context_Screen_Ptr->Width;
        DDSurfaceDesc_temp.lPitch= Context_Screen_Ptr-&gtixelPerLine;//一个字节代表8个bits
        DDSurfaceDesc_temp.lpSurface= Context_Screen_Ptr->ScreenColorBits_Ptr;
        DDSurfaceDesc_temp.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN| DDSCAPS_SYSTEMMEMORY;

        if (DD_OK==lpDDraw->CreateSurface ( &DDSurfaceDesc_temp, lplpDDSurface, NULL))
           {  //这个CreateSurface出错//
                return NULL;
        }
           //....
}
现在可以确定的是,执行到这儿时lpDDraw是对劲的,这个DDraw对象使用的是8bits色彩模式,用了自定义的调色板。全屏独占模式, DDSCL_FULLSCREEN| DDSCL_ALLOWMODEX| DDSCL_EXCLUSIVE| DDSCL_ALLOWREBOOT
那个Context_Screen_Ptr结构的值为:
Context_Screen_Ptr->Widtd= 0x00000280  
Context_Screen_Ptr->Height= 0x000001E0  
Context_Screen_Ptr->PixelPerLine= 0x00000280
Context_Screen_Ptr->ScreenColorBits_Ptr= 0xA3E85A0 //也确定这儿就是有效的surface的缓存

但执行完后,CreateSurface就返回了一个错误的参数, Error 80070057: One or more of the parameters passed to the method are incorrect。
因为我实在是drirectdraw苦手,一点也不通,搞的现在很狼狈又没有办法,只好来发帖询问了,希望路过的大侠能够指教一下。

16

主题

280

帖子

280

积分

中级会员

Rank: 3Rank: 3

积分
280
QQ
发表于 2011-6-5 10:17:00 | 显示全部楼层

Re:DirectDraw,求助! 使用自定义的surfaceMemory创建Surface时,返

// For this example, g_lpDD is a valid IDirectDraw7 interface pointer.

#define WIDTH  64 // in pixels
#define HEIGHT 64
#define DEPTH  3  // in bytes (3bytes == 24 bits)

    HRESULT hr;
    LPVOID  lpSurface  = NULL;
    HLOCAL  hMemHandle = NULL;
    DDSURFACEDESC2 ddsd2;
    LPDIRECTDRAWSURFACE7 lpDDS;

    // Allocate memory for a 64 by 64, 24-bit per pixel buffer.
    // REMEMBER: The application is responsible for freeing this
    //           buffer when it is no longer needed.
    if (lpSurface = malloc((size_t)WIDTH*HEIGHT*DEPTH))
        ZeroMemory(lpSurface, (DWORD)WIDTH*HEIGHT*DEPTH);
    else
        return DDERR_OUTOFMEMORY;

    // Initialize the surface description.
    ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC2));
    ZeroMemory(&ddsd2.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
    ddsd2.dwSize = sizeof(ddsd2);
    ddsd2.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE |
                    DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_CAPS;
    ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
                           DDSCAPS_SYSTEMMEMORY;
    ddsd2.dwWidth = WIDTH;
    ddsd2.dwHeight= HEIGHT;
    ddsd2.lPitch  = (LONG)DEPTH * WIDTH;
    ddsd2.lpSurface = lpSurface;

    // Set up the pixel format for 24-bit RGB (8-8-8).
    ddsd2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
    ddsd2.ddpfPixelFormat.dwFlags= DDPF_RGB;
    ddsd2.ddpfPixelFormat.dwRGBBitCount = (DWORD)DEPTH*8;
    ddsd2.ddpfPixelFormat.dwRBitMask    = 0x00FF0000;
    ddsd2.ddpfPixelFormat.dwGBitMask    = 0x0000FF00;
    ddsd2.ddpfPixelFormat.dwBBitMask    = 0x000000FF;

    // Create the surface
    hr = g_lpDD->CreateSurface(&ddsd2, &lpDDS, NULL);
    return hr;


sdk里面的例子

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2011-6-6 05:38:00 | 显示全部楼层

Re:DirectDraw,求助! 使用自定义的surfaceMemory创建Surface时,返

很感谢你的回复,Direct SDK里的例子我查着查着发现好多是和TV之类相关的实际应用,就没有细看,谢谢你帮忙找到这个。
不过我最后没有把指定lpSurfaceMem的代码写出来,我只是创建了一个临时的surface,在需要的时候,把传来的surfaceMem复制到这个surface里再处理,虽然效率比较差,还暂时可以解决问题了。如果有什么新的进展,我会再回复,也还是希望能有朋友帮下忙
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-6-9 17:55

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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