• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 505  文章 - 1034  trackbacks - 0
            <2007年8月>
            2930311234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678


            子曾經曰過:編程無他,唯手熟爾!

            常用鏈接

            留言簿(94)

            隨筆分類(649)

            隨筆檔案(505)

            相冊

            BCB

            Crytek

            • crymod
            • Crytek's Offical Modding Portal

            Game Industry

            OGRE

            other

            Programmers

            Qt

            WOW Stuff

            搜索

            •  

            積分與排名

            • 積分 - 911304
            • 排名 - 14

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            想把游戲里的倒計時用LCD效果的數字時鐘來顯示,不想用美術的圖片,只用代碼來寫,呵呵。

            《windows程序設計》上的例子的改進版:

            GDI畫的




            #define ID_TIMER    1

            #define MAX_LOADSTRING 100

            // 全局變量:
            HINSTANCE hInst;                                // 當前實例
            TCHAR szTitle[MAX_LOADSTRING];                    // 標題欄文本
            TCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口類名

            // 此代碼模塊中包含的函數的前向聲明:
            ATOM                MyRegisterClass(HINSTANCE hInstance);
            BOOL                InitInstance(HINSTANCE, 
            int);
            LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
            INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

            int APIENTRY _tWinMain(HINSTANCE hInstance,
                                 HINSTANCE hPrevInstance,
                                 LPTSTR    lpCmdLine,
                                 
            int       nCmdShow)
            {
                UNREFERENCED_PARAMETER(hPrevInstance);
                UNREFERENCED_PARAMETER(lpCmdLine);

                 
            // TODO: 在此放置代碼。
                MSG msg;
                HACCEL hAccelTable;

                
            // 初始化全局字符串
                LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
                LoadString(hInstance, IDC_PRACTISE_2005, szWindowClass, MAX_LOADSTRING);
                MyRegisterClass(hInstance);

                
            // 執行應用程序初始化:
                if (!InitInstance (hInstance, nCmdShow))
                {
                    
            return FALSE;
                }

                hAccelTable 
            = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PRACTISE_2005));

                
            // 主消息循環:
                while (GetMessage(&msg, NULL, 00))
                {
                    
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                    {
                        TranslateMessage(
            &msg);
                        DispatchMessage(
            &msg);
                    }
                }

                
            return (int) msg.wParam;
            }



            //
            //  函數: MyRegisterClass()
            //
            //  目的: 注冊窗口類。
            //
            //  注釋:
            //
            //    僅當希望
            //    此代碼與添加到 Windows 95 中的“RegisterClassEx”
            //    函數之前的 Win32 系統兼容時,才需要此函數及其用法。調用此函數十分重要,
            //    這樣應用程序就可以獲得關聯的
            //    “格式正確的”小圖標。
            //
            ATOM MyRegisterClass(HINSTANCE hInstance)
            {
                WNDCLASSEX wcex;

                wcex.cbSize 
            = sizeof(WNDCLASSEX);

                wcex.style            
            = CS_HREDRAW | CS_VREDRAW;
                wcex.lpfnWndProc    
            = WndProc;
                wcex.cbClsExtra        
            = 0;
                wcex.cbWndExtra        
            = 0;
                wcex.hInstance        
            = hInstance;
                wcex.hIcon            
            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PRACTISE_2005));
                wcex.hCursor        
            = LoadCursor(NULL, IDC_ARROW);
                wcex.hbrBackground    
            = (HBRUSH)(COLOR_WINDOW+1);
                wcex.lpszMenuName    
            = MAKEINTRESOURCE(IDC_PRACTISE_2005);
                wcex.lpszClassName    
            = szWindowClass;
                wcex.hIconSm        
            = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

                
            return RegisterClassEx(&wcex);
            }

            //
            //   函數: InitInstance(HINSTANCE, int)
            //
            //   目的: 保存實例句柄并創建主窗口
            //
            //   注釋:
            //
            //        在此函數中,我們在全局變量中保存實例句柄并
            //        創建和顯示主程序窗口。
            //
            BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
            {
               HWND hWnd;

               hInst 
            = hInstance; // 將實例句柄存儲在全局變量中

               hWnd 
            = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
                  CW_USEDEFAULT, 
            0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

               
            if (!hWnd)
               {
                  
            return FALSE;
               }

               ShowWindow(hWnd, nCmdShow);
               UpdateWindow(hWnd);

               
            return TRUE;
            }

            void DisplayDigit (HDC hdc, int iNumber)
            {
                
            static BOOL  fSevenSegment [10][7= {
                    
            11,     1,     0,     1,     1,     1,             // 0
                    00,     1,     0,     0,     1,     0,             // 1
                    10,     1,     1,     1,     0,     1,             // 2
                    10,     1,     1,     0,     1,     1,             // 3
                    01,     1,     1,     0,     1,     0,             // 4
                    11,     0,     1,     0,     1,     1,             // 5
                    11,     0,     1,     1,     1,     1,             // 6
                    10,     1,     0,     0,     1,     0,             // 7
                    11,     1,     1,     1,     1,     1,             // 8
                    11,     1,     1,     0,     1,     1 } ;        // 9

                
            static POINT ptSegment [7][6= {
                    
            7,  6,  11,    2,  31,  235,  6,  31101110,
                    
            6,  7,  101110316,   352,  312,  11,
                    
            367,  4011403136,  3532313211,
                    
            7 , 361132313235,  3631401140,
                    
            6 , 37104110616,   652,  612,  41,
                    
            36374041406136,  6532613241,
                    
            7 , 661162316235,  6631701170 } ;

                
            int        iSeg ;
                
            for (iSeg = 0 ; iSeg < 7 ; iSeg++)
                {
                    
            if (fSevenSegment [iNumber][iSeg])
                    {
                        Polygon (hdc, ptSegment [iSeg], 
            6) ;
                    }
                }
            }

            void DisplayTwoDigits (HDC hdc, int iNumber, BOOL fSuppress)
            {
                
            if (!fSuppress || (iNumber / 10 != 0))
                    DisplayDigit (hdc, iNumber 
            / 10) ;
                OffsetWindowOrgEx (hdc, 
            -420, NULL) ;
                DisplayDigit (hdc, iNumber 
            % 10) ;
                OffsetWindowOrgEx (hdc, 
            -420, NULL) ;
            }

            void DisplayColon (HDC hdc)
            {
                POINT ptColon [
            2][4= {    2,    21,    6,    17,    10,    21,    6,    25,
                    
            2,    51,    6,    47,    10,    51,    6,     55 } ;

                Polygon (hdc, ptColon [
            0], 4) ;
                Polygon (hdc, ptColon [
            1], 4) ;

                OffsetWindowOrgEx (hdc, 
            -120, NULL) ;
            }

            void DisplayBlank(HDC hdc)
            {
                OffsetWindowOrgEx (hdc, 
            -120, NULL) ;
            }

            void DisplayTime (HDC hdc, BOOL f24Hour, BOOL fSuppress)
            {
                SYSTEMTIME st ;
                GetLocalTime (
            &st) ;
                
            if (f24Hour)
                    DisplayTwoDigits (hdc, st.wHour, fSuppress) ;
                
            else
                    DisplayTwoDigits (hdc, (st.wHour 
            %= 12? st.wHour : 12, fSuppress) ;
                
            if (st.wSecond % 2 == 0)
                {
                    DisplayColon (hdc) ;
                }
                
            else
                {
                    DisplayBlank(hdc);
                }
                DisplayTwoDigits (hdc, st.wMinute, FALSE) ;
                
            if (st.wSecond % 2 != 0)
                {
                    DisplayColon (hdc) ;
                }
                
            else
                {
                    DisplayBlank(hdc);
                }
                DisplayTwoDigits (hdc, st.wSecond, FALSE) ;
            }


            //
            //  函數: WndProc(HWND, UINT, WPARAM, LPARAM)
            //
            //  目的: 處理主窗口的消息。
            //
            //  WM_COMMAND    - 處理應用程序菜單
            //  WM_PAINT    - 繪制主窗口
            //  WM_DESTROY    - 發送退出消息并返回
            //
            //
            LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
            {
                
            int wmId, wmEvent;
                PAINTSTRUCT ps;
                HDC hdc;

                
            static BOOL           f24Hour, fSuppress ;
                
            static HBRUSH         hBrushRed ;
                
            static int                cxClient, cyClient ;
                TCHAR                    szBuffer [
            2] ;


                
            switch (message)
                {
                
            case WM_COMMAND:
                    wmId    
            = LOWORD(wParam);
                    wmEvent 
            = HIWORD(wParam);
                    
            // 分析菜單選擇:
                    switch (wmId)
                    {
                    
            case IDM_ABOUT:
                        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                        
            break;
                    
            case IDM_EXIT:
                        DestroyWindow(hWnd);
                        
            break;
                    
            default:
                        
            return DefWindowProc(hWnd, message, wParam, lParam);
                    }
                    
            break;
                
            case     WM_CREATE:
                    hBrushRed 
            = CreateSolidBrush (RGB (25500)) ;
                    SetTimer (hWnd, ID_TIMER, 
            1000, NULL) ;// fall through

                
            case     WM_SETTINGCHANGE:
                    GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME, szBuffer, 
            2) ;
                    f24Hour 
            = (szBuffer[0== '1') ;

                    GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITLZERO, szBuffer, 
            2) ;
                    fSuppress 
            = (szBuffer[0== '0') ;

                    InvalidateRect (hWnd, NULL, TRUE) ;
                    
            return 0 ;

                
            case     WM_SIZE:
                    cxClient 
            = LOWORD (lParam) ;
                    cyClient 
            = HIWORD (lParam) ;
                    
            return 0 ;

                
            case     WM_TIMER:
                    InvalidateRect (hWnd, NULL, TRUE) ;
                    
            return 0 ;
                
            case WM_PAINT:
                    hdc 
            = BeginPaint(hWnd, &ps);

                    
            // TODO: 在此添加任意繪圖代碼
                    SetMapMode (hdc, MM_ISOTROPIC) ;
                    SetWindowExtEx (hdc, 
            27672, NULL) ;
                    SetViewportExtEx (hdc, cxClient, cyClient, NULL) ;

                    SetWindowOrgEx (hdc, 
            13836, NULL) ;
                    SetViewportOrgEx (hdc, cxClient 
            / 2, cyClient / 2, NULL) ;
                    SelectObject (hdc, GetStockObject (NULL_PEN)) ;
                    SelectObject (hdc, hBrushRed) ;
                    DisplayTime (hdc, f24Hour, fSuppress) ;

                    EndPaint(hWnd, 
            &ps);
                    
            break;
                
            case WM_DESTROY:
                    KillTimer (hWnd, ID_TIMER) ;
                    DeleteObject (hBrushRed) ;
                    PostQuitMessage(
            0);
                    
            break;
                
            default:
                    
            return DefWindowProc(hWnd, message, wParam, lParam);
                }
                
            return 0;
            }

            // “關于”框的消息處理程序。
            INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
            {
                UNREFERENCED_PARAMETER(lParam);
                
            switch (message)
                {
                
            case WM_INITDIALOG:
                    
            return (INT_PTR)TRUE;

                
            case WM_COMMAND:
                    
            if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
                    {
                        EndDialog(hDlg, LOWORD(wParam));
                        
            return (INT_PTR)TRUE;
                    }
                    
            break;
                }
                
            return (INT_PTR)FALSE;
            }

            用DX來畫:

            沒寫完,部分代碼,只畫了一個segment.發現用這種方法挺麻煩的。實現起來有點難度。做游戲也好長時間了,還真沒搞過這么底層的東東。把引擎掛在嘴邊上,不如好好寫寫這種小玩意兒。呵呵,估計跟我一樣的人不少啊,都是用引擎的層層封裝的API。





            #include <d3d9.h>
            #pragma warning( disable : 
            4996 ) // disable deprecated warning 
            #include <strsafe.h>
            #pragma warning( 
            default : 4996 ) 

            //-----------------------------------------------------------------------------
            // Global variables
            //-----------------------------------------------------------------------------
            LPDIRECT3D9             g_pD3D       = NULL; // Used to create the D3DDevice
            LPDIRECT3DDEVICE9       g_pd3dDevice = NULL; // Our rendering device
            LPDIRECT3DVERTEXBUFFER9 g_pVB        = NULL; // Buffer to hold vertices 頂點Buffer

            // A structure for our custom vertex type 自定義頂點類型
            struct CUSTOMVERTEX
            {
                FLOAT x, y, z, rhw; 
            // The transformed position for the vertex
                DWORD color;        // The vertex color
            };

            // Our custom FVF, which describes our custom vertex structure
            // 【2008-03-08】D3DFVF_XYZRHW 是描述經過坐標變換的頂點坐標,就是轉換為屏幕坐標了
            #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

            //-----------------------------------------------------------------------------
            // Name: InitD3D()
            // Desc: Initializes Direct3D
            //-----------------------------------------------------------------------------
            HRESULT InitD3D( HWND hWnd )
            {
                
            // Create the D3D object.
                if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
                    
            return E_FAIL;

                
            // Set up the structure used to create the D3DDevice
                D3DPRESENT_PARAMETERS d3dpp;
                ZeroMemory( 
            &d3dpp, sizeof(d3dpp) );
                d3dpp.Windowed 
            = TRUE;
                d3dpp.SwapEffect 
            = D3DSWAPEFFECT_DISCARD;
                d3dpp.BackBufferFormat 
            = D3DFMT_UNKNOWN;

                
            // Create the D3DDevice
                if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                    
            &d3dpp, &g_pd3dDevice ) ) )
                {
                    
            return E_FAIL;
                }

                
            // Device state would normally be set here

                
            return S_OK;
            }

            //-----------------------------------------------------------------------------
            // Name: InitVB()
            // Desc: Creates a vertex buffer and fills it with our vertices. The vertex
            //       buffer is basically just a chuck of memory that holds vertices. After
            //       creating it, we must Lock()/Unlock() it to fill it. For indices, D3D
            //       also uses index buffers. The special thing about vertex and index
            //       buffers is that they can be created in device memory, allowing some
            //       cards to process them in hardware, resulting in a dramatic
            //       performance gain.
            //-----------------------------------------------------------------------------
            HRESULT InitVB()
            {
                
            // Initialize vertices for rendering triangle strips 初始化要渲染的三角形鏈的頂點
                CUSTOMVERTEX vertices[] =
                {
                    { 
            300.0f, 150.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
                    { 330.0f, 130.0f, 0.5f, 1.0f, 0xff00ff00, },
                    { 330.0f, 170.0f, 0.5f, 1.0f, 0xff00ffff, },
                    { 430.0f, 130.0f, 0.5f, 1.0f, 0xffff0000, },
                    { 430.0f, 170.0f, 0.5f, 1.0f, 0xff00ff00, },
                    { 460.0f, 150.0f, 0.5f, 1.0f, 0xff00ffff
            , },
                };

                
            // Create the vertex buffer. 創建vertex buffer
                
            // Here we are allocating enough memory
                
            // (from the default pool) to hold all our 3 custom vertices. We also
                
            // specify the FVF, so the vertex buffer knows what data it contains.
                if( FAILED( g_pd3dDevice->CreateVertexBuffer( 6*sizeof(CUSTOMVERTEX),
                    
            0, D3DFVF_CUSTOMVERTEX,
                    D3DPOOL_DEFAULT, 
            &g_pVB, NULL ) ) )
                {
                    
            return E_FAIL;
                }

                
            // Now we fill the vertex buffer. 填充vertex buffer
                
            // To do this, we need to Lock() the VB to
                
            // gain access to the vertices. This mechanism is required becuase vertex
                
            // buffers may be in device memory.
                VOID* pVertices; // 輸出參數
                if( FAILED( g_pVB->Lock( 0sizeof(vertices), (void**)&pVertices, 0 ) ) )
                    
            return E_FAIL;
                memcpy( pVertices, vertices, 
            sizeof(vertices) );
                g_pVB
            ->Unlock();

                
            return S_OK;
            }

            //-----------------------------------------------------------------------------
            // Name: Cleanup()
            // Desc: Releases all previously initialized objects
            //-----------------------------------------------------------------------------
            VOID Cleanup()
            {
                
            if( g_pVB != NULL )        
                    g_pVB
            ->Release();

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

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

            //-----------------------------------------------------------------------------
            // Name: Render()
            // Desc: Draws the scene
            //-----------------------------------------------------------------------------
            VOID Render()
            {
                
            // Clear the backbuffer to a blue color
                g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f0 );

                
            // Begin the scene
                if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
                {
                    
            // Draw the triangles in the vertex buffer. 畫vertex buffer中的三角形
                    
            // This is broken into a few steps. 

                    
            // We are passing the vertices down a "stream", so first we need
                    
            // to specify the source of that stream, which is our vertex buffer. 
                    
            // 我們正傳遞頂點到一個“流”里,這個流的源頭是vertex buffer
                    g_pd3dDevice->SetStreamSource( 0, g_pVB, 0sizeof(CUSTOMVERTEX) );

                    
            // Then we need to let D3D know what vertex shader to use.
                    
            // 讓D3D知道我們用什么vertex shader
                    
            // Full, custom vertex shaders are an advanced topic,
                    
            // but in most cases the vertex shader is just the FVF,
                    
            // so that D3D knows what type of vertices we are dealing with. 
                    g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

                    
            // Finally, we call DrawPrimitive() which does the actual rendering
                    
            // of our geometry.
                    
            // 注意:用三角形鏈 triangle strips
                    g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP04 );

                    
            // 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:
                    Cleanup();
                    PostQuitMessage( 
            0 );
                    
            return 0;
                }

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

            //-----------------------------------------------------------------------------
            // Name: WinMain()
            // Desc: The application's entry point
            //-----------------------------------------------------------------------------
            INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
            {
                
            // Register the window class
                WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L0L,
                    GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                    
            "D3D Tutorial", NULL };
                RegisterClassEx( 
            &wc );

                
            // Create the application's window
                HWND hWnd = CreateWindow( "D3D Tutorial""D3D Tutorial 02: Vertices",
                    WS_OVERLAPPEDWINDOW, 
            100100700300,
                    NULL, NULL, wc.hInstance, NULL );

                
            // Initialize Direct3D
                if( SUCCEEDED( InitD3D( hWnd ) ) )
                {
                    
            // Create the vertex buffer
                    if( SUCCEEDED( InitVB() ) )
                    {
                        
            // Show the window
                        ShowWindow( hWnd, SW_SHOWDEFAULT );
                        UpdateWindow( hWnd );

                        
            // Enter the message loop
                        MSG msg;
                        ZeroMemory( 
            &msg, sizeof(msg) );
                        
            while( msg.message!=WM_QUIT )
                        {
                            
            if( PeekMessage( &msg, NULL, 0U0U, PM_REMOVE ) )
                            {
                                TranslateMessage( 
            &msg );
                                DispatchMessage( 
            &msg );
                            }
                            
            else
                                Render();
                        }
                    }
                }
                UnregisterClass( 
            "D3D Tutorial", wc.hInstance );
                
            return 0;
            }







            posted on 2008-02-28 23:50 七星重劍 閱讀(1387) 評論(1)  編輯 收藏 引用 所屬分類: Game GraphicsIDE -- visual c++

            FeedBack:
            # re: 數字時鐘DigitalClock嘗試 2008-02-29 10:14 大膽地
            8cuo  回復  更多評論
              
            久久天天婷婷五月俺也去| 国产精品99久久精品爆乳| 久久久久黑人强伦姧人妻| 青青草原综合久久| 狠狠色婷婷综合天天久久丁香 | 久久无码高潮喷水| 久久强奷乱码老熟女网站| 思思久久精品在热线热| 亚洲人成网亚洲欧洲无码久久| 久久精品国产亚洲av麻豆蜜芽 | 亚洲七七久久精品中文国产 | 亚洲精品国产综合久久一线| 日本加勒比久久精品| 久久久久青草线蕉综合超碰| 久久人做人爽一区二区三区 | 久久婷婷五月综合色高清| 国产精品福利一区二区久久| 久久久91精品国产一区二区三区| 国产精品热久久无码av| 伊人久久大香线蕉综合5g| 无码人妻精品一区二区三区久久 | 情人伊人久久综合亚洲| 久久精品国产99国产精品| 久久久久久久久66精品片| 久久久久久久久无码精品亚洲日韩| 久久精品一区二区| 亚洲国产高清精品线久久 | 亚洲中文字幕无码久久综合网 | 精品综合久久久久久88小说| 思思久久99热只有频精品66| 久久久精品免费国产四虎| 久久久久久久免费视频| 国产成人香蕉久久久久| 亚洲国产精品无码久久SM| 久久国产香蕉视频| 高清免费久久午夜精品| 性做久久久久久久久| 麻豆精品久久精品色综合| 久久亚洲精精品中文字幕| 少妇久久久久久被弄到高潮| 久久久综合九色合综国产|