begin process at 2012 02 08 09:55:27
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

DirectX

 > PLEIN ECRAN + AFFICHAGE DE TEXTE

PLEIN ECRAN + AFFICHAGE DE TEXTE


 Information sur la source

Note :
8,5 / 10 - par 2 personnes
8,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :DirectX Niveau :Initié Date de création :01/11/2001 Vu / téléchargé :10 305 / 415

Auteur : Lightness1024!

Ecrire un message privé
Site perso
Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note

 Description

Necessite les librairies de Direct3D de DirectX8.
telechargables gratuitement sur le site de microsoft avec la SDK DirectX8.

Source

  • /*** Lightness1024! ProgrammatO 01/02/2001 17:38:31 ***
  • *** Base de programme Directx8 plein ecran ***/
  • #include <d3d8.h>
  • #include <D3dx8core.h>
  • #ifdef UNICODE
  • #define _tWinMain wWinMain
  • #else
  • #define _tWinMain WinMain
  • #endif
  • // Variables globales:
  • LPDIRECT3D8 g_pD3D = NULL; // pour faire l'objet d3d8
  • LPDIRECT3DDEVICE8 g_pd3dDevice = NULL; // le materiel de rendu
  • LPDIRECT3DVERTEXBUFFER8 g_pVB = NULL; // la zone des vertices (non utilisé encore)
  • // Initialisation de Direct3D
  • HRESULT InitD3D( HWND hWnd )
  • {
  • // Create the D3D object, which is needed to create the D3DDevice.
  • if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
  • return E_FAIL;
  • // Get the current desktop display mode
  • D3DDISPLAYMODE d3ddm;
  • d3ddm.Width = 1024;
  • d3ddm.Height = 768;
  • d3ddm.Format = D3DFMT_R5G6B5;
  • d3ddm.RefreshRate = 0;
  • // Au cas où on veut détecter les paramètres courants:
  • /*if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
  • return E_FAIL;*/
  • D3DPRESENT_PARAMETERS d3dpp;
  • ZeroMemory( &d3dpp, sizeof(d3dpp) );
  • d3dpp.Windowed = FALSE;
  • d3dpp.BackBufferWidth = 1024;
  • d3dpp.BackBufferHeight = 768;
  • d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  • d3dpp.BackBufferFormat = d3ddm.Format;
  • d3dpp.hDeviceWindow = hWnd;
  • d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
  • d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
  • d3dpp.BackBufferCount = 1;
  • d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
  • d3dpp.EnableAutoDepthStencil = FALSE;
  • //d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  • // software : D3DDEVTYPE_REF
  • if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
  • D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  • &d3dpp, &g_pd3dDevice ) ) )
  • {
  • return E_FAIL;
  • }
  • // c bon
  • // le debut de l'initialisation du vertex buffer
  • //if (FAILED (g_pd3dDevice->CreateVertexBuffer (3,
  • return S_OK;
  • }
  • // Nettoie tout le bordel
  • VOID Cleanup()
  • {
  • if( g_pd3dDevice != NULL)
  • g_pd3dDevice->Release();
  • if( g_pD3D != NULL)
  • g_pD3D->Release();
  • }
  • // Calcul du rendu
  • VOID Render()
  • {
  • if( NULL == g_pd3dDevice )
  • return;
  • LPD3DXFONT pD3DXFont;
  • LOGFONT lf;
  • ZeroMemory (&lf, sizeof(LOGFONT));
  • lf.lfHeight = 200;
  • lf.lfWeight = 45;
  • if (FAILED (D3DXCreateFontIndirect(g_pd3dDevice, &lf, &pD3DXFont)))
  • return;
  • RECT rct;
  • rct.left = 0;
  • rct.top = 0;
  • rct.bottom = 768;
  • rct.right = 1024;
  • // Clear the backbuffer
  • g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(128,128,128), 1.0f, 0 );
  • // Begin the scene
  • g_pd3dDevice->BeginScene();
  • // Trucs a tracer:
  • pD3DXFont->DrawText (TEXT("hello world"), -1, &rct, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(255, 255, 255));
  • // End the scene
  • g_pd3dDevice->EndScene();
  • // Present the backbuffer contents to the display
  • g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
  • }
  • //-----------------------------------------------------------------------------
  • // Name: MsgProc()
  • // Desc: The window's message handler
  • //-----------------------------------------------------------------------------
  • LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  • {
  • switch( msg )
  • {
  • case WM_DESTROY:
  • PostQuitMessage( 0 );
  • return 0;
  • case WM_PAINT:
  • Render();
  • ValidateRect( hWnd, NULL );
  • return 0;
  • }
  • return DefWindowProc( hWnd, msg, wParam, lParam );
  • }
  • //-----------------------------------------------------------------------------
  • // Name: WinMain()
  • // Desc: The application's entry point
  • //-----------------------------------------------------------------------------
  • INT WINAPI _tWinMain( HINSTANCE /*hInst*/, HINSTANCE, LPTSTR, INT )
  • {
  • // Register the window class
  • WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
  • GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
  • TEXT("D3D Tutorial"), NULL };
  • RegisterClassEx( &wc );
  • // Create the application's window
  • HWND hWnd = CreateWindow( TEXT("D3D Tutorial"), TEXT("Essai"),
  • WS_OVERLAPPEDWINDOW, 0, 0, 1024, 768,
  • GetDesktopWindow(), NULL, wc.hInstance, NULL );
  • // Initialize Direct3D
  • if( SUCCEEDED( InitD3D( hWnd ) ) )
  • {
  • // Show the window
  • ShowWindow( hWnd, SW_SHOWDEFAULT );
  • UpdateWindow( hWnd );
  • // Enter the message loop
  • MSG msg;
  • while( GetMessage( &msg, NULL, 0, 0 ) )
  • {
  • TranslateMessage( &msg );
  • DispatchMessage( &msg );
  • }
  • }
  • // Clean up everything and exit the app
  • Cleanup();
  • UnregisterClass( TEXT("D3D Tutorial"), wc.hInstance );
  • return 0;
  • }
