bool modelLoader( const std::string & fileName, ModelLoaderCallBack * callBack ) { if (0 == callBack) { return false; } if (fileName.empty()) { callBack->error("fileName is null"); return false; } { std::ifstream ifs(fileName); if (false==ifs.is_open() ) { callBack->error(fileName + " can not be opened "); return false; } } /************************************/ return Import3DFromFile(fileName,callBack); /************************************/ return false; }
int init() { if (!Import3DFromFile(modelname)) return(0); LoadGLTextures(scene); glGetUniformBlockIndex = (PFNGLGETUNIFORMBLOCKINDEXPROC) glutGetProcAddress("glGetUniformBlockIndex"); glUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC) glutGetProcAddress("glUniformBlockBinding"); glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) glutGetProcAddress("glGenVertexArrays"); glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)glutGetProcAddress("glBindVertexArray"); glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) glutGetProcAddress("glBindBufferRange"); glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC) glutGetProcAddress("glDeleteVertexArrays"); program = setupShaders(); genVAOsAndUniformBuffer(scene); glEnable(GL_DEPTH_TEST); glClearColor(1.0f, 1.0f, 1.0f, 0.0f); // // Uniform Block // glGenBuffers(1,&matricesUniBuffer); glBindBuffer(GL_UNIFORM_BUFFER, matricesUniBuffer); glBufferData(GL_UNIFORM_BUFFER, MatricesUniBufferSize,NULL,GL_DYNAMIC_DRAW); glBindBufferRange(GL_UNIFORM_BUFFER, matricesUniLoc, matricesUniBuffer, 0, MatricesUniBufferSize); //setUniforms(); glBindBuffer(GL_UNIFORM_BUFFER,0); glEnable(GL_MULTISAMPLE); return true; }
int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nShowCmd ) // Window Show State { MSG msg; // Windows Message Structure BOOL done=FALSE; // Bool Variable To Exit Loop createAILogger(); logInfo("App fired!"); // load scene if (!Import3DFromFile(basepath+modelname)) return 0; logInfo("=============== Post Import ===================="); // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL, "Would You Like To Run In Fullscreen Mode?", "Start Fullscreen?", MB_YESNO|MB_ICONEXCLAMATION)==IDNO) { fullscreen=FALSE; // Windowed Mode } // Create Our OpenGL Window (also calls GLinit und LoadGLTextures) if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { return 0; } while(!done) // Game Loop { if (PeekMessage(&msg, NULL, 0,0, PM_REMOVE)) // Is There A Message Waiting { if (msg.message==WM_QUIT) // Have we received A Quit Message? { done=TRUE; // If So done=TRUE } else { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else { // Draw The Scene. Watch For ESC Key And Quit Messaged From DrawGLScene() if (active) { if (keys[VK_ESCAPE]) // Was ESC pressed? { done=TRUE; // ESC signalled A quit } else { DrawGLScene(); // Draw The Scene SwapBuffers(hDC); // Swap Buffers (Double Buffering) } } if (keys[VK_F1]) // Is F1 Being Pressed? { keys[VK_F1]=FALSE; // If so make Key FALSE KillGLWindow(); // Kill Our Current Window fullscreen=!fullscreen; // Toggle Fullscreen //recreate Our OpenGL Window if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { return 0; // Quit if Window Was Not Created } } } } // *** cleanup *** // clear map textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) // clear texture ids if (textureIds) { delete[] textureIds; textureIds = NULL; } // *** cleanup end *** // Shutdown destroyAILogger(); KillGLWindow(); return (msg.wParam); // Exit The Program }
int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nShowCmd ) // Window Show State { MSG msg; BOOL done=FALSE; createAILogger(); logInfo("App fired!"); // Check the command line for an override file path. int argc; LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argv != NULL && argc > 1) { std::wstring modelpathW(argv[1]); modelpath = std::string(modelpathW.begin(), modelpathW.end()); } if (!Import3DFromFile(modelpath)) return 0; logInfo("=============== Post Import ===================="); if (MessageBox(NULL, "Would You Like To Run In Fullscreen Mode?", "Start Fullscreen?", MB_YESNO|MB_ICONEXCLAMATION)==IDNO) { fullscreen=FALSE; } if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { return 0; } while(!done) // Game Loop { if (PeekMessage(&msg, NULL, 0,0, PM_REMOVE)) { if (msg.message==WM_QUIT) { done=TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { // Draw The Scene. Watch For ESC Key And Quit Messaged From DrawGLScene() if (active) { if (keys[VK_ESCAPE]) { done=TRUE; } else { DrawGLScene(); SwapBuffers(hDC); } } if (keys[VK_F1]) { keys[VK_F1]=FALSE; KillGLWindow(); fullscreen=!fullscreen; if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { return 0; } } } } // *** cleanup *** textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) if (textureIds) { delete[] textureIds; textureIds = NULL; } // *** cleanup end *** destroyAILogger(); KillGLWindow(); return (msg.wParam); }
int main(int argc, char *argv[]) { OSMesaContext ctx; void *buffer; if (argc < 3) { fprintf(stderr, "Usage:\n"); fprintf(stderr, " render modelname pngname [width height] [camx camy camz] [centerx centerz centerz] [upx upy upz] [fovy]\n"); fprintf(stderr, "Default: width=%d height=%d cam=[%0.4f %0.4f %0.4f] center=[%0.4f %0.4f %0.4f] up=[%0.4f %0.4f %0.4f] fovy=%0.4f\n", Width, Height, camx, camy, camz, centerx, centery, centerz, upx, upy, upz, fovy); return 0; } modelname = argv[1]; pngname = argv[2]; if (argc >= 5) { Width = atoi(argv[3]); Height = atoi(argv[4]); } if (argc >= 8) { camx = atoi(argv[5]); camy = atoi(argv[6]); camz = atoi(argv[7]); } if (argc >= 11) { centerx = atoi(argv[8]); centery = atoi(argv[9]); centerz = atoi(argv[10]); } if (argc >= 14) { upx = atoi(argv[11]); upy = atoi(argv[12]); upz = atoi(argv[13]); } if (argc >= 15) { fovy = atoi(argv[14]); } if (!Import3DFromFile(modelname)) { fprintf(stderr, "model cannot be loaded!\n"); return 0; } /* Create an RGBA-mode context */ #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 /* specify Z, stencil, accum sizes */ ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL ); #else ctx = OSMesaCreateContext( OSMESA_RGBA, NULL ); #endif if (!ctx) { printf("OSMesaCreateContext failed!\n"); return 0; } /* Allocate the image buffer */ buffer = malloc( Width * Height * 4 * sizeof(GLubyte) ); if (!buffer) { printf("Alloc image buffer failed!\n"); return 0; } /* Bind the buffer to the context and make it current */ if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) { printf("OSMesaMakeCurrent failed!\n"); return 0; } { int z, s, a; glGetIntegerv(GL_DEPTH_BITS, &z); glGetIntegerv(GL_STENCIL_BITS, &s); glGetIntegerv(GL_ACCUM_RED_BITS, &a); printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a); } InitGL(Width, Height); render_image(); if (pngname != NULL) { png::image< png::rgba_pixel > image(Width, Height); GLubyte * p_buffer = (GLubyte*)buffer; for (png::uint_32 y = 0; y < Height; ++y) { for (png::uint_32 x = 0; x < Width; ++x) { png::uint_32 r, g, b, a; r = *(p_buffer++); g = *(p_buffer++); b = *(p_buffer++); a = *(p_buffer++); image[Height-1-y][x] = png::rgba_pixel(r, g, b, a); } } image.write(pngname); } else { printf("Specify a filename if you want to make an image file\n"); } printf("all done\n"); /* free the image buffer */ free( buffer ); // *** cleanup *** textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) textureName.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) if (textureIds) { delete[] textureIds; textureIds = NULL; } /* destroy the context */ OSMesaDestroyContext( ctx ); return 0; }