void releaseSpecialKey(int key, int x, int y) { int ret; switch (key) { case GLUT_KEY_LEFT: if(_camera->deltaAngle < 0.0f) _camera->deltaAngle = 0.0f; break; case GLUT_KEY_RIGHT: if(_camera->deltaAngle > 0.0f) _camera->deltaAngle = 0.0f; break; case GLUT_KEY_UP: if(_camera->deltaMove > 0.0f) _camera->deltaMove = 0.0f; break; case GLUT_KEY_DOWN: if(_camera->deltaMove < 0.0f) _camera->deltaMove = 0.0f; break; case GLUT_KEY_F2: ret = SOIL_save_screenshot("img.bmp", SOIL_SAVE_TYPE_BMP, 0,0,1344,768); if(ret) printf("\nScreensave saved!\n"); else printf("\nScreensave NOT saved!"); break; default: break; } }
bool GLVideo::SaveScreenshot( const str_type::char_t* name, const Texture::BITMAP_FORMAT fmt, math::Rect2D rect) { str_type::string fileName = name, ext; const int type = GetSOILTexType(fmt, ext); if (!Platform::IsExtensionRight(fileName, ext)) fileName.append(ext); if (rect.size.x <= 0 || rect.size.y <= 0) { rect.pos = math::Vector2i(0,0); rect.size = GetScreenSize(); } const bool r = (SOIL_save_screenshot( fileName.c_str(), type, rect.pos.x, rect.pos.y, rect.size.x, rect.size.y)); if (!r) { ShowMessage(str_type::string("Couldn't save screen shot ") + fileName, GSMT_ERROR); } return r; }
//todo: append date/time info so I get unique screenshot names //todo: save as png void asdf_multiplat_t::save_screenshot(std::string file_path) const { // if the last 3 characters aren't "bmp", tack on ".bmp" // check the length first, rather than trying to compare with a substring of size - 3 where size might be smaller than 3 if (file_path.size() > 4 && (file_path.compare(file_path.size() - 3, 3, "bmp") != 0)) { file_path += ".bmp"; } auto save_result = SOIL_save_screenshot ( file_path.c_str(), SOIL_SAVE_TYPE_BMP, 0, 0, settings.resolution_width, settings.resolution_height ); //soil returns 0 for failure apparently if(save_result == 0) { LOG("ERROR: SOIL failed saving screenshot {%zu,%zu} \"%s\"" , settings.resolution_width, settings.resolution_height, file_path.c_str()); LOG(" SOIL: %s", SOIL_last_result()); } else { LOG("Screenshot saved to: \"%s\"", file_path.c_str()); } }
void sierpin(GLfloatPoint *corner) { int index = rand()%3; GLfloatPoint point = corner[index]; drawDot(point.x,point.y); int i; for(i=0;i<50000;i++) { index = rand()%3; point.x=(point.x + corner[index].x)/2; point.y=(point.y + corner[index].y)/2; drawDot(point.x,point.y); } SOIL_save_screenshot("output/sierpinMouse.bmp",SOIL_SAVE_TYPE_BMP,0,0,640,600); }
void screenshot(std::string _filename, int _w, int _h) { _filename.append(date_time()); _filename.append(".bmp"); std::vector< unsigned char > buf( _w * _h * 3 ); glPixelStorei( GL_PACK_ALIGNMENT, 1 ); glReadPixels( 0, 0, _w, _h, GL_RGB, GL_UNSIGNED_BYTE, &buf[0] ); _w= glutGet(GLUT_WINDOW_WIDTH); _h = glutGet(GLUT_WINDOW_HEIGHT); int state = SOIL_save_screenshot(_filename.c_str(), SOIL_SAVE_TYPE_BMP, 0, 0, _w, _h); if (!state) std::cout << "Error: Cannot save the screenshot" << std::endl; else std::cout << "Saved in " << _filename << std::endl; }
void sierpin(void) { glClear(GL_COLOR_BUFFER_BIT); GLfloatPoint T[3] = {{10,10},{600,10},{300,600}}; int index = rand()%3; GLfloatPoint point = T[index]; drawDot(point.x,point.y); int i; for(i=0;i<50000;i++) { index = rand()%3; point.x=(point.x + T[index].x)/2; point.y=(point.y + T[index].y)/2; drawDot(point.x,point.y); } SOIL_save_screenshot("output/sierpin.bmp",SOIL_SAVE_TYPE_BMP,0,0,640,600); glFlush(); }
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if(action == GLFW_PRESS ){ if(key == GLFW_KEY_W) { char filename[] = "out.bmp"; SOIL_save_screenshot ( filename, SOIL_SAVE_TYPE_BMP, 0, 0, WIDTH, HEIGHT ); } #ifdef STATIC_IMAGES } else if(key == GLFW_KEY_N) { // Capture Image stream1 >> cameraFrame; if( cameraFrame.empty() ) { exit(0); } updated = true; #endif }
void Painter::save_painting(std::string folder, int time_step) { draw(); std::ostringstream s; if (folder.length() == 0) { s << "scr"; } else { s << folder << "/scr"; } if (time_step >= 0) { s << std::string(Util::concat4digits("_", time_step)); } s << ".png"; int success = SOIL_save_screenshot(s.str().c_str(), SOIL_SAVE_TYPE_PNG, 0, 0, WIDTH, HEIGHT); if(!success) { std::cout << "ERROR: Failed to take screen shot: " << s.str().c_str() << std::endl; return; } }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; HWND hwnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; float theta = 0.0f; // register window class wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_OWNDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = "GLSample"; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if (!RegisterClassEx(&wcex)) return 0; // create main window hwnd = CreateWindowEx(0, "GLSample", "SOIL Sample", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 512, 512, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nCmdShow); // check my error handling /* SOIL_load_OGL_texture( "img_test.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0 ); std::cout << "'" << SOIL_last_result() << "'" << std::endl; */ // enable OpenGL for the window EnableOpenGL(hwnd, &hDC, &hRC); glEnable( GL_BLEND ); //glDisable( GL_BLEND ); // straight alpha glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // premultiplied alpha (remember to do the same in glColor!!) //glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); // do I want alpha thresholding? glEnable( GL_ALPHA_TEST ); glAlphaFunc( GL_GREATER, 0.5f ); // log what the use is asking us to load std::string load_me = lpCmdLine; if( load_me.length() > 2 ) { //load_me = load_me.substr( 1, load_me.length() - 2 ); load_me = load_me.substr( 0, load_me.length() - 0 ); } else { //load_me = "img_test_uncompressed.dds"; //load_me = "img_test_indexed.tga"; //load_me = "img_test.dds"; load_me = "img_test.png"; //load_me = "odd_size.jpg"; //load_me = "img_cheryl.jpg"; //load_me = "oak_odd.png"; //load_me = "field_128_cube.dds"; //load_me = "field_128_cube_nomip.dds"; //load_me = "field_128_cube_uc.dds"; //load_me = "field_128_cube_uc_nomip.dds"; //load_me = "Goblin.dds"; //load_me = "parquet.dds"; //load_me = "stpeters_probe.hdr"; //load_me = "VeraMoBI_sdf.png"; // for testing the texture rectangle code //load_me = "test_rect.png"; } std::cout << "'" << load_me << "'" << std::endl; // 1st try to load it as a single-image-cubemap // (note, need DDS ordered faces: "EWUDNS") GLuint tex_ID; int time_me; std::cout << "Attempting to load as a cubemap" << std::endl; time_me = clock(); tex_ID = SOIL_load_OGL_single_cubemap( load_me.c_str(), SOIL_DDS_CUBEMAP_FACE_ORDER, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS //| SOIL_FLAG_COMPRESS_TO_DXT //| SOIL_FLAG_TEXTURE_REPEATS //| SOIL_FLAG_INVERT_Y | SOIL_FLAG_DDS_LOAD_DIRECT ); time_me = clock() - time_me; std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl; if( tex_ID > 0 ) { glEnable( GL_TEXTURE_CUBE_MAP ); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glEnable( GL_TEXTURE_GEN_R ); glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP ); glBindTexture( GL_TEXTURE_CUBE_MAP, tex_ID ); // report std::cout << "the loaded single cube map ID was " << tex_ID << std::endl; //std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl; } else { std::cout << "Attempting to load as a HDR texture" << std::endl; time_me = clock(); tex_ID = SOIL_load_OGL_HDR_texture( load_me.c_str(), //SOIL_HDR_RGBE, //SOIL_HDR_RGBdivA, SOIL_HDR_RGBdivA2, 0, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS //| SOIL_FLAG_COMPRESS_TO_DXT ); time_me = clock() - time_me; std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl; // did I fail? if( tex_ID < 1 ) { // loading of the single-image-cubemap failed, try it as a simple texture std::cout << "Attempting to load as a simple 2D texture" << std::endl; // load the texture, if specified time_me = clock(); tex_ID = SOIL_load_OGL_texture( load_me.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS //| SOIL_FLAG_MULTIPLY_ALPHA //| SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT //| SOIL_FLAG_NTSC_SAFE_RGB //| SOIL_FLAG_CoCg_Y //| SOIL_FLAG_TEXTURE_RECTANGLE ); time_me = clock() - time_me; std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl; } if( tex_ID > 0 ) { // enable texturing glEnable( GL_TEXTURE_2D ); //glEnable( 0x84F5 );// enables texture rectangle // bind an OpenGL texture ID glBindTexture( GL_TEXTURE_2D, tex_ID ); // report std::cout << "the loaded texture ID was " << tex_ID << std::endl; //std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl; } else { // loading of the texture failed...why? glDisable( GL_TEXTURE_2D ); std::cout << "Texture loading failed: '" << SOIL_last_result() << "'" << std::endl; } } // program main loop const float ref_mag = 0.1f; while (!bQuit) { // check for messages if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // handle or dispatch messages if (msg.message == WM_QUIT) { bQuit = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { // OpenGL animation code goes here theta = clock() * 0.1; float tex_u_max = 1.0f;//0.2f; float tex_v_max = 1.0f;//0.2f; glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glScalef( 0.8f, 0.8f, 0.8f ); //glRotatef(-0.314159f*theta, 0.0f, 0.0f, 1.0f); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glNormal3f( 0.0f, 0.0f, 1.0f ); glBegin(GL_QUADS); glNormal3f( -ref_mag, -ref_mag, 1.0f ); glTexCoord2f( 0.0f, tex_v_max ); glVertex3f( -1.0f, -1.0f, -0.1f ); glNormal3f( ref_mag, -ref_mag, 1.0f ); glTexCoord2f( tex_u_max, tex_v_max ); glVertex3f( 1.0f, -1.0f, -0.1f ); glNormal3f( ref_mag, ref_mag, 1.0f ); glTexCoord2f( tex_u_max, 0.0f ); glVertex3f( 1.0f, 1.0f, -0.1f ); glNormal3f( -ref_mag, ref_mag, 1.0f ); glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, 1.0f, -0.1f ); glEnd(); glPopMatrix(); tex_u_max = 1.0f; tex_v_max = 1.0f; glPushMatrix(); glScalef( 0.8f, 0.8f, 0.8f ); glRotatef(theta, 0.0f, 0.0f, 1.0f); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glNormal3f( 0.0f, 0.0f, 1.0f ); glBegin(GL_QUADS); glTexCoord2f( 0.0f, tex_v_max ); glVertex3f( 0.0f, 0.0f, 0.1f ); glTexCoord2f( tex_u_max, tex_v_max ); glVertex3f( 1.0f, 0.0f, 0.1f ); glTexCoord2f( tex_u_max, 0.0f ); glVertex3f( 1.0f, 1.0f, 0.1f ); glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, 1.0f, 0.1f ); glEnd(); glPopMatrix(); { /* check for errors */ GLenum err_code = glGetError(); while( GL_NO_ERROR != err_code ) { printf( "OpenGL Error @ %s: %i", "drawing loop", err_code ); err_code = glGetError(); } } SwapBuffers(hDC); Sleep (1); } } // and show off the screenshot capability /* load_me += "-screenshot.tga"; SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_TGA, 0, 0, 512, 512 ); //*/ //* load_me += "-screenshot.bmp"; SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_BMP, 0, 0, 512, 512 ); //*/ /* load_me += "-screenshot.dds"; SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_DDS, 0, 0, 512, 512 ); //*/ // shutdown OpenGL DisableOpenGL(hwnd, hDC, hRC); // destroy the window explicitly DestroyWindow(hwnd); return msg.wParam; }
ruby_value rb_mGraphicsCLASS_to_bmp(ruby_value self, ruby_value filename) { return SOIL_save_screenshot(StringValuePtr(filename), SOIL_SAVE_TYPE_BMP, 0, 0, qgf_graphics_width, qgf_graphics_height); }