当前位置: 首页>>代码示例>>C++>>正文


C++ IDirect3DTexture9::UnlockRect方法代码示例

本文整理汇总了C++中IDirect3DTexture9::UnlockRect方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DTexture9::UnlockRect方法的具体用法?C++ IDirect3DTexture9::UnlockRect怎么用?C++ IDirect3DTexture9::UnlockRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDirect3DTexture9的用法示例。


在下文中一共展示了IDirect3DTexture9::UnlockRect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _CreateTexture

bool CSprite::_CreateTexture(const CBitmap& _bitmap)
{
	HRESULT hr;
	CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance();
	IDirect3DDevice9 *pD3Device = pGraphicsManager->GetDevice();

	int iWidth = _bitmap.GetWidth();
	int iHeight = _bitmap.GetHeight();

	IDirect3DTexture9 *pSystemTexture = NULL;

	hr = pD3Device->CreateTexture((UINT)iWidth, (UINT)iHeight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM,
		&pSystemTexture, NULL);
	if(FAILED(hr))
	{
		LogError("Failed to create system texture");
		return false;
	}

	D3DLOCKED_RECT lockedRect;
	memset(&lockedRect, 0, sizeof(lockedRect));

	hr = pSystemTexture->LockRect(0, &lockedRect, NULL, 0);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to lock system texture rect", hr);
		return false;
	}

	DWORD *pTexLocation = (DWORD *)lockedRect.pBits;
	for(int iRowIndex = 0; iRowIndex < iHeight; iRowIndex++)
	{
		memcpy(pTexLocation, _bitmap.GetRow(iRowIndex), sizeof(DWORD) * iWidth);

		for(int iColumnIndex = 0; iColumnIndex < iWidth; iColumnIndex++)
		{
			DWORD dwPixel = pTexLocation[iColumnIndex];

			if(dwPixel != g_dwBackgroundColor)
			{
				dwPixel |= 0xff000000l;
				pTexLocation[iColumnIndex] = dwPixel;
			}
		}

		BYTE *pTextureByteLocation = (BYTE *)pTexLocation;
		pTextureByteLocation += lockedRect.Pitch;
		
		pTexLocation = (DWORD *)pTextureByteLocation;
	}

	hr = pSystemTexture->UnlockRect(0);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to unlock system texture rect", hr);
		return false;
	}

	hr = pD3Device->CreateTexture(iWidth, iHeight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pTexture, NULL);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to create video texture", hr);
		return false;
	}

	hr = pD3Device->UpdateTexture(pSystemTexture, m_pTexture);
	if(FAILED(hr))
	{
		LogErrorHr("Failed to update video texture", hr);
		return false;
	}

	pSystemTexture->Release();

	return true;
}
开发者ID:svdmaar,项目名称:Coop,代码行数:76,代码来源:Sprite.cpp

示例2: parseCodeImage

bool parseCodeImage(const char* pszPath)
{
    D3DXIMAGE_INFO info;
    HRESULT re = D3DXGetImageInfoFromFileA(pszPath, &info);
    if(re != S_OK)
        return false;


    IDirect3DTexture9 *pText = NULL;
    //D3DXCreateTextureFromFileA(g_pDevice, pszPath, &pText); //用没有 EX 的函数, 创建的纹理长宽会变成 2的 n次方
    re = D3DXCreateTextureFromFileExA(g_pDevice, pszPath, info.Width, info.Height, 
        info.MipLevels, 0/*D3DUSAGE_RENDERTARGET*/, info.Format, D3DPOOL_SYSTEMMEM, 
        D3DX_FILTER_TRIANGLE,D3DX_FILTER_TRIANGLE,D3DCOLOR_ARGB(255,0,0,0), NULL, NULL, &pText);

    FILE* pFile = fopen("D:/hehe.txt", "w");

    D3DLOCKED_RECT rc;
    pText->LockRect(0, &rc, NULL, 0);

    BYTE bR = 0, bG = 0, bB = 0;

    DWORD* pSrc = (DWORD*)rc.pBits;
    for (int i = 0; i < info.Height ; i++)
    {
        for (int j = 0; j < info.Width; j++)
        {
            bR = (*pSrc) >> 16;
            bG = (*pSrc) << 16 >> 24;
            bB = (*pSrc) & 0x000000ff;

           if (bR >= 205 && bG >= 205 && bB >= 205)
           {
                fprintf(pFile, "1");
           }
           else
           {
               fprintf(pFile, "8");
           }

           BYTE t = max( max(bR, bG), bB);

           *pSrc = t | t << 8 | t << 16;
               

            ++pSrc;

        }

        fprintf(pFile, "\r\n");
    }

    pText->UnlockRect(0);

    // 保存灰度图
    re = D3DXSaveTextureToFileA("D:/hehe.jpg", D3DXIFF_BMP, pText, NULL);

    
    pText->Release();

    fclose(pFile);


}
开发者ID:Riven2Exile,项目名称:TestDX,代码行数:63,代码来源:YanZheng.cpp

