• <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 © 美洲豹

            久久精品中文字幕无码绿巨人| 久久se精品一区精品二区| 久久久久久亚洲精品无码| 成人国内精品久久久久影院VR| 99久久精品免费国产大片| 国产综合成人久久大片91| 亚洲欧美日韩精品久久亚洲区 | 色综合久久综精品| 欧美成a人片免费看久久| 国内精品久久久久影院薰衣草 | 久久精品男人影院| 久久国产亚洲精品| 久久99精品国产麻豆宅宅| 日日狠狠久久偷偷色综合96蜜桃 | 一本色道久久综合狠狠躁篇| 欧美精品国产综合久久| 91久久婷婷国产综合精品青草| 久久久久综合国产欧美一区二区| 亚洲AV无码久久寂寞少妇| 午夜精品久久久久久久无码| 亚洲天堂久久精品| 久久av无码专区亚洲av桃花岛| 亚洲精品无码久久久久AV麻豆| 国产精品99久久精品| 无码精品久久久久久人妻中字| 欧美精品丝袜久久久中文字幕| 国产精品一久久香蕉产线看 | 99久久精品免费看国产免费| 久久久亚洲欧洲日产国码二区| 一本大道久久东京热无码AV| AA级片免费看视频久久| 精品久久久久久久久中文字幕| 伊人久久精品无码二区麻豆| 四虎国产精品成人免费久久| 久久激情亚洲精品无码?V| 久久综合九色综合久99| 精品久久久久久综合日本| 国产精品久久久久久久久鸭| 九九久久99综合一区二区| 韩国三级大全久久网站| 久久久久久免费一区二区三区|