Esempio n. 1
0
void cleanup()   // it's a dirty job.. but some function has to do it...
{
   if (myRect1)
      delete myRect1;
   if (myRect2)
      delete myRect2;
   if (myRect3)
      delete myRect3;
   if (myRect4)
      delete myRect4;
   if (myRect5)
      delete myRect5;

   if( lpD3DDevice8 != NULL ) 
      lpD3DDevice8->Release();

   if( lpD3D8 != NULL )       
      lpD3D8->Release();

   if( lpD3DXFont != NULL )
      lpD3DXFont->Release();

   if( lpD3DTex1 != NULL )
      lpD3DTex1->Release();
}
Esempio n. 2
0
// XBMC tells us to stop the screensaver
// we should free any memory and release
// any resources we have created.
extern "C" void Stop()
{
    delete world.waterField;
    world.waterField = NULL;
    for (int i = 0; effects[i] != NULL; i++)
        delete effects[i];
    if (g_Texture != NULL)
    {
        g_Texture->Release();
        g_Texture = NULL;
    }
    return;
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
    if( g_pTexture != NULL )
        g_pTexture->Release();

    if( g_pVB != NULL )
        g_pVB->Release();

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

    if( g_pD3D != NULL )
        g_pD3D->Release();
}
Esempio n. 4
0
void LoadTexture()
{
    // Setup our texture
    //long hFile;
    int numTextures = 0;
    static char szSearchPath[512];
    static char szPath[512];
    static char foundTexture[1024];

    strcpy(szPath,world.szTextureSearchPath);
    if (world.szTextureSearchPath[strlen(world.szTextureSearchPath) - 1] != '\\')
        strcat(szPath,"\\");
    strcpy(szSearchPath,szPath);
    strcat(szSearchPath,"*");

    WIN32_FIND_DATA fd;
    HANDLE hFind = FindFirstFile( szSearchPath, &fd);
    if(hFind != INVALID_HANDLE_VALUE)
    {
        do
        {
            int len = (int)strlen(fd.cFileName);
            if (len < 4 || (strcmpi(fd.cFileName + len - 4, ".txt") == 0))
                continue;

            if (rand() % (numTextures+1) == 0) // after n textures each has 1/n prob
            {
                strcpy(foundTexture,szPath);
                strcat(foundTexture,fd.cFileName);
            }
            numTextures++;
        } while( FindNextFile( hFind, &fd));
        FindClose( hFind);
    }


    if (g_Texture != NULL && numTextures > 0)
    {
        g_Texture->Release();
        g_Texture = NULL;
    }

    if (numTextures > 0)
        D3DXCreateTextureFromFileA(g_pd3dDevice, foundTexture, &g_Texture);
}
Esempio n. 5
0
// Loads a font texture and sets it as current font to display
BOOL	D3D_LoadFontTextureByFile ( char *file_path )
{
	D3DSURFACE_DESC desc;

	// Free our old texture
	if (m_pFontTexture)
		m_pFontTexture->Release();

	// Try to load it
	if ( !(D3D_OK == D3DXCreateTextureFromFile ( m_pOrigDDevice, file_path, &m_pFontTexture )) )
		return FALSE;

	m_pFontTexture->GetLevelDesc( 0, &desc );
	m_uiFontWidth = desc.Width;
	m_uiFontHeight = desc.Height;

	return TRUE;
}
Esempio n. 6
0
bool CN3Texture::Convert(D3DFORMAT Format, int nWidth, int nHeight, BOOL bGenerateMipMap)
{
	if(m_lpTexture == NULL) return false;

	D3DSURFACE_DESC dsd;
	m_lpTexture->GetLevelDesc(0, &dsd);
	if(0 >= nWidth || 0 >= nHeight)
	{
		nWidth = dsd.Width;
		nHeight = dsd.Height;
	}

	LPDIRECT3DTEXTURE8 lpTexOld = m_lpTexture;

	m_lpTexture = NULL;
	if(this->Create(nWidth, nHeight, Format, bGenerateMipMap) == false) return false;
	if(bGenerateMipMap)
	{
		LPDIRECT3DSURFACE8 lpTSOld;
		lpTexOld->GetSurfaceLevel(0, &lpTSOld);
		this->GenerateMipMap(lpTSOld); // MipMap 생성
		lpTSOld->Release();
	}
	else
	{
		LPDIRECT3DSURFACE8 lpTSNew;
		LPDIRECT3DSURFACE8 lpTSOld;
		m_lpTexture->GetSurfaceLevel(0, &lpTSNew);
		lpTexOld->GetSurfaceLevel(0, &lpTSOld);
		D3DXLoadSurfaceFromSurface(lpTSNew, NULL, NULL, lpTSOld, NULL, NULL, D3DX_FILTER_NONE, 0); // 첫번재 레벨 서피스 복사.
		lpTSOld->Release();
		lpTSNew->Release();
	}

	lpTexOld->Release(); lpTexOld = NULL;
	
	return true;
}
Esempio n. 7
0
bool CN3Texture::GenerateMipMap(LPDIRECT3DSURFACE8 lpSurfSrc)
{
	if(m_lpTexture == NULL) return false;

	// MipMap 이 몇개 필요한지 계산..
	int nMMC = m_lpTexture->GetLevelCount();
	int nMMC2 = 0;
	for(int nW = m_Header.nWidth, nH = m_Header.nHeight; nW >=4 && nH >= 4; nW /=2, nH /= 2) nMMC2++;

	bool bNeedReleaseSurf = false;
	if(NULL == lpSurfSrc) 
	{
		bNeedReleaseSurf = true;
		if(D3D_OK != m_lpTexture->GetSurfaceLevel(0, &lpSurfSrc)) return false;
	}

	HRESULT rval = D3D_OK;
	if(nMMC < nMMC2) // 적으면 새로 생성..
	{
		LPDIRECT3DTEXTURE8 lpTexOld = m_lpTexture;
		m_lpTexture = NULL;
		rval = this->CreateFromSurface(lpSurfSrc, m_Header.Format, TRUE);
		if(bNeedReleaseSurf) { lpSurfSrc->Release(); lpSurfSrc = NULL; }
		lpTexOld->Release(); lpTexOld = NULL;

		if(D3D_OK == rval)
		{
			m_Header.bMipMap = TRUE;
			return true;
		}
		else
		{
			m_Header.bMipMap = FALSE;
			return FALSE;
		}
	}
	else // MipMap 이 있으면 그냥 표면만 복사
	{
		if(false == bNeedReleaseSurf) // 다른 서피스에서 복사해야 되는 거면 0 레벨도 복사..
		{
			LPDIRECT3DSURFACE8 lpSurfDest;
			m_lpTexture->GetSurfaceLevel(0, &lpSurfDest);
			DWORD dwFilter = D3DX_FILTER_TRIANGLE; // 기본 필터는 없다..
			HRESULT rval = D3DXLoadSurfaceFromSurface(lpSurfDest, NULL, NULL, lpSurfSrc, NULL, NULL, dwFilter, 0); // 작은 맵 체인에 서피스 이미지 축소 복사 
			lpSurfDest->Release(); lpSurfDest = NULL;
		}

		for(int i = 1; i < nMMC2; i++)
		{
			LPDIRECT3DSURFACE8 lpSurfDest, lpSurfUp;
			m_lpTexture->GetSurfaceLevel(i-1, &lpSurfUp);
			m_lpTexture->GetSurfaceLevel(i, &lpSurfDest);
			DWORD dwFilter = D3DX_FILTER_TRIANGLE; // 기본 필터는 없다..
			HRESULT rval = D3DXLoadSurfaceFromSurface(lpSurfDest, NULL, NULL, lpSurfUp, NULL, NULL, dwFilter, 0); // 작은 맵 체인에 서피스 이미지 축소 복사 
			lpSurfDest->Release();
			lpSurfUp->Release();
		}

		if(bNeedReleaseSurf) { lpSurfSrc->Release(); lpSurfSrc = NULL; }
		if(D3D_OK == rval)
		{
			m_Header.bMipMap = TRUE;
			return true;
		}
		else
		{
			m_Header.bMipMap = FALSE;
			return FALSE;
		}
	}
}
Esempio n. 8
0
Filename_notice *prepare_filename_notice(LPDIRECT3DDEVICE8 pd3dDevice,
        char const *filename)
{
    HRESULT result;
    Filename_notice *notice = NULL;
    HDC hDC = NULL;
    HFONT hFont = NULL;
    SIZE size;
    int width, height;
    LPDIRECT3DTEXTURE8 pTexture = NULL;
    LPDIRECT3DVERTEXBUFFER8 pVB = NULL;
    DWORD *pBitmapBits = NULL;
    BITMAPINFO bmi;
    HBITMAP hbmBitmap = NULL;
    D3DLOCKED_RECT d3dlr;
    BYTE *pDstRow;
    int x, y;
   
    hDC = CreateCompatibleDC(NULL);

    SetMapMode(hDC, MM_TEXT);

    hFont = CreateFont(
            FONT_HEIGHT,                // height
            0,                          // width (0 = closest)
            0,                          // escapement (0 = none)
            0,                          // orientation (0 = none)
            FW_NORMAL,                  // bold
            FALSE,                      // italic
            FALSE,                      // underline
            FALSE,                      // strikeout
            DEFAULT_CHARSET,
            OUT_DEFAULT_PRECIS,         // TrueType (OUT_TT_PRECIS) doesn't help
            CLIP_DEFAULT_PRECIS,
            ANTIALIASED_QUALITY,
            VARIABLE_PITCH,
            FONT_NAME);
    if (hFont == NULL) {
        goto done;
    }

    // Set text properties
    SelectObject(hDC, hFont);
    SetTextColor(hDC, RGB(255,255,255));
    SetBkColor(hDC, 0x00000000);
    SetTextAlign(hDC, TA_TOP);

    GetTextExtentPoint32(hDC, filename, strlen(filename), &size);
    width = size.cx;
    height = size.cy;

    // Create a new texture for the font
    result = pd3dDevice->CreateTexture(width, height, 1, 0, D3DFMT_A4R4G4B4,
            D3DPOOL_MANAGED, &pTexture);
    if (FAILED(result)) {
        goto done;
    }

    // Prepare to create a bitmap
    ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = width;
    bmi.bmiHeader.biHeight = -height;       // negative means top-down
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biBitCount = 32;

    hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS,
            (VOID**)&pBitmapBits, NULL, 0);
    SelectObject(hDC, hbmBitmap);

    ExtTextOut(hDC, 0, 0, ETO_OPAQUE, NULL, filename, strlen(filename), NULL);

    // Lock the surface and write the alpha values for the set pixels
    pTexture->LockRect(0, &d3dlr, 0, 0);
    pDstRow = (BYTE*)d3dlr.pBits;

    for (y = 0; y < height; y++) {
        WORD *pDst16 = (WORD *)pDstRow;

        for (x = 0; x < width; x++) {
            BYTE bAlpha = (BYTE)((pBitmapBits[width*y + x] & 0xff) >> 4);

            if (bAlpha > 0) {
                *pDst16++ = (WORD)((bAlpha << 12) | 0x0fff);
            } else {
                *pDst16++ = (WORD)(0x0000);
            }
        }

        pDstRow += d3dlr.Pitch;
    }

    // Done updating texture
    pTexture->UnlockRect(0);

    // Create vertices
    result = pd3dDevice->CreateVertexBuffer(4*sizeof(FONT2DVERTEX),
            D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &pVB);
    if (FAILED(result)) {
        goto done;
    }

    notice = new Filename_notice;
    notice->width = width;
    notice->height = height;
    notice->pd3dDevice = pd3dDevice;
    notice->pTexture = pTexture;
    pTexture = NULL;
    notice->pVB = pVB;
    pVB = NULL;

    pd3dDevice->BeginStateBlock();
    apply_render_state(pd3dDevice);
    pd3dDevice->SetTexture(0, notice->pTexture);
    pd3dDevice->EndStateBlock(&notice->dwSavedStateBlock);

    pd3dDevice->BeginStateBlock();
    apply_render_state(pd3dDevice);
    pd3dDevice->SetTexture(0, notice->pTexture);
    pd3dDevice->EndStateBlock(&notice->dwDrawTextStateBlock);

done:
    if (pVB != NULL) {
        pVB->Release();
    }
    if (pTexture != NULL) {
        pTexture->Release();
    }
    if (hbmBitmap != NULL) {
        DeleteObject(hbmBitmap);
    }
    if (hFont != NULL) {
        DeleteObject(hFont);
    }
    if (hDC != NULL) {
        DeleteDC(hDC);
    }

    return notice;
}