示例3: GetDC

bool CreateFontTexture
(
 IDirect3DDevice9* pDev,
 DWORD usage,
 D3DPOOL pool,
 UINT ch,
 Font* pFont
) {
   HDC hdc = GetDC(NULL);
   HFONT hFont = ::CreateFont(0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("MS UI Gothic")); 
   HFONT hOldFont = (HFONT)::SelectObject(hdc, hFont); 

   HRESULT hr;
   int gm_w, gm_h;
   int fnt_x, fnt_y;
   BYTE *bmp_p = NULL;
   int bmp_w, bmp_h; //bmp_p
   {
      TEXTMETRIC tm;
      GLYPHMETRICS gm;
      MAT2 mat2 = { {0,1}, {0,0}, {0,0}, {0,1} };

      GetTextMetrics(hdc, &tm);
      DWORD bufsize = GetGlyphOutline(
         hdc, ch, GGO_GRAY4_BITMAP, &gm, 0, NULL, &mat2);
      if (bufsize == GDI_ERROR) {
         bufsize = GetLastError();
         goto fin;
      }
      bmp_p = (BYTE*)malloc(bufsize);
      DWORD r = GetGlyphOutline(
         hdc, ch, GGO_GRAY4_BITMAP, &gm, bufsize, bmp_p, &mat2);

      pFont->tm_max_w = tm.tmMaxCharWidth;
      pFont->tm_ave_w = tm.tmAveCharWidth;
      gm_w = gm.gmCellIncX;
      gm_h = tm.tmHeight;
      bmp_w = ((gm.gmBlackBoxX + 3) / 4) * 4; //4-align
      bmp_h = gm.gmBlackBoxY;
      fnt_x = gm.gmptGlyphOrigin.x;
      fnt_y = tm.tmAscent - gm.gmptGlyphOrigin.y;
   }

   IDirect3DTexture9* pTex;
   hr = pDev->CreateTexture(gm_w, gm_h, 1,
      usage, D3DFMT_A8R8G8B8, pool,
      &pTex, NULL);

   {
      D3DLOCKED_RECT rect;
      pTex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD);
      FillMemory(rect.pBits, rect.Pitch * gm_h, 0);
      for (int y=0; y<bmp_h; ++y) {
         BYTE* p = ((BYTE*)rect.pBits) + rect.Pitch * (fnt_y + y) + fnt_x * 4;
         for (int x=0; x<bmp_w; ++x) {
            DWORD trans = ((255 * bmp_p[x+y*bmp_w]) /16)&0xFF;
            DWORD color = 0x00FFFFFF | (trans << 24);
            memcpy(p, &color, 4);
            p += 4;
         }
      }
      pTex->UnlockRect(0);
   }
   pFont->pTex = pTex;
   pFont->gm_w = gm_w;
   pFont->gm_h = gm_h;
   pFont->fnt_x = fnt_x;
   pFont->fnt_y = fnt_y;

fin:
   if (bmp_p) { free(bmp_p); }
   SelectObject(hdc, hOldFont); 
   return true;
}
开发者ID:dai1975,项目名称:BootesDances,代码行数:74,代码来源:Font.cpp

示例4: init

