/**-----------------------------------------------------------------------------
 * 초기화 객체들 소거
 *------------------------------------------------------------------------------
 */
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();
    }
}
示例#2
0
	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;
	}
示例#3
0
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);
}
示例#4
0
//-------------------------------------------------------------------------------------------------
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);
}
示例#5
0
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);
}	
示例#6
0
void DevState::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
	ods("D3D9: Blit %d %d %d %d", x, y, w, h);

	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);
}
示例#7
0
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);
   }
}
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;
}
/**-----------------------------------------------------------------------------
 * 초기화 객체들 소거
 *------------------------------------------------------------------------------
 */
VOID Cleanup()
{
	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();
	}

	delete[] g_pvHeightMap;
}
示例#10
0
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;
}
示例#11
0
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;
}
示例#12
0
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
}
示例#13
0
/* 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");
   }
}
示例#14
0
void Game_End()
{
    if (imgShip) imgShip->Release();
	if (imgAsteroid) imgAsteroid->Release();

    DirectInput_Shutdown();
    Direct3D_Shutdown();
}
示例#15
0
void freeTexture() {
  if (hmap_o) delete[] hmap_o; hmap_o = NULL;
  if (dmap  ) delete[] dmap  ; dmap   = NULL;

  if (tnrm) tnrm->Release(); tnrm = NULL;
  if (thgt) thgt->Release(); thgt = NULL;
  if (tcol) tcol->Release(); tcol = NULL;
}
示例#16
0
文件: D3D9.cpp 项目: Borsos/RubikCube
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;
}
示例#17
0
void Cleanup()
{
	// 폰트를 release 한다.
	if (gpFont)
	{
		gpFont->Release();
		gpFont = NULL;
	}

	// 모델을 release 한다.
	if (gpSphere)
	{
		gpSphere->Release();
		gpSphere = NULL;
	}

	// 쉐이더를 release 한다.
	if (gpNormalMappingShader)
	{
		gpNormalMappingShader->Release();
		gpNormalMappingShader = NULL;
	}

	// 텍스처를 release 한다.
	if (gpStoneDM)
	{
		gpStoneDM->Release();
		gpStoneDM = NULL;
	}

	if (gpStoneSM)
	{
		gpStoneSM->Release();
		gpStoneSM = NULL;
	}

	if (gpStoneNM)
	{
		gpStoneNM->Release();
		gpStoneNM = NULL;
	}

	// D3D를 release 한다.
	if (gpD3DDevice)
	{
		gpD3DDevice->Release();
		gpD3DDevice = NULL;
	}

	if (gpD3D)
	{
		gpD3D->Release();
		gpD3D = NULL;
	}
}
示例#18
0
//-------------------------------------------------------------
// 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;
}
示例#19
0
// シーンの描画
void DrawScene(void* data)
{
#if 1
	struct vertex 
	{
	    FLOAT x, y, z, rhw;
		FLOAT tu, tv;
	};
	vertex v[4] = 
	{
		{0,                        0, 0.0f, 1.0f, 0.0f, 0.0f},
		{SCREEN_WIDTH,             0, 0.0f, 1.0f, 1.0f, 0.0f},
		{0,            SCREEN_HEIGHT, 0.0f, 1.0f, 0.0f, 1.0f},
		{SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, 1.0f, 1.0f, 1.0f},
	};

	D3DLOCKED_RECT pRect;
	DWORD time,lasttime;
	lasttime = timeGetTime();
	time = lasttime;

	while(true)
	{
		time = timeGetTime();
		if(time-lasttime >= 1000*10)
		{
			g_tex->LockRect(0, &pRect, NULL, D3DLOCK_DISCARD);
			for(int y = 0; y<SCREEN_HEIGHT; y++)
			{
				for(int x = 0; x<SCREEN_WIDTH; x++)
				{
					DWORD color = 0x00ff00ff;
					color = (edupt::to_int(image[y*SCREEN_WIDTH+x].x_)<<16) + (edupt::to_int(image[y*SCREEN_WIDTH+x].y_)<<8) + edupt::to_int(image[y*SCREEN_WIDTH+x].z_);
					memcpy((BYTE*)pRect.pBits+pRect.Pitch*y + 4*x, &color, sizeof(DWORD));
				}
			}
			g_tex->UnlockRect(0);
			lasttime = time;
		}

		g_pD3DDev->BeginScene();
		g_pD3DDev->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_RGBA(128,128,128,0),1.0f,0);

		g_pD3DDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);

		g_pD3DDev->SetTexture(0, g_tex);
		g_pD3DDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(vertex));

		g_pD3DDev->EndScene();
		g_pD3DDev->Present(NULL, NULL, NULL, NULL);
	}
#endif
}
示例#20
0
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
}
示例#21
0
	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;
	}
VOID Cleanup()
{
	if ( g_pMeshMaterials != NULL )
		delete[] g_pMeshMaterials;

	if ( g_pMeshTextures )
	{
		for ( DWORD i = 0; i < g_dwNumMaterials; ++i )
		{
			if ( g_pMeshTextures[i] )
			{
				g_pMeshTextures[i]->Release();
			}
		}
	}

	if ( g_pMesh )
	{
		g_pMesh->Release();
	}

	if ( g_pTexture1 != NULL )
	{
		g_pTexture1->Release();
	}

	if ( g_pTexture2 != NULL )
	{
		g_pTexture2->Release();
	}

	if ( g_pVB1 != NULL )
	{
		g_pVB1->Release();
	}

	if ( g_pVB2 != NULL )
	{
		g_pVB2->Release();
	}

	if ( g_pd3dDevice != NULL )
	{
		g_pd3dDevice->Release();
	}

	if ( g_pD3D != NULL )
	{
		g_pD3D->Release();
	}
}
/**-----------------------------------------------------------------------------
 * 정점버퍼를 생성하고 정점값을 채워넣는다.
 * HeightMap정보도 여기서 초기화한다.
 *------------------------------------------------------------------------------
 */
