简体   繁体   English

Scaleform GFx 与 OpenGL 集成

[英]Scaleform GFx integration with OpenGL

I'm having a problem integrating a Scaleform GFx solution into a simple application.我在将 Scaleform GFx 解决方案集成到简单应用程序中时遇到问题。

The problem is in the displayed scene a model that is supposed to be white is being displayed as violet.问题是在显示的场景中,本应为白色的模型显示为紫色。

问题

As far as I can tell that color effect appears before I start rendering the GFx component;据我所知,颜色效果出现在我开始渲染 GFx 组件之前; calling FxTest::Initialize is enough to cause the problem.调用 FxTest::Initialize 足以导致问题。

Code below.下面的代码。

GFx wrapper: GFx 包装器:



    FxTest::FxTest() {
        is_initialized_ = false;
        last_play_time_ = 0;
    }

    FxTest::~FxTest() {
        GMemory::DetectMemoryLeaks();
    }

    void FxTest::Initialize(const char* movie_file) {
        // setup logger
        loader_.SetLog(GPtr(*new GFxPlayerLog()));

        // setup file opener
        GPtr file_opener = *new GFxFileOpener;
        loader_.SetFileOpener(file_opener);

        // setup renderer
        renderer_ = *GRendererOGL::CreateRenderer();
        if(!renderer_ || !renderer_->SetDependentVideoMode()) {
            return;
        }
        render_config_ = *new GFxRenderConfig(renderer_, GFxRenderConfig::RF_EdgeAA);
        if(!render_config_) {
            return;
        }
        loader_.SetRenderConfig(render_config_);

        // setup movie
        ui_movie_def_ = *(loader_.CreateMovie(movie_file, GFxLoader::LoadKeepBindData | GFxLoader::LoadWaitFrame1));
        if(!ui_movie_def_) {
            return;
        }
        ui_movie_ = *ui_movie_def_->CreateInstance(GFxMovieDef::MemoryParams(), true);
        if(!ui_movie_) {
            return;
        }

        ui_movie_->Advance(0.0f, 0);
        ui_movie_->SetBackgroundAlpha(0.0f);
        ui_movie_->SetViewport(1024, 768, 0, 0, 1024, 768);
        ui_movie_->SetViewScaleMode(GFxMovieView::ScaleModeType::SM_NoScale);

        is_initialized_ = true;
        last_play_time_ = timeGetTime();
    }

    void FxTest::UpdateViewport(int width, int height) {
        if (!ui_movie_) {
            return;
        }
        ui_movie_->SetViewport(width, height, 0, 0, width, height);
        last_play_time_ = timeGetTime();
    }

    void FxTest::AdvanceAndDisplay() {
        if (!ui_movie_) {
            return;
        }
        BeginDisplay();

        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

        DWORD mtime = timeGetTime();
        float deltaTime = ((float)(mtime - last_play_time_)) / 1000.0f;

        ui_movie_->Advance(deltaTime, 0);
        ui_movie_->Display();

        last_play_time_ = mtime;

        EndDisplay();
    }

    void FxTest::BeginDisplay() {
        glPushAttrib(GL_ALL_ATTRIB_BITS);
    }

    void FxTest::EndDisplay() {
        glPopAttrib();
    }

    void FxTest::OnMouse(GFxEvent::EventType event_type, UInt button, SInt x, SInt y) {
        if (!ui_movie_) {
            return;
        }
        GFxMouseEvent mouse_event(event_type, 0, x, y);
        ui_movie_->HandleEvent(mouse_event);
    }


Glut scene:过剩场景:



    FxTest* g_FxTest = NULL;

    void display() {
        glMatrixMode(GL_MODELVIEW);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();

        glTranslatef(0.0, 0.0, -4.5);
        glScalef(1.0, 1.0, 1.0);

        glPushMatrix();
            glutSolidTeapot(1);
        glPopMatrix();

        if (g_FxTest->IsInitialized()) {
            g_FxTest->AdvanceAndDisplay();
        }

        glFlush();
        glutSwapBuffers();
    }

    void reshapeFunc(int x, int y) {
        if (y == 0 || x == 0) {
            return;
        }

        glMatrixMode(GL_PROJECTION);  
        glLoadIdentity();

        gluPerspective(40.0, (GLdouble)x / (GLdouble)y, 0.5, 20.0);
        glViewport(0, 0, x, y);

        if (g_FxTest->IsInitialized()) {
            g_FxTest->UpdateViewport(x, y);
        }
    }

    void idleFunc(void) {
        display();
    }

    void mouseMotion(int x, int y) {
        if (g_FxTest && g_FxTest->IsInitialized()) {
            g_FxTest->OnMouse(GFxEvent::MouseMove, 0, x, y);
        }
    }

    void mouse(int button, int button_state, int x, int y) {
        if (g_FxTest && g_FxTest->IsInitialized()) {
            if (button_state == GLUT_DOWN) {
                g_FxTest->OnMouse(GFxEvent::MouseDown, button, x, y);
            } else if (button_state == GLUT_UP) {
                g_FxTest->OnMouse(GFxEvent::MouseUp, button, x, y);
            }
        }
    }

    int main(int argc, char **argv) {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);

        glutInitWindowSize(1024, 768);
        glutCreateWindow("GFx");

        glutDisplayFunc(display);
        glutReshapeFunc(reshapeFunc);
        glutIdleFunc(idleFunc);
        glutMouseFunc(mouse);
        glutMotionFunc(mouseMotion);
        glutPassiveMotionFunc(mouseMotion);

        /*glut init*/
        glClearColor(0.5, 0.5, 0.5, 0.0);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);

        GFxSystem gfx_init;
        g_FxTest = new FxTest();
        g_FxTest->Initialize("Movie//NpcShop.swf"); // problem start here

        glutMainLoop();
        return 0;
    }


Please help me understand what I am doing wrong.请帮助我了解我做错了什么。

Okey, im found what wrong - after FxTest::Initialize teapot get texture from gfx, it means that in big project need get good moment for loading or enable / disable GL_TEXTURE_2D after / before start loading gfx.好吧,我发现了什么问题 - 在FxTest::Initialize teapot 从 gfx 获取纹理之后,这意味着在大项目中需要获得加载的好时机,或者在开始加载 gfx 之后/之前启用/禁用 GL_TEXTURE_2D。

glDisable(GL_TEXTURE_2D); // after initialization and all good

thanks for all.谢谢大家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM