本文整理汇总了C++中LPDIRECT3DTEXTURE9类的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DTEXTURE9类的具体用法?C++ LPDIRECT3DTEXTURE9怎么用?C++ LPDIRECT3DTEXTURE9使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPDIRECT3DTEXTURE9类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool AlphaMap::init(bool pAlphaCheck, LPDIRECT3DTEXTURE9 pTexture)
{
d_solid = true;
if (!pAlphaCheck)
return false;
D3DSURFACE_DESC surfaceDesc;
pTexture->GetLevelDesc(0, &surfaceDesc);
d_width = surfaceDesc.Width;
d_height = surfaceDesc.Height;
d_mask.resize(d_width * d_height);
D3DLOCKED_RECT lockedRect;
if (SUCCEEDED(pTexture->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD)))
{
unsigned char* bits = (unsigned char*)lockedRect.pBits;
for (int y = 0; y < d_height; ++y)
{
for (int x = 0; x < d_width; ++x)
{
bool solid = (bits[x * 4 + y * lockedRect.Pitch + 3] != 0);
d_mask[x + y * d_width] = solid;
if (!solid)
d_solid = false;
}
}
pTexture->UnlockRect(0);
}
return true;
}
示例2:
//-------------------------------------------------------------------------------------------------
sdMemoryTexture::sdMemoryTexture(LPDIRECT3DTEXTURE9 spD3DTexture)
{
NIASSERT(spD3DTexture);
// 获取渲染设备
NiDX9Renderer* spRenderer = NiDX9Renderer::GetRenderer();
NIASSERT(spRenderer);
// 提取格式信息
D3DSURFACE_DESC kLevelDesc;
spD3DTexture->GetLevelDesc(0, &kLevelDesc);
m_uiWidth = kLevelDesc.Width;
m_uiHeight = kLevelDesc.Height;
m_uiLevel = spD3DTexture->GetLevelCount();
m_eFormat = kLevelDesc.Format;
//
m_spD3DTexture = spD3DTexture;
m_spD3DTexture->AddRef();
// 创建GB纹理对象
m_spTexture = spRenderer->CreateNiTextureFromD3DTexture(m_spD3DTexture);
NIASSERT(m_spTexture);
}
示例3:
int RendererD3D::InitializeTextureFromBits(byte* pImageBits, int width, int height)
{
HRESULT result;
LPDIRECT3DSURFACE9 surface=NULL;
LPDIRECT3DTEXTURE9 texture = NULL;
result = D3DXCreateTexture( m_pd3dDevice, width, height, D3DX_DEFAULT, 0, D3DFMT_R8G8B8,D3DPOOL_MANAGED, &texture);
texture->GetSurfaceLevel(0, &surface);
RECT rect;
rect.top = 0;
rect.left = 0;
rect.bottom = height;
rect.right = width;
result = D3DXLoadSurfaceFromMemory(surface,NULL,NULL,pImageBits,D3DFMT_R8G8B8, width*3*sizeof(byte),NULL,&rect,D3DX_DEFAULT,0);
surface->Release();
assert(result == D3D_OK);
m_textureList.push_back(texture);
return (m_textureList.size()-1);
}
示例4: d3d_unlock_region
static void d3d_unlock_region(ALLEGRO_BITMAP *bitmap)
{
ALLEGRO_BITMAP_D3D *d3d_bmp = (ALLEGRO_BITMAP_D3D *)bitmap;
d3d_bmp->modified = true;
if (bitmap->locked_region.format != 0 && bitmap->locked_region.format != bitmap->format) {
if (!(bitmap->lock_flags & ALLEGRO_LOCK_READONLY)) {
_al_convert_bitmap_data(
bitmap->locked_region.data, bitmap->locked_region.format, bitmap->locked_region.pitch,
d3d_bmp->locked_rect.pBits, bitmap->format, d3d_bmp->locked_rect.Pitch,
0, 0, 0, 0, bitmap->lock_w, bitmap->lock_h);
}
al_free(bitmap->locked_region.data);
}
if (d3d_bmp->is_backbuffer) {
ALLEGRO_DISPLAY_D3D *d3d_disp = (ALLEGRO_DISPLAY_D3D *)bitmap->display;
d3d_disp->render_target->UnlockRect();
}
else {
LPDIRECT3DTEXTURE9 texture;
if (_al_d3d_render_to_texture_supported())
texture = d3d_bmp->system_texture;
else
texture = d3d_bmp->video_texture;
texture->UnlockRect(0);
if (bitmap->lock_flags & ALLEGRO_LOCK_READONLY)
return;
d3d_do_upload(d3d_bmp, bitmap->lock_x, bitmap->lock_y,
bitmap->lock_w, bitmap->lock_h, false);
}
}
示例5: return
lpta::LptaTexture::DATA LptaD3DTextureManager::GenerateDefaultData(void)
{
LPDIRECT3DTEXTURE9 textureData = nullptr;
D3DLOCKED_RECT d3dLockedRect;
HRESULT result = d3ddev->CreateTexture(
DEFAULT_TEXTURE_WIDTH, DEFAULT_TEXTURE_HEIGHT,
1, 0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&textureData,
nullptr
);
if (FAILED(result)) {
throw TextureD3DFailure("could not obtain texture object for default");
}
result = textureData->LockRect(0, &d3dLockedRect, nullptr, 0);
if (FAILED(result)) {
textureData->Release();
throw TextureD3DFailure("failed to lock rectangle to set default texture color");
}
unsigned long *rawData = (unsigned long *)d3dLockedRect.pBits;
for (unsigned long *pixel = rawData;
pixel < rawData + (DEFAULT_TEXTURE_WIDTH * DEFAULT_TEXTURE_HEIGHT); ++pixel) {
*pixel = DEFAULT_TEXTURE_COLOR;
}
textureData->UnlockRect(0);
return (lpta::LptaTexture::DATA)textureData;
}
示例6: if
D3DFORMAT CDxtexDoc::GetFormat(LPDIRECT3DBASETEXTURE9 ptex)
{
LPDIRECT3DTEXTURE9 pmiptex = NULL;
LPDIRECT3DCUBETEXTURE9 pcubetex = NULL;
LPDIRECT3DVOLUMETEXTURE9 pvoltex = NULL;
D3DFORMAT fmt = D3DFMT_UNKNOWN;
if (IsVolumeMap())
pvoltex = (LPDIRECT3DVOLUMETEXTURE9)ptex;
else if (IsCubeMap())
pcubetex = (LPDIRECT3DCUBETEXTURE9)ptex;
else
pmiptex = (LPDIRECT3DTEXTURE9)ptex;
if (pvoltex != NULL)
{
D3DVOLUME_DESC vd;
pvoltex->GetLevelDesc(0, &vd);
fmt = vd.Format;
}
else if (pcubetex != NULL)
{
D3DSURFACE_DESC sd;
pcubetex->GetLevelDesc(0, &sd);
fmt = sd.Format;
}
else if( pmiptex != NULL )
{
D3DSURFACE_DESC sd;
pmiptex->GetLevelDesc(0, &sd);
fmt = sd.Format;
}
return fmt;
}
示例7: l_Image_Load
int l_Image_Load( lua_State* L )
{
D3DXIMAGE_INFO imgInfo;
const char* fileName = lua_tostring( L, 1 );
bool dxtCompression = false;
D3DFORMAT d3dfmt = D3DFMT_UNKNOWN;
//check for dds format
{
if( _strcmpi( "dds", fileName + strlen( fileName ) - 3 ) == 0 )
{
DDSHEAD header;
FILE* f;
if(fopen_s( &f, fileName, "rb" ) == 0)
{
if( fread( &header, sizeof(header), 1, f ) == 1 )
{
if( strncmp( (const char*)header.Signature, "DDS ", 4 ) == 0 && ( header.FourCC == D3DFMT_DXT1 || header.FourCC == D3DFMT_DXT3 || header.FourCC == D3DFMT_DXT5 ) )
{
d3dfmt = D3DFMT_A8R8G8B8;
}
}
fclose(f);
}
}
}
LPDIRECT3DTEXTURE9 texture;
HRESULT hr = D3DXCreateTextureFromFileEx( g_pd3dDevice, fileName, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_FROM_FILE, 0, d3dfmt, D3DPOOL_SCRATCH, D3DX_DEFAULT, D3DX_DEFAULT, 0, &imgInfo, 0, &texture );
if( FAILED( hr ) )
{
return 0;
}
ImageData* imgData = createImage();
imgData->width = imgInfo.Width;
imgData->height = imgInfo.Height;
imgData->format = getFormatByD3D( imgInfo.Format );
imgData->imgData = malloc( imgData->width * imgData->height * imgData->format->bytesPerPixel );
D3DLOCKED_RECT rect;
texture->LockRect(0, &rect, 0, 0 );
memcpy( imgData->imgData, rect.pBits, imgData->width * imgData->height * imgData->format->bytesPerPixel );
texture->UnlockRect( 0 );
texture->Release();
//lua_pushlightuserdata( L, imgData );
ImageData** luaData = lua_pushimage( L );
*luaData = imgData;
return 1;
}
示例8: convert_compressed
static bool convert_compressed(LPDIRECT3DTEXTURE9 dest, LPDIRECT3DTEXTURE9 src,
int x, int y, int width, int height) {
#ifdef ALLEGRO_CFG_D3DX9
bool ok = true;
LPDIRECT3DSURFACE9 dest_texture_surface = NULL;
LPDIRECT3DSURFACE9 src_texture_surface = NULL;
if (dest->GetSurfaceLevel(0, &dest_texture_surface) != D3D_OK) {
ALLEGRO_ERROR("convert_compressed: GetSurfaceLevel failed on dest.\n");
ok = false;
}
if (ok && src->GetSurfaceLevel(0, &src_texture_surface) != D3D_OK) {
ALLEGRO_ERROR("convert_compressed: GetSurfaceLevel failed on src.\n");
ok = false;
}
RECT rect;
rect.left = x;
rect.top = y;
rect.right = x + width;
rect.bottom = y + height;
if (ok && _al_imp_D3DXLoadSurfaceFromSurface &&
_al_imp_D3DXLoadSurfaceFromSurface(dest_texture_surface,
NULL,
&rect,
src_texture_surface,
NULL,
&rect,
D3DX_FILTER_NONE,
0) != D3D_OK) {
ALLEGRO_ERROR("convert_compressed: D3DXLoadSurfaceFromSurface failed.\n");
ok = false;
}
int i;
if (src_texture_surface) {
if ((i = src_texture_surface->Release()) != 0) {
ALLEGRO_DEBUG("convert_compressed (src) ref count == %d\n", i);
}
}
if (dest_texture_surface) {
if ((i = dest_texture_surface->Release()) != 0) {
// This can be non-zero
ALLEGRO_DEBUG("convert_compressed (dest) ref count == %d\n", i);
}
}
return ok;
#else
(void)dest;
(void)src;
(void)x;
(void)y;
(void)width;
(void)height;
return false;
#endif
}
示例9: d3d_sync_bitmap_texture
/* Copy bitmap->memory to texture memory */
static void d3d_sync_bitmap_texture(ALLEGRO_BITMAP *bitmap,
int x, int y, int width, int height)
{
D3DLOCKED_RECT locked_rect;
RECT rect;
ALLEGRO_BITMAP_D3D *d3d_bmp = (ALLEGRO_BITMAP_D3D *)bitmap;
LPDIRECT3DTEXTURE9 texture;
rect.left = x;
rect.top = y;
rect.right = x + width;
rect.bottom = y + height;
if (_al_d3d_render_to_texture_supported())
texture = d3d_bmp->system_texture;
else
texture = d3d_bmp->video_texture;
if (texture->LockRect(0, &locked_rect, &rect, 0) == D3D_OK) {
_al_convert_bitmap_data(bitmap->memory, bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits, bitmap->format, locked_rect.Pitch,
x, y, 0, 0, width, height);
/* Copy an extra row and column so the texture ends nicely */
if (rect.bottom > bitmap->h) {
_al_convert_bitmap_data(
bitmap->memory,
bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits,
bitmap->format, locked_rect.Pitch,
0, bitmap->h-1,
0, height,
width, 1);
}
if (rect.right > bitmap->w) {
_al_convert_bitmap_data(
bitmap->memory,
bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits,
bitmap->format, locked_rect.Pitch,
bitmap->w-1, 0,
width, 0,
1, height);
}
if (rect.bottom > bitmap->h && rect.right > bitmap->w) {
_al_convert_bitmap_data(
bitmap->memory,
bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits,
bitmap->format, locked_rect.Pitch,
bitmap->w-1, bitmap->h-1,
width, height,
1, 1);
}
texture->UnlockRect(0);
}
else {
ALLEGRO_ERROR("d3d_sync_bitmap_texture: Couldn't lock texture to upload.\n");
}
}
示例10:
LPDIRECT3DTEXTURE9 D3D9::CreateTexture(int texWidth, int texHeight, D3DCOLOR color)
{
LPDIRECT3DTEXTURE9 pTexture;
HRESULT hr = D3DXCreateTexture(d3ddevice_,
texWidth,
texHeight,
0,
0,
D3DFMT_A8R8G8B8, // 4 bytes for a pixel
D3DPOOL_MANAGED,
&pTexture);
if (FAILED(hr))
{
MessageBox(NULL, L"Create texture failed", L"Error", 0);
}
// Lock the texture and fill in color
D3DLOCKED_RECT lockedRect;
hr = pTexture->LockRect(0, &lockedRect, NULL, 0);
if (FAILED(hr))
{
MessageBox(NULL, L"Lock texture failed!", L"Error", 0);
}
DWORD sideColor = 0xff000000; // the side line color
int side_width = 10;
// Calculate number of rows in the locked Rect
int rowCount = (texWidth * texHeight * 4 ) / lockedRect.Pitch;
for (int i = 0; i < texWidth; ++i)
{
for (int j = 0; j < texHeight; ++j)
{
int index = i * rowCount + j;
int* pData = (int*)lockedRect.pBits;
if (i <= side_width || i >= texWidth - side_width
|| j <= side_width || j >= texHeight - side_width)
{
memcpy(&pData[index], &sideColor, 4);
}
else
{
memcpy(&pData[index], &color, 4);
}
}
}
pTexture->UnlockRect(0);
return pTexture;
}
示例11: DXTRACE_ERR
//-------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: 디바이스가 생성된후의 초기화
// 프레임버퍼 포맷과 디바이스 종류가 변한뒤에 호출
// 여기서 확보한 메모리는 DeleteDeviceObjects()에서 해제
//-------------------------------------------------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
HRESULT hr;
LPDIRECT3DTEXTURE9 pHeightTexture;
D3DSURFACE_DESC desc;
// 법선맵 생성
D3DUtil_CreateTexture( m_pd3dDevice,// 높이맵 읽기
_T("height.bmp"), &pHeightTexture );
pHeightTexture->GetLevelDesc(0,&desc);// 텍스처 정보 얻기
D3DXCreateTexture(m_pd3dDevice, desc.Width, desc.Height, 0, 0,
D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &m_pNormalMap);// 텍스처 생성
D3DXComputeNormalMap(m_pNormalMap, // 법선맵 생성
pHeightTexture, NULL, 0, D3DX_CHANNEL_RED, 1.0f);
SAFE_RELEASE( pHeightTexture ); // 필요없어진 리소스 해제
// 정점선언 오브젝트 생성
if( FAILED( hr = m_pd3dDevice->CreateVertexDeclaration(
decl, &m_pDecl )))
return DXTRACE_ERR ("CreateVertexDeclaration", hr);
// 주전자 읽기
if(FAILED(hr=m_pMesh ->Create( m_pd3dDevice, _T("t-pot.x"))))
return DXTRACE_ERR( "Load Object", hr );
// 지형 읽기
if(FAILED(hr=m_pMeshBg->Create( m_pd3dDevice, _T("map.x"))))
return DXTRACE_ERR( "Load Ground", hr );
// 셰이더 읽기
LPD3DXBUFFER pErr=NULL;
if( FAILED( hr = D3DXCreateEffectFromFile(
m_pd3dDevice, "hlsl.fx", NULL, NULL,
0 , NULL, &m_pEffect, &pErr ))){
// 셰이더 읽기 실패
MessageBox( NULL, (LPCTSTR)pErr->GetBufferPointer()
, "ERROR", MB_OK);
}else{
m_hTechnique = m_pEffect->GetTechniqueByName( "TShader" );
m_hmWVP = m_pEffect->GetParameterByName( NULL, "mWVP" );
m_hvLightDir = m_pEffect->GetParameterByName( NULL, "vLightDir" );
m_hvColor = m_pEffect->GetParameterByName( NULL, "vColor" );
m_hvEyePos = m_pEffect->GetParameterByName( NULL, "vEyePos" );
m_htDecaleTex= m_pEffect->GetParameterByName( NULL, "DecaleTex" );
m_htNormalMap= m_pEffect->GetParameterByName( NULL, "NormalMap" );
}
SAFE_RELEASE(pErr);
// 폰트
m_pFont->InitDeviceObjects( m_pd3dDevice );
return S_OK;
}
示例12: SetD3DResourcePrivateData
void SetD3DResourcePrivateData(LPDIRECT3DRESOURCE9 res, const char* FName)
{
#if R3D_SET_DEBUG_D3D_NAMES
DWORD sz = strlen(FName);
res->SetPrivateData(WKPDID_D3DDebugObjectName, FName, sz, 0);
void* p = 0;
res->QueryInterface(IID_IDirect3DTexture9, &p);
if(p)
{
LPDIRECT3DTEXTURE9 t = (LPDIRECT3DTEXTURE9)p;
int mipsCount = t->GetLevelCount();
for (int i = 0; i < mipsCount; ++i)
{
LPDIRECT3DSURFACE9 surf;
t->GetSurfaceLevel(i, &surf);
surf->SetPrivateData(WKPDID_D3DDebugObjectName, FName, sz, 0);
surf->Release();
}
t->Release();
return;
}
p = 0;
res->QueryInterface(IID_IDirect3DCubeTexture9, &p);
if(p)
{
LPDIRECT3DCUBETEXTURE9 t = (LPDIRECT3DCUBETEXTURE9)p;
int mipsCount = t->GetLevelCount();
for (int i = 0; i < mipsCount; ++i)
{
for (int j = D3DCUBEMAP_FACE_POSITIVE_X; j <= D3DCUBEMAP_FACE_NEGATIVE_Z; ++j)
{
LPDIRECT3DSURFACE9 surf;
t->GetCubeMapSurface((D3DCUBEMAP_FACES)j, i, &surf);
surf->SetPrivateData(WKPDID_D3DDebugObjectName, FName, sz, 0);
surf->Release();
}
}
t->Release();
return;
}
#endif
}
示例13: imageLoadFromFile
bool Atlas::createTexure_( Logger & _logger, const MAGIC_CHANGE_ATLAS & c, LPDIRECT3DTEXTURE9 * _texture )
{
uint32_t image_width;
uint32_t image_height;
unsigned char * pixels = nullptr;
if( c.data == nullptr )
{
pixels = imageLoadFromFile( c.file, image_width, image_height );
}
else
{
pixels = imageLoadFromMemory( c.data, c.length, image_width, image_height );
}
unsigned char * correct_pixels = pixels;
UINT texture_width = getTexturePOW2( image_width );
UINT texture_height = getTexturePOW2( image_height );
LPDIRECT3DTEXTURE9 texture = NULL;
if( m_pDevice->CreateTexture( texture_width, texture_height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL ) != D3D_OK )
{
return false;
}
D3DLOCKED_RECT lockedRect;
DXCALL texture->LockRect( 0, &lockedRect, NULL, D3DLOCK_DISCARD );
if( lockedRect.pBits == NULL || lockedRect.Pitch == 0 )
{
return false;
}
for( size_t i = 0; i != image_height; ++i )
{
unsigned char * image = correct_pixels + i * image_width * 4;
unsigned char * bits = static_cast<unsigned char *>(lockedRect.pBits) + lockedRect.Pitch * i;
std::copy( image, image + image_width * 4, bits );
}
DXCALL texture->UnlockRect( 0 );
imageFree( pixels );
*_texture = texture;
return true;
}
示例14: Cleanup
/**-----------------------------------------------------------------------------
* 초기화 객체들 소거
*------------------------------------------------------------------------------
*/
VOID Cleanup()
{
if ( g_pTexNormal != NULL )
{
g_pTexNormal->Release();
}
if ( g_pTexHeight != NULL )
{
g_pTexHeight->Release();
}
if ( g_pTexDiffuse != NULL )
{
g_pTexDiffuse->Release();
}
if ( g_pIB != NULL )
{
g_pIB->Release();
}
if ( g_pVB != NULL )
{
g_pVB->Release();
}
if ( g_pd3dDevice != NULL )
{
g_pd3dDevice->Release();
}
if ( g_pD3D != NULL )
{
g_pD3D->Release();
}
}
示例15: blit
void DevState::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
// Blit is called often. Thus, we do not want to always log here.
#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT
ods("D3D9: Blit %d %d %d %d", x, y, w, h);
#endif
if (! texTexture || !a_ucTexture)
return;
D3DLOCKED_RECT lr;
if ((x == 0) && (y == 0) && (w == uiWidth) && (h == uiHeight)) {
if (texTexture->LockRect(0, &lr, NULL, D3DLOCK_DISCARD) != D3D_OK)
return;
} else {
RECT r;
r.left = x;
r.top = y;
r.right = x + w;
r.bottom = y + h;
if (texTexture->LockRect(0, &lr, &r, 0) != D3D_OK)
return;
}
for (unsigned int r=0;r < h;++r) {
unsigned char *dptr = reinterpret_cast<unsigned char *>(lr.pBits) + r * lr.Pitch;
unsigned char *sptr = a_ucTexture + 4 * ((y + r) * uiWidth + x);
memcpy(dptr, sptr, w * 4);
}
texTexture->UnlockRect(0);
}