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

            久久亚洲高清综合| 精品伊人久久大线蕉色首页| 久久不见久久见免费视频7| 亚洲精品午夜国产VA久久成人| 欧洲精品久久久av无码电影| 久久精品国产亚洲av高清漫画| 国产午夜精品理论片久久影视 | 欧美亚洲另类久久综合婷婷| 久久久国产亚洲精品| 91精品国产91久久久久福利| 国产精品激情综合久久| 中文字幕精品无码久久久久久3D日动漫 | 精品久久人人做人人爽综合| 区久久AAA片69亚洲 | 欧美日韩中文字幕久久久不卡| 亚洲色欲久久久综合网东京热| 日本久久久久久中文字幕| 久久伊人五月丁香狠狠色| 色综合久久88色综合天天 | 久久美女网站免费| 久久精品国产亚洲av麻豆蜜芽| 91精品免费久久久久久久久| 无码专区久久综合久中文字幕| 久久久久亚洲精品天堂久久久久久 | 日韩av无码久久精品免费| 久久久WWW成人免费精品| 国内精品久久人妻互换| 亚洲人AV永久一区二区三区久久| 国产精品成人精品久久久| 久久精品成人国产午夜| 日本强好片久久久久久AAA| 久久综合九色综合网站| 久久精品中文字幕有码| 国产精品99久久久久久董美香| 久久99国产精品二区不卡| 国产精品久久午夜夜伦鲁鲁| 欧美亚洲色综久久精品国产| 久久亚洲AV成人无码电影| 久久精品麻豆日日躁夜夜躁| 久久亚洲精品人成综合网| 久久精品成人国产午夜|