HRESULT InitVB()
{
	D3DSURFACE_DESC		ddsd;
	D3DLOCKED_RECT		d3drc;

	g_pTexHeight->GetLevelDesc( 0, &ddsd );	// 텍스처의 정보
	g_cxHeight = ddsd.Width;				// 텍스처의 가로크기
	g_czHeight = ddsd.Height;				// 텍스처의 세로크기
	g_pLog->Log( "Texture Size:[%d,%d]", g_cxHeight, g_czHeight );
	g_pvHeightMap = new D3DXVECTOR3[g_cxHeight * g_czHeight];	// 높이맵배열 생성

	if ( FAILED( g_pd3dDevice->CreateVertexBuffer( ddsd.Width*ddsd.Height*sizeof( CUSTOMVERTEX ),
		0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
	{
		return E_FAIL;
	}

	// 텍스처 메모리 락!
	g_pTexHeight->LockRect( 0, &d3drc, NULL, D3DLOCK_READONLY );
    VOID* pVertices;
	// 정점버퍼 락!
	if ( FAILED( g_pVB->Lock( 0, g_cxHeight*g_czHeight*sizeof( CUSTOMVERTEX ), (void**)&pVertices, 0 ) ) )
	{
		return E_FAIL;
	}

	CUSTOMVERTEX	v;
	CUSTOMVERTEX*	pV = (CUSTOMVERTEX*)pVertices;
	for ( DWORD z = 0; z < g_czHeight; z++ )
	{
		for ( DWORD x = 0; x < g_cxHeight; x++ )
		{
			v.p.x = (float)x - g_cxHeight / 2.0f;		// 정점의 x좌표(메시를 원점에 정렬)
			v.p.z = -( (float)z - g_czHeight / 2.0f );	// 정점의 z좌표(메시를 원점에 정렬), z축이 모니터안쪽이므로 -를 곱한다.
			v.p.y = ( (float)( *( (LPDWORD)d3drc.pBits + x + z*( d3drc.Pitch / 4 ) ) & 0x000000ff ) ) / 10.0f;	/// DWORD이므로 pitch/4
			v.n.x = v.p.x;
			v.n.y = v.p.y;
			v.n.z = v.p.z;
			D3DXVec3Normalize( &v.n, &v.n );
			v.t.x = (float)x / ( g_cxHeight - 1 );
			v.t.y = (float)z / ( g_czHeight - 1 );
			*pV++ = v;									// 정점버퍼에 정점 저장
			g_pvHeightMap[z * g_cxHeight + x] = v.p;	// 높이맵에 정점 저장
		}
	}

    g_pVB->Unlock();
	g_pTexHeight->UnlockRect( 0 );

    return S_OK;
}
示例#24
0
HRESULT VertexObject::CreateTextureFromSurface(LPDIRECT3DSURFACE9 pSurface, RECT* pSrcRect, RECT* pDestRect, LPDIRECT3DTEXTURE9* ppTexture)
{
	int width, height;
	RECT Src;
	D3DSURFACE_DESC surfDesc;
	pSurface->GetDesc(&surfDesc);

	if( !pSrcRect )
	{
		width = surfDesc.Width;
		height = surfDesc.Height;
		Src.left = Src.top = 0;
		Src.right = width;
		Src.bottom = height;
	}
	else
	{
		width = pSrcRect->right - pSrcRect->left; // + 1;
		height = pSrcRect->bottom - pSrcRect->top; // + 1;
		Src = *pSrcRect;
	}

	D3DXCreateTexture(DDevice, width, height, 
	1, 0, surfDesc.Format, D3DPOOL_DEFAULT, ppTexture) ;

	// Retrieve the surface image of the texture.
	LPDIRECT3DSURFACE9 pTexSurface;
	LPDIRECT3DTEXTURE9 pTexture = *ppTexture;
	pTexture->GetLevelDesc(0, &surfDesc);
	pTexture->GetSurfaceLevel(0, &pTexSurface);

	// Create a clean surface to clear the texture with.
	LPDIRECT3DSURFACE9 pCleanSurface;
	D3DLOCKED_RECT lockRect;
	DDevice->CreateOffscreenPlainSurface(
	surfDesc.Width, surfDesc.Height, surfDesc.Format, D3DPOOL_DEFAULT, &pCleanSurface, NULL);
	pCleanSurface->LockRect(&lockRect, NULL, 0) ;
	memset((BYTE*)lockRect.pBits, 0, surfDesc.Height * lockRect.Pitch);
	pCleanSurface->UnlockRect() ;

	DDevice->UpdateSurface(pCleanSurface, NULL, pTexSurface, NULL);
	pCleanSurface->Release();

	// Copy the image to the texture.
	POINT destPoint = { 0, 0 };
	DDevice->UpdateSurface(pSurface, &Src, pTexSurface, &destPoint);
	pTexSurface->Release();

	return S_OK;
}
示例#25
0
/*  CDirect3D::BlankTexture
clears a texture (fills it with zeroes)
IN:
texture		-	the texture to be blanked
-----
returns true if successful, false otherwise
*/
bool CDirect3D::BlankTexture(LPDIRECT3DTEXTURE9 texture)
{
	D3DLOCKED_RECT lr;
	HRESULT hr;

	if(FAILED(hr = texture->LockRect(0, &lr, NULL, 0))) {
		DXTRACE_ERR_MSGBOX(TEXT("Unable to lock texture"), hr);
		return false;
	} else {
		memset(lr.pBits, 0, lr.Pitch * quadTextureSize);
		texture->UnlockRect(0);
		return true;
	}
}
示例#26
0
int surface_create(int width, int height, bool depthbuffer, bool, bool)
{
  LPDIRECT3DTEXTURE9 texture = NULL;
  d3ddev->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
  enigma::Surface* surface = new enigma::Surface();
  enigma::DX9Texture* gmTexture = new enigma::DX9Texture(texture);
  const int texid = enigma::textures.size();
  enigma::textures.push_back(gmTexture);
  //d3ddev->CreateRenderTarget(width, height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 2, false, &surface->surf, NULL);
  texture->GetSurfaceLevel(0,&surface->surf);
  surface->texture = texid; surface->width = width; surface->height = height;
  enigma::surfaces.push_back(surface);
  return enigma::surfaces.size() - 1;
}
示例#27
0
void AmjuGLDX9::SetTexture(
  AmjuGL::TextureHandle* th, 
  AmjuGL::TextureType tt, 
  AmjuGL::TextureDepth td,  
  int width, 
  int height, 
  uint8* data)
{
  AMJU_CALL_STACK;

  HRESULT res = D3DXCreateTexture(
    dd, //LPDIRECT3DDEVICE9 pDevice,
    width, //UINT Width,
    height, //UINT Height,
    0, //  Mip Levels: 0 means create all
    D3DUSAGE_DYNAMIC, //DWORD Usage,
    (td == AmjuGL::AMJU_RGB ? D3DFMT_R8G8B8 : D3DFMT_A8R8G8B8), //D3DFORMAT Format,
    D3DPOOL_DEFAULT, // Pool,
    reinterpret_cast<LPDIRECT3DTEXTURE9*>(th) //LPDIRECT3DTEXTURE9 * ppTexture
  );

  LPDIRECT3DTEXTURE9 pTex = reinterpret_cast<LPDIRECT3DTEXTURE9>(*th);

  D3DLOCKED_RECT lockedRect;
  pTex->LockRect(0, &lockedRect, NULL, 0);

  switch (td)
  {
  case AmjuGL::AMJU_RGB:
    CopyRGBTexture((uint8*)lockedRect.pBits, lockedRect.Pitch, data, width, height); 
    break;
  case AmjuGL::AMJU_RGBA:
    CopyRGBATexture((uint8*)lockedRect.pBits, lockedRect.Pitch, data, width, height); 
    break;
  }

  pTex->UnlockRect(0);

  // TODO Create data for each mipmap level.
  // NB We want the same functionality as screenshot shrinking.
  IDirect3DSurface9 * pSurfaceLevel;
  for (unsigned int iLevel = 0; iLevel < pTex->GetLevelCount(); iLevel++)
  {
    pTex->GetSurfaceLevel(iLevel, &pSurfaceLevel);

    // TODO Write this mip map
    
    pSurfaceLevel->Release();
  }
}
VOID Cleanup()
{
	if (NULL != g_pMeshMaterials0)
	{
		delete [] g_pMeshMaterials0;
	}
	if (g_pMeshTextures0)
	{
		for (DWORD i = 0; i < g_dwNumMaterials; ++i)
		{
			if (g_pMeshTextures0[i])
			{
				g_pMeshTextures0[i]->Release();
			}
		}
		delete [] g_pMeshTextures0;
	}
	if (NULL != g_pMesh0)
	{
		g_pMesh0->Release();
	}


	if (NULL != g_pTexture0)
	{
		g_pTexture0->Release();
	}
	if (NULL != g_pTexture1)
	{
		g_pTexture1->Release();
	}
	if (NULL != g_pVertexBuffer0)
	{
		g_pVertexBuffer0->Release();
	}
	if (NULL != g_pVertexBuffer1)
	{
		g_pVertexBuffer1->Release();
	}

	if (NULL != g_pD3DDevice)
	{
		g_pD3DDevice->Release();
	}

	if (NULL != g_pD3D)
	{
		g_pD3D->Release();
	}
}
示例#29
0
// returns the index this texture is in class
int CNumberToSprite::AddTexture(IDirect3DDevice9* pd3dDevice, LPCWSTR numberFileName)
{
    HRESULT hr;
    LPDIRECT3DTEXTURE9 pTex;
    V( D3DXCreateTextureFromFile(pd3dDevice, numberFileName, &pTex) );

    // get length
    D3DSURFACE_DESC desc;
    V( pTex->GetLevelDesc(0, &desc) );

    m_vSpacing.push_back((float)desc.Width / m_nSYMBOLS);
    m_vpTex.push_back(pTex);

    return (int)(m_vpTex.size() - 1);
}
示例#30
0
	virtual const char* lock_framebuffer( void *& buffer, unsigned & pitch )
	{
		if ( retry_count && !restore_objects() ) return "Lock failed";

		lptex->GetLevelDesc(0, &d3dsd);
		if ( lptex->GetSurfaceLevel(0, &lpsurface) != D3D_OK )
			return "Lock failed";

		if ( lpsurface->LockRect(&d3dlr, 0, flags.lock) != D3D_OK )
			return "Lock failed";
		buffer = d3dlr.pBits;
		pitch = d3dlr.Pitch;

		return buffer != 0 ? 0 : "Lock failed";
	}