• <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 美洲豹 閱讀(349) 評論(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 © 美洲豹

            久久精品国产亚洲av麻豆小说| 国产午夜福利精品久久2021| 国产亚州精品女人久久久久久| 国产精品免费久久久久影院| 久久久久国产| 久久婷婷五月综合97色直播| 久久超碰97人人做人人爱| 777久久精品一区二区三区无码| 性高湖久久久久久久久| 久久久久亚洲AV成人片| 久久精品夜色噜噜亚洲A∨| 一本色道久久99一综合| 亚洲国产二区三区久久| 国产aⅴ激情无码久久| Xx性欧美肥妇精品久久久久久| 久久受www免费人成_看片中文| www.久久热| 久久精品国产亚洲AV忘忧草18| 女人香蕉久久**毛片精品| 亚洲熟妇无码另类久久久| 久久精品国产一区二区电影| 韩国三级大全久久网站| A级毛片无码久久精品免费| 久久久精品国产亚洲成人满18免费网站 | 亚洲人成网站999久久久综合 | 2019久久久高清456| www亚洲欲色成人久久精品| 无码日韩人妻精品久久蜜桃| 久久久久久久久66精品片| 成人午夜精品久久久久久久小说| 久久精品夜夜夜夜夜久久| 免费精品国产日韩热久久| 久久这里只有精品视频99| 久久国产影院| 国产999精品久久久久久| 欧美一区二区精品久久| 久久精品国产只有精品2020| 久久国产乱子精品免费女| 久久se精品一区精品二区| 亚洲国产二区三区久久| 国内精品久久久久久中文字幕|