void PrintGLInfo() { std::string fname = GetPiUserDir() + "opengl.txt"; FILE *f = fopen(fname.c_str(), "w"); if (!f) return; std::ostringstream ss; ss << "OpenGL version " << glGetString(GL_VERSION); ss << ", running on " << glGetString(GL_VENDOR); ss << " " << glGetString(GL_RENDERER) << std::endl; ss << "Available extensions:" << std::endl; GLint numext = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &numext); if (glewIsSupported("GL_VERSION_3_0")) { for (int i = 0; i < numext; ++i) { ss << " " << glGetStringi(GL_EXTENSIONS, i) << std::endl; } } else { ss << " "; std::istringstream ext(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))); std::copy( std::istream_iterator<std::string>(ext), std::istream_iterator<std::string>(), std::ostream_iterator<std::string>(ss, "\n ")); } fprintf(f, "%s", ss.str().c_str()); fclose(f); printf("OpenGL system information saved to %s\n", fname.c_str()); }
void Pi::Init() { config.Load(GetPiUserDir() + "config.ini"); Pi::detail.planets = config.Int("DetailPlanets"); Pi::detail.cities = config.Int("DetailCities"); int width = config.Int("ScrWidth"); int height = config.Int("ScrHeight"); const SDL_VideoInfo *info = NULL; Uint32 sdlInitFlags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK; #if defined _WIN32 && defined _DEBUG sdlInitFlags |= SDL_INIT_NOPARACHUTE; #endif if (SDL_Init(sdlInitFlags) < 0) { fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError()); exit(-1); } InitJoysticks(); // no mode set, find an ok one if ((width <= 0) || (height <= 0)) { SDL_Rect **modes = SDL_ListModes(NULL, SDL_HWSURFACE | SDL_FULLSCREEN); if (modes == 0) { fprintf(stderr, "It seems no video modes are available..."); } if (modes == (SDL_Rect **)-1) { // hm. all modes available. odd. try 800x600 width = 800; height = 600; } else { width = modes[0]->w; height = modes[0]->h; } } info = SDL_GetVideoInfo(); printf("SDL_GetVideoInfo says %d bpp\n", info->vfmt->BitsPerPixel); switch (info->vfmt->BitsPerPixel) { case 16: SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); break; case 24: case 32: SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); break; default: fprintf(stderr, "Invalid pixel depth: %d bpp\n", info->vfmt->BitsPerPixel); } SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); Uint32 flags = SDL_OPENGL; if (config.Int("StartFullscreen")) flags |= SDL_FULLSCREEN; if ((Pi::scrSurface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, flags)) == 0) { // fall back on 16-bit depth buffer... SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); fprintf(stderr, "Failed to set video mode. (%s). Re-trying with 16-bit depth buffer.\n", SDL_GetError()); if ((Pi::scrSurface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, flags)) == 0) { fprintf(stderr, "Failed to set video mode: %s", SDL_GetError()); } } glewInit(); SDL_WM_SetCaption("Pioneer","Pioneer"); Pi::scrWidth = width; Pi::scrHeight = height; Pi::scrAspect = width / (float)height; Pi::rng.seed(time(NULL)); InitOpenGL(); GLFTInit(); // Gui::Init shouldn't initialise any VBOs, since we haven't tested // that the capability exists. (Gui does not use VBOs so far) Gui::Init(scrWidth, scrHeight, 800, 600); if (!GLEW_ARB_vertex_buffer_object) { Error("OpenGL extension ARB_vertex_buffer_object not supported. Pioneer can not run on your graphics card."); } Render::Init(width, height); draw_progress(0.1f); Galaxy::Init(); draw_progress(0.2f); NameGenerator::Init(); if (config.Int("DisableShaders")) Render::ToggleShaders(); if (config.Int("EnableHDR")) Render::ToggleHDR(); draw_progress(0.3f); LmrModelCompilerInit(); //unsigned int control_word; //_clearfp(); //_controlfp_s(&control_word, _EM_INEXACT | _EM_UNDERFLOW, _MCW_EM); //double fpexcept = Pi::timeAccelRates[1] / Pi::timeAccelRates[0]; draw_progress(0.4f); ShipType::Init(); draw_progress(0.5f); GeoSphere::Init(); draw_progress(0.6f); Space::Init(); draw_progress(0.7f); Polit::Init(); draw_progress(0.8f); SpaceStation::Init(); draw_progress(0.9f); if (!config.Int("DisableSound")) { Sound::Init(); Sound::SetGlobalVolume(config.Float("SfxVolume")); Sound::Pause(0); } draw_progress(1.0f); // test code to produce list of ship stats FILE *pStatFile = fopen("shipstat.csv","wt"); if (pStatFile) { fprintf(pStatFile, "name,lmrname,hullmass,capacity,xsize,ysize,zsize,facc,racc,uacc,aacc\n"); for (std::map<std::string, ShipType>::iterator i = ShipType::types.begin(); i != ShipType::types.end(); ++i) { ShipType *shipdef = &(i->second); LmrModel *lmrModel = LmrLookupModelByName(shipdef->lmrModelName.c_str()); LmrObjParams lmrParams; memset(&lmrParams, 0, sizeof(LmrObjParams)); LmrCollMesh *collMesh = new LmrCollMesh(lmrModel, &lmrParams); Aabb aabb = collMesh->GetAabb(); double hullmass = shipdef->hullMass; double capacity = shipdef->capacity; double xsize = aabb.max.x-aabb.min.x; double ysize = aabb.max.y-aabb.min.y; double zsize = aabb.max.z-aabb.min.z; double brad = aabb.GetBoundingRadius(); double simass = (hullmass + capacity) * 1000.0; double angInertia = (2/5.0)*simass*brad*brad; double acc1 = shipdef->linThrust[ShipType::THRUSTER_FORWARD] / (9.81*simass); double acc2 = shipdef->linThrust[ShipType::THRUSTER_REVERSE] / (9.81*simass); double acc3 = shipdef->linThrust[ShipType::THRUSTER_UP] / (9.81*simass); double acca = shipdef->angThrust/angInertia; fprintf(pStatFile, "%s,%s,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%f\n", shipdef->name.c_str(), shipdef->lmrModelName.c_str(), hullmass, capacity, xsize, ysize, zsize, acc1, acc2, acc3, acca); } fclose(pStatFile); } gameMenuView = new GameMenuView(); config.Save(); }
/* * Must create the folders if they do not exist already. */ std::string GetFullSavefileDirPath() { return GetPiUserDir("savefiles"); }
void Screendump(const char* destFile, const int width, const int height) { std::string fname = join_path(GetPiUserDir("screenshots").c_str(), destFile, 0); // pad rows to 4 bytes, which is the default row alignment for OpenGL const int stride = (3*width + 3) & ~3; std::vector<png_byte> pixel_data(stride * height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glPixelStorei(GL_PACK_ALIGNMENT, 4); // never trust defaults glReadBuffer(GL_FRONT); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &pixel_data[0]); glFinish(); png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); if (!png_ptr) { fprintf(stderr, "Couldn't create png_write_struct\n"); return; } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, 0); fprintf(stderr, "Couldn't create png_info_struct\n"); return; } //http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3.1 if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, &info_ptr); fprintf(stderr, "Couldn't set png jump buffer\n"); return; } FILE *out = fopen(fname.c_str(), "wb"); if (!out) { png_destroy_write_struct(&png_ptr, &info_ptr); fprintf(stderr, "Couldn't open %s for writing\n", fname.c_str()); return; } png_init_io(png_ptr, out); png_set_filter(png_ptr, 0, PNG_FILTER_NONE); png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_bytepp rows = new png_bytep[height]; for (int i = 0; i < height; ++i) { rows[i] = reinterpret_cast<png_bytep>(&pixel_data[(height-i-1) * stride]); } png_set_rows(png_ptr, info_ptr, rows); png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0); png_destroy_write_struct(&png_ptr, &info_ptr); delete[] rows; fclose(out); printf("Screenshot %s saved\n", fname.c_str()); }