游戏开发论坛

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

D3D模拟OPENGL里的glReadPixels函数问题

[复制链接]

52

主题

155

帖子

160

积分

注册会员

Rank: 2

积分
160
发表于 2007-4-9 15:36:00 | 显示全部楼层 |阅读模式
以下代码是模拟OPENGL里的glReadPixels函数,就是得到图像内容buffer,我需要对图像进行处理。
有些问题:
为什么要CreateRenderTarget设置一个新的渲染目标?
如果使用 IDirect3DDevice9::GetBackBuffer呢? 有什么差别吗?

int mySetRenderTarget( IDirect3DSurface9 **surf, int width, int height, D3DFORMAT fmt )
{
    HRESULT hr;

    IDirect3DSurface9 *s = 0;

    hr = g_pd3dDevice->CreateRenderTarget( width, height, fmt, D3DMULTISAMPLE_NONE, 0, TRUE, &s, 0 );

    if( FAILED( hr ) )
        return 0;

    *surf = s;

    hr = g_pd3dDevice->SetRenderTarget( 0, s );

    if( FAILED( hr ) )
        return 0;

    return 1;
}

int myReadPixel( IDirect3DSurface9 *surf, int x, int y, mycolor *data )
{
    D3DLOCKED_RECT lr;

    HRESULT hr = surf->LockRect( &lr, 0, D3DLOCK_READONLY );

    if( FAILED( hr ) )
        return 0;

    mycolor *cbuf = ((mycolor*)lr.pBits) + x * 4 + y * lr.Pitch;

    if( !cbuf )
        return 0;

    data->alpha = cbuf->alpha;
    data->red   = cbuf->red;
    data->green = cbuf->green;
    data->blue  = cbuf->blue;

    surf->UnlockRect();
}

15

主题

363

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-4-9 16:26:00 | 显示全部楼层

Re:D3D模拟OPENGL里的glReadPixels函数问题

好像是因为,BackBuffer如果不是某个特殊的格式,是不能Lock的……一般的ARGB8是无法Lock的,我记得是这样~~
而RenderTarget就可以随意Lock
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-4-12 19:36

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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