void RenderState::init(IDirect3DDevice9* dev) {
    _dev = dev;

    D3DDEVICE_CREATION_PARAMETERS params;
    HRESULT hr = dev->GetCreationParameters(&params);
    if (FAILED(hr)) {
        MM_LOG_INFO(format("Failed to obtain device creation parameters"));
    }
    else {
        _focusWindow = params.hFocusWindow;
    }

    // create "selected" texture
    WCHAR* dataPath = NULL;
    if (Interop::OK()) {
        IDirect3DTexture9 * tex;

        int width = 256;
        int height = 256;
        HRESULT hr = dev->CreateTexture(width, height, 1, 0,
                                        D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, 0);
        if (FAILED(hr)) {
            MM_LOG_INFO("Failed to create 'selection' texture");
        } else {
            _selectionTexture = tex;

            D3DLOCKED_RECT rect;
            hr = tex->LockRect(0, &rect, 0, D3DLOCK_DISCARD);
            if (FAILED(hr)) {
                MM_LOG_INFO("Failed to lock 'selection' texture");
            }
            else {
                unsigned char* dest = static_cast<unsigned char*>(rect.pBits);

                // fill it with a lovely shade of green
                Uint32 numEls = width * height;
                for (Uint32 i = 0; i < numEls; ++i) {
                    Uint32* d = (Uint32*)(dest + (i*sizeof(Uint32)));
                    *d = 0xFF00FF00;
                }
                //MM_LOG_INFO("filled selection texture");
                tex->UnlockRect(0);
            }
        }
    }

    // Set key bindings.  Input also assumes that CONTROL modifier is required for these as well.
    // TODO: should push this out to conf file eventually so that they can be customized without rebuild
    // If you change these, be sure to change LocStrings/ProfileText in MMLaunch!
    _punctKeyMap[DIK_BACKSLASH] = [&]() {
        this->loadMods();
    };
    _punctKeyMap[DIK_RBRACKET] = [&]() {
        this->toggleShowModMesh();
    };
    _punctKeyMap[DIK_SEMICOLON] = [&]() {
        this->clearTextureLists();
    };
    _punctKeyMap[DIK_COMMA] = [&]() {
        this->selectNextTexture();
    };
    _punctKeyMap[DIK_PERIOD] = [&]() {
        this->selectPrevTexture();
    };
    _punctKeyMap[DIK_SLASH] = [&]() {
        this->requestSnap();
    };
    _punctKeyMap[DIK_MINUS] = [&]() {
        this->loadEverything();
    };


    // If you change these, be sure to change LocStrings/ProfileText in MMLaunch!
    _fKeyMap[DIK_F1] = [&]() {
        this->loadMods();
    };
    _fKeyMap[DIK_F2] = [&]() {
        this->toggleShowModMesh();
    };
    _fKeyMap[DIK_F6] = [&]() {
        this->clearTextureLists();
    };
    _fKeyMap[DIK_F3] = [&]() {
        this->selectNextTexture();
    };
    _fKeyMap[DIK_F4] = [&]() {
        this->selectPrevTexture();
    };
    _fKeyMap[DIK_F7] = [&]() {
        this->requestSnap();
    };
    _fKeyMap[DIK_F10] = [&]() {
        this->loadEverything();
    };

    _pCurrentKeyMap = &_fKeyMap;

    if (Interop::OK()) {
        if (Interop::Conf().LoadModsOnStart) {
            loadEverything();
//.........这里部分代码省略.........
开发者ID:Tarek-Samy,项目名称:ModelMod,代码行数:101,代码来源:RenderState.cpp

示例5: Texture_Init_Failure

  IDirect3DTexture9 * Texture_DX9::build_from_Image(const Image &image) {
    Video_DX9 &vdx = dynamic_cast<Video_DX9 &>(get_Video());

    IDirect3DTexture9 * ppTexture;

    D3DFORMAT format;
    switch(image.color_space()) {
      case Image::Luminance:
        format = D3DFMT_L8;
        break;

      case Image::Luminance_Alpha:
        format = D3DFMT_A8B8G8R8;
        break;

      case Image::RGB:
        format = D3DFMT_A8B8G8R8;
        break;

      case Image::RGBA:
        format = D3DFMT_A8B8G8R8;
        break;

      default:
        format = D3DFMT_UNKNOWN;
        abort();
    }

    set_sampler_states();

    if(FAILED(Video_DX9::D3DXCreateTexture()(vdx.get_d3d_device(),
                                             UINT(image.width()), UINT(image.height()),
                                             D3DX_DEFAULT,
                                             0,
                                             format,
                                             D3DPOOL_MANAGED,
                                             &ppTexture)))
      throw Texture_Init_Failure();

    D3DLOCKED_RECT rect;
    if(FAILED(ppTexture->LockRect(0, &rect, 0, 0))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    if(image.color_space() == Image::Luminance) {
      memcpy(rect.pBits, image.get_data(), image.width() * image.height());
    }
    else if(image.color_space() == Image::Luminance_Alpha) {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 2) {
        dest[0] = src[0];
        dest[1] = src[0];
        dest[2] = src[0];
        dest[3] = src[1];
      }
    }
    else if(image.color_space() == Image::RGB) {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 3) {
        dest[0] = src[2];
        dest[1] = src[1];
        dest[2] = src[0];
        dest[3] = 0xFF;
      }
    }
    else /*if(image.color_space() == Image::RGBA)*/ {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 4) {
        dest[0] = src[2];
        dest[1] = src[1];
        dest[2] = src[0];
        dest[3] = src[3];
      }
    }

    if(FAILED(ppTexture->UnlockRect(0))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    if(FAILED(Video_DX9::D3DXFilterTexture()(ppTexture, 0, D3DX_DEFAULT, D3DX_DEFAULT))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    return ppTexture;
  }
开发者ID:ccharri,项目名称:EECS494-Assignment3,代码行数:91,代码来源:Texture.cpp

示例6: LoadElevations

HRESULT Loader::LoadElevations( float **ppImageData, int* nSize, const char * szFilename, bool swapVertical /*= true*/)
{
	float* pImageData = NULL;
	CParaFile cFile;
	cFile.OpenAssetFile(szFilename, true, ParaTerrain::Settings::GetInstance()->GetMediaPath());
	if(cFile.isEof())
		return E_FAIL;
	
	int elevWidth=0;
	int elevHeight=0;

	if(strcmp(szFilename+strlen(szFilename)-4, ".raw") == 0)
	{
		/// Load from raw elevation 
		elevWidth = (int)sqrt((float)(((int)cFile.getSize()/4)));
		elevHeight = elevWidth;
		/// just use the file buffer as the image buffer
		pImageData = (float*)cFile.getBuffer();
		cFile.GiveupBufferOwnership();
	}
	else
	{
#ifdef USE_DIRECTX_RENDERER
		D3DSURFACE_DESC desc;
		IDirect3DTexture9* pTexture = NULL;
		HRESULT hr;

		/// Create a D3DFMT_X8R8G8B8 texture -- use D3DPOOL_SCRATCH to 
		// ensure that this will succeeded independent of the device
		hr = D3DXCreateTextureFromFileInMemoryEx( CGlobals::GetRenderDevice(), cFile.getBuffer(), (int)cFile.getSize(),
			0, 0, 1, 0, 
			D3DFMT_X8R8G8B8, D3DPOOL_SCRATCH, 
			D3DX_FILTER_NONE, D3DX_FILTER_NONE,
			0, NULL, NULL, &pTexture );
		if( FAILED(hr) )
			return hr;

		pTexture->GetLevelDesc( 0, &desc ); 

		elevWidth = desc.Width;
		elevHeight = desc.Height;

		// create an array of floats to store the values of the bmp
		pImageData = new float[elevWidth * elevHeight];

		if( pImageData == NULL )
		{
			SAFE_RELEASE( pTexture );
			return E_OUTOFMEMORY;
		}

		//ZeroMemory( pImageData, elevWidth * elevHeight * sizeof(FLOAT) );

		D3DLOCKED_RECT lockedRect;

		hr = pTexture->LockRect( 0, &lockedRect, NULL, D3DLOCK_READONLY );
		float fMin=1.0f,fMax=-1.0f;
		if( SUCCEEDED(hr) )
		{
			DWORD* pBuffer = (DWORD*) lockedRect.pBits;
			for( DWORD iY=0; iY<desc.Height; iY++ )
			{
				pBuffer = (DWORD*)((BYTE*)lockedRect.pBits + lockedRect.Pitch * iY);

				for( DWORD iX=0; iX<desc.Width; iX++ )
				{
					LinearColor color((DWORD)(*pBuffer));
					float fValue = (color.r+color.g+color.b)/3.0f-0.5f;
					if (fValue<fMin)
						fMin = fValue;
					if (fValue>fMax)
						fMax = fValue;

					if (swapVertical)
					{
						// Invert Y, so it appears the same as the bmp
						pImageData[ (desc.Height-1-iY)*elevWidth + iX] = fValue;
					}
					else
					{
						pImageData[ iY*elevWidth + iX] = fValue;
					}
					pBuffer++;
				}
			}
			pTexture->UnlockRect( 0 );

			/// Normalize all values between 0.0f and 1.0f
			/*float fHeight = (fMax-fMin);
			for( DWORD iY=0; iY<desc.Height; iY++ )
			{
			for( DWORD iX=0; iX<desc.Width; iX++ )
			{
			pImageData[ iY*elevWidth + iX] = (pImageData[ iY*elevWidth + iX]-fMin)/fHeight;
			}
			}*/
		}
		SAFE_RELEASE( pTexture );
#else 
		return E_FAIL;
//.........这里部分代码省略.........
开发者ID:LiXizhi,项目名称:NPLRuntime,代码行数:101,代码来源:Loader.cpp


注:本文中的IDirect3DTexture9::UnlockRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。