/*** Lightness1024! ProgrammatO 01/02/2001 17:38:31 ***
 *** Base de programme Directx8 plein ecran         ***/

#include <d3d8.h>
#include <D3dx8core.h>


#ifdef UNICODE
#define _tWinMain wWinMain
#else
#define _tWinMain WinMain
#endif

// Variables globales:
LPDIRECT3D8             g_pD3D       = NULL; // pour faire l'objet d3d8
LPDIRECT3DDEVICE8       g_pd3dDevice = NULL; // le materiel de rendu
LPDIRECT3DVERTEXBUFFER8 g_pVB        = NULL; // la zone des vertices (non utilisé encore)


// Initialisation de Direct3D
HRESULT InitD3D( HWND hWnd )
{
    // Create the D3D object, which is needed to create the D3DDevice.
    if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    // Get the current desktop display mode
    D3DDISPLAYMODE d3ddm;

	d3ddm.Width = 1024;
	d3ddm.Height = 768;
	d3ddm.Format = D3DFMT_R5G6B5;
	d3ddm.RefreshRate = 0;
	
	// Au cas où on veut détecter les paramètres courants:
	/*if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
		return E_FAIL;*/


    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );

    d3dpp.Windowed = FALSE;
	d3dpp.BackBufferWidth = 1024;
	d3dpp.BackBufferHeight = 768;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = d3ddm.Format;
	d3dpp.hDeviceWindow = hWnd;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	d3dpp.BackBufferCount = 1;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.EnableAutoDepthStencil = FALSE;
	//d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	// software : D3DDEVTYPE_REF
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pd3dDevice ) ) )
    {
        return E_FAIL;
    }

    // c bon
	// le debut de l'initialisation du vertex buffer
	//if (FAILED (g_pd3dDevice->CreateVertexBuffer (3, 

    return S_OK;
}


// Nettoie tout le bordel
VOID Cleanup()
{
    if( g_pd3dDevice != NULL) 
        g_pd3dDevice->Release();

    if( g_pD3D != NULL)
        g_pD3D->Release();
}



// Calcul du rendu
VOID Render()
{
    if( NULL == g_pd3dDevice )
        return;
	LPD3DXFONT pD3DXFont;
	LOGFONT lf;
	ZeroMemory (&lf, sizeof(LOGFONT));
	lf.lfHeight = 200;
	lf.lfWeight = 45;
	
	if (FAILED (D3DXCreateFontIndirect(g_pd3dDevice, &lf, &pD3DXFont)))
		return;
	
	RECT rct;
	rct.left = 0;
	rct.top = 0;
	rct.bottom = 768;
	rct.right = 1024;

    // Clear the backbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(128,128,128), 1.0f, 0 );
    
    // Begin the scene
	g_pd3dDevice->BeginScene();
    
    // Trucs a tracer:
	pD3DXFont->DrawText (TEXT("hello world"), -1, &rct, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(255, 255, 255));
    
    // End the scene
    g_pd3dDevice->EndScene();
    
    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}




//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_DESTROY:
            PostQuitMessage( 0 );
            return 0;

        case WM_PAINT:
            Render();
            ValidateRect( hWnd, NULL );
            return 0;
    }

    return DefWindowProc( hWnd, msg, wParam, lParam );
}




//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------

INT WINAPI _tWinMain( HINSTANCE /*hInst*/, HINSTANCE, LPTSTR, INT )
{
    // Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      TEXT("D3D Tutorial"), NULL };
    RegisterClassEx( &wc );

    // Create the application's window
    HWND hWnd = CreateWindow( TEXT("D3D Tutorial"), TEXT("Essai"),
                              WS_OVERLAPPEDWINDOW, 0, 0, 1024, 768,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );


    // Initialize Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    { 
        // Show the window
        ShowWindow( hWnd, SW_SHOWDEFAULT );
        UpdateWindow( hWnd );
		
        // Enter the message loop
        MSG msg; 
        while( GetMessage( &msg, NULL, 0, 0 ) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
    }

    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( TEXT("D3D Tutorial"), wc.hInstance );
    return 0;
}

 

 Conclusion

langage C++
le projet pour MS VC++ 6.0 est dans le ZIP (workspace) avec executable compilé en Release pour Win32.
le script de compilation est inscrit dans le log (.plg)

pour infos: lightness1024@aol.com

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip CLASSE TEMPLATE TABLEAUX SÉCURISÉS À ALLOCATIONS AUTOMATIQUE...
Source avec Zip CRYPTAGE DE TEXTE
Source avec Zip CHANGEMENT BASE 10 -&GT; 2
Source avec une capture SPRITES PALETISÉS EN 2D QUI SE DÉPLACENT

 Sources de la même categorie

Source avec Zip Source avec une capture MP3 DX9 JOUER par f_l_a_s_h_b_a_c_k
Source avec Zip Source avec une capture EQUINOX VISUAL SON METER par f_l_a_s_h_b_a_c_k
Source avec Zip Source avec une capture FLEUR EN DELIRE! par f_l_a_s_h_b_a_c_k
Source avec Zip Source avec une capture DIREXCT X 9 D3D par f_l_a_s_h_b_a_c_k
Source avec Zip BLOP DIRECT X par f_l_a_s_h_b_a_c_k

Commentaires et avis

Commentaire de FrancoisB le 14/04/2002 13:12:43

Malheureusement comme moi lorsque tu swap de tache et tu reviens l'ecran est blanc...

Commentaire de Lightness1024! le 26/05/2002 12:43:25

c'est normal si je en refait pas de rendu.
si tu veu voir un code d'un programme en DirectX8 qui n'a pas ce problème télécharge les sources de l'alpha13 sur ce site: www.serhum.fr.st

Commentaire de YodaKyce le 02/03/2003 16:30:52

Bravo et merci pour ce code,
Enfin un exemple concret pour afficher du texte avec DX8...
Merci bcp :)

Commentaire de Lightness1024! le 02/03/2003 21:47:43

de rien !  :)
si je distribue ces sources c'est bien pour aider les gens.
pour DirectX 9 c'est exactement la meme methode.
je conseille de télécharger la SDK pour voir en détail les arguments de chaque fonctions de DirectX c'est tres pratique.

@#

Commentaire de darktoto le 08/06/2005 20:07:02

Merci, cette source va me servir de base pour essayer directx 9. Je regrette tout de même que DirectDraw soit à présent Deprecated, c'était vraiment beaucoup plus simple pour la 2d.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,404 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales