• <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>

            Ogre App添加Console的方法

            Posted on 2008-08-18 09:28 美洲豹 閱讀(352) 評論(0)  編輯 收藏 引用
            以前一直想添加一個Console用于調試,后來在OgreWiki的HOWTO中查到了一個,其中推薦的方法如下:
            Console.h如下:
            #include <stdio.h>
            #include <fcntl.h>
            #include <io.h>
            #include <iostream>
            #include <string>

            extern void showWin32Console();

            void showWin32Console()
            {
                static const WORD MAX_CONSOLE_LINES = 500;
                int hConHandle;
                long lStdHandle;
                CONSOLE_SCREEN_BUFFER_INFO coninfo;
                FILE *fp;
                // allocate a console for this app
                AllocConsole();
                // set the screen buffer to be big enough to let us scroll text
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
                coninfo.dwSize.Y = MAX_CONSOLE_LINES;
                SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),
                    coninfo.dwSize);
                // redirect unbuffered STDOUT to the console
                lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
                hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
                fp = _fdopen( hConHandle, "w" );
                *stdout = *fp;
                setvbuf( stdout, NULL, _IONBF, 0 );
                // redirect unbuffered STDIN to the console
                lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
                hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
                fp = _fdopen( hConHandle, "r" );
                *stdin = *fp;
                setvbuf( stdin, NULL, _IONBF, 0 );
                // redirect unbuffered STDERR to the console
                lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
                hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
                fp = _fdopen( hConHandle, "w" );
                *stderr = *fp;
                setvbuf( stderr, NULL, _IONBF, 0 );
                // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
                // point to console as well
                std::ios::sync_with_stdio();
            }

            而后,在main.cpp中如下使用即可:
            /*
            -----------------------------------------------------------------------------
            Filename:    OgreAnimationTest.cpp
            -----------------------------------------------------------------------------

            This source file is generated by the Ogre AppWizard.

            Check out: http://conglomerate.berlios.de/wiki/doku.php?id=ogrewizards

            Based on the Example Framework for OGRE
            (Object-oriented Graphics Rendering Engine)

            Copyright (c) 2000-2007 The OGRE Team
            For the latest info, see http://www.ogre3d.org/

            You may use this sample code for anything you like, it is not covered by the
            LGPL like the rest of the OGRE engine.
            -----------------------------------------------------------------------------
            */

            #include "OgreAnimationTest.h"

            #include "Console.h"


            #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            #define WIN32_LEAN_AND_MEAN
            #include "windows.h"
            #endif

            #ifdef __cplusplus
                extern "C" {
            #endif

            #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
                    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
            #else
                    int main(int argc, char *argv[])
            #endif
                    {
                        // Create application object
                        OgreAnimationTestApp app;

                        showWin32Console();

                        try {
                            app.go();
                        } catch( Ogre::Exception& e ) {
            #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
                            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
            #else
                            std::cerr << "An exception has occured: " <<
                                e.getFullDescription().c_str() << std::endl;
            #endif
                        }

                        FreeConsole();

                        return 0;
                    }

            #ifdef __cplusplus
                }
            #endif

            用showWin32Console()及FreeConsole()即可,在其他程序段中,所有的用printf,cout輸出的結果將重定向到這個console中,方便調試。

            posts - 15, comments - 2, trackbacks - 0, articles - 29

            Copyright © 美洲豹

            亚洲欧美日韩精品久久亚洲区 | 久久精品国产精品亚洲| 国产精品一区二区久久| 99精品久久精品一区二区| 97久久久精品综合88久久| 久久夜色tv网站| 青青青青久久精品国产h久久精品五福影院1421| 情人伊人久久综合亚洲| 色婷婷久久综合中文久久一本| 亚洲人AV永久一区二区三区久久 | 久久青青草原精品国产软件| 久久久久亚洲爆乳少妇无| 一本色道久久88综合日韩精品 | 狠狠精品久久久无码中文字幕| 久久精品天天中文字幕人妻| 久久久久久国产精品免费免费| 久久午夜福利无码1000合集| 久久亚洲中文字幕精品有坂深雪 | 久久久久国产亚洲AV麻豆| 亚洲精品无码久久久影院相关影片| 久久中文字幕一区二区| 综合网日日天干夜夜久久| 精品免费久久久久国产一区| 国产精品久久久久无码av| 久久精品国产亚洲αv忘忧草 | 久久久久亚洲av毛片大| 99国产精品久久| 久久久无码一区二区三区 | 久久99精品久久久久久| 无码精品久久久天天影视 | 国产成人99久久亚洲综合精品| 久久精品国产亚洲AV高清热| 久久人人添人人爽添人人片牛牛| 久久综合日本熟妇| 日韩亚洲国产综合久久久| 久久嫩草影院免费看夜色| 色综合久久88色综合天天 | 久久综合一区二区无码| 久久久久国产精品麻豆AR影院| 91精品国产91热久久久久福利| 国产 亚洲 欧美 另类 久久|