I'm having a problem integrating a Scaleform GFx solution into a simple application.
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; calling FxTest::Initialize is enough to cause the problem.
Code below.
GFx wrapper:
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.
glDisable(GL_TEXTURE_2D); // after initialization and all good
thanks for all.