2015-12-21 3 views
1

im получить проблему с решением масштабирования gifx интеграции в простом примере приложения.Интеграция с масштабированием GFx с OpenGL

Проблема в дисплее сцене, модель, которая должна будет иметь белый цвет шоу фиолетовый, пример: problem

им обнаружить, что цветовой эффект появляется перед им начать оказывать GFX компонент, достаточно вызова FxTest :: Initialize.

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); 
    } 

 

Перенасыщение сцена:

 


    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; 
    } 

 

Пожалуйста, помогите мне понять, что не так.

P.S .: Мой английский не совершенен, исправьте, если найдете ошибки.

ответ

1

Okey, im нашел что не так - после FxTest::Initialize чайник получает текстуру от gfx, это означает, что в большом проекте нужно получить хороший момент для загрузки или включить/отключить GL_TEXTURE_2D после/до начала загрузки gfx.

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

благодарит всех.

Смежные вопросы