0/5 (1 avis)
Vue 5 751 fois - Téléchargée 456 fois
//CODE DU SECOND REPERTOIRE //MAIN.CPP UNIQUEMENT (RESTE DANS LE ZIP) #include <windows.h> #include <commctrl.h> #include "DXUtils.h" #include "resource.h" #define SAFE_RELEASE(a) if(a){a->Release();a=NULL;} #define SAFE_RELEASE_ARRAY(a) if(a){delete [] a;a = NULL;} extern HWND g_hDlg; HWND g_hPicture1; HWND g_hPicture2; char g_FPS[6]; bool g_CallBoucle = true; SFontProperties* g_FontTab = NULL; bool Update1() { static float CurrentTime = DXUtil_Timer(TIMER_GETABSOLUTETIME); if( DXUtil_Timer(TIMER_GETABSOLUTETIME)-CurrentTime>0.015f )//64 fps ( 1/fps. calculé par 1/66 mais a cause des arrondis on a 64fps) { srand((unsigned int)timeGetTime()); //On réinitialise le hasard. //-----------Préparation des variables d'affichage------ static float Timer = 0.0f; static float dwFrames = 0.0f; CurrentTime = DXUtil_Timer(TIMER_GETABSOLUTETIME); //-----------Préparation du device pour l'affichage----- DXUtil_Timer(TIMER_START); g_MainSwapChain->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&g_Surf); g_Device->SetRenderTarget(0,g_Surf); g_Device->Clear(NULL,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); g_Device->BeginScene(); PrintText("Premiere fenetre",-1,-1,D3DCOLOR_ARGB(255,255,0,0),1); dwFrames++; PrintText(g_FPS,0,0,D3DCOLOR_ARGB(255,0,255,0),1); //FPS if( CurrentTime-Timer > 1.0f ) { sprintf(g_FPS,"%.2f",dwFrames / (CurrentTime - Timer)); dwFrames = 0; Timer = CurrentTime; } //-----------Affichage de la frame---------------------- g_Device->EndScene(); g_MainSwapChain->Present(NULL,NULL,g_hPicture1,NULL,0); } return true; } bool Update2() { static float CurrentTime = DXUtil_Timer(TIMER_GETABSOLUTETIME); if( DXUtil_Timer(TIMER_GETABSOLUTETIME)-CurrentTime>0.015f )//64 fps ( 1/fps. calculé par 1/66 mais a cause des arrondis on a 64fps) { srand((unsigned int)timeGetTime()); //On réinitialise le hasard. //-----------Préparation des variables d'affichage------ static float Timer = 0.0f; static float dwFrames = 0.0f; CurrentTime = DXUtil_Timer(TIMER_GETABSOLUTETIME); //-----------Préparation du device pour l'affichage----- DXUtil_Timer(TIMER_START); g_SecondSwapChain->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&g_Surf); g_Device->SetRenderTarget(0,g_Surf); g_Device->Clear(NULL,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); g_Device->BeginScene(); PrintText("Seconde fenetre",-1,-1,D3DCOLOR_ARGB(255,255,0,0),1); dwFrames++; PrintText(g_FPS,0,0,D3DCOLOR_ARGB(255,0,255,0),1); //FPS if( CurrentTime-Timer > 1.0f ) { sprintf(g_FPS,"%.2f",dwFrames / (CurrentTime - Timer)); dwFrames = 0; Timer = CurrentTime; } //-----------Affichage de la frame---------------------- g_Device->EndScene(); g_SecondSwapChain->Present(NULL,NULL,g_hPicture2,NULL,0); } return true; } bool CenterDlg(HWND hWnd) { RECT l_Dim; int l_ScreenWidth = GetSystemMetrics(SM_CXSCREEN); int l_ScreenHeight = GetSystemMetrics(SM_CYSCREEN); GetWindowRect(hWnd,&l_Dim); int l_AppWidth = l_Dim.right - l_Dim.left; int l_AppHeight = l_Dim.bottom - l_Dim.top; //Center the window SetWindowPos(hWnd,HWND_TOP,(l_ScreenWidth-l_AppWidth)/2, (l_ScreenHeight-l_AppHeight)/2, l_AppWidth, l_AppHeight, SWP_SHOWWINDOW); return true; } LRESULT CALLBACK DlgProc(HWND DlgProc, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: DestroyWindow(DlgProc); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_INITDIALOG: break; case WM_COMMAND: switch(HIWORD(wParam)) { case BN_CLICKED: switch(LOWORD(wParam)) { case IDCANCEL: DestroyWindow(DlgProc); break; } break; } break; default: return FALSE; } return FALSE; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG Msg; g_hDlg = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_MAINFORM), NULL, (DLGPROC) DlgProc); CenterDlg(g_hDlg); RECT rc; //GetWindowRect(g_hDlg,&rc); //les deux sont possibles GetWindowRect(GetDlgItem(g_hDlg,IDC_PICTURE2),&rc); InitDGraphics(rc.right-rc.left,rc.bottom-rc.top,32); if(g_hDlg == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } //-----Création et initialisation des polices g_FontTab = LoadFonts(g_FontTab,"FontList.wbf"); if( g_FontTab == NULL ) { MessageBox(g_hDlg,"Impossible d'initialiser les polices !","Erreur fatale !",MB_ICONHAND); return -1; } else { HFONT l_TmpFont; g_FontList = new LPD3DXFONT[g_NumbOfFonts]; for(int k=0 ; k<g_NumbOfFonts ; k++) { l_TmpFont = CreateFont( g_FontTab[k].m_Size, //taille de la police : 10, 12, 16, etc 0, 0, 0, g_FontTab[k].m_Flag, //texte gras ou non g_FontTab[k].m_Italic, //italique : true ou false g_FontTab[k].m_Underlined, //souligné : true ou false FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH, g_FontTab[k].m_Name); D3DXCreateFont( g_Device, l_TmpFont, &g_FontList[k] ); DeleteObject( l_TmpFont ); } } InitCommonControls(); ShowWindow(g_hDlg, nCmdShow); UpdateWindow(g_hDlg); g_hPicture1 = GetDlgItem(g_hDlg,IDC_PICTURE); g_hPicture2 = GetDlgItem(g_hDlg,IDC_PICTURE2); while(g_CallBoucle) { //pour les erreurs non debug if( PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE) ) { if ( !GetMessage(&Msg, NULL, 0, 0) ) g_CallBoucle=false; DispatchMessage(&Msg); } else { if( !Update1() || !Update2() ) g_CallBoucle=false; } } for(int i=0;i<g_NumbOfFonts;i++) g_FontList[i]->Release(); SAFE_RELEASE_ARRAY(g_FontList); SAFE_RELEASE_ARRAY(g_FontTab); SAFE_RELEASE(g_Surf); SAFE_RELEASE(g_MainSwapChain); SAFE_RELEASE(g_SecondSwapChain); SAFE_RELEASE(g_Device); SAFE_RELEASE(g_D3D); return Msg.wParam; }
18 août 2004 à 18:04
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.