Example #1
0
bool Engine::initEngine()
{
    LOGME_CALL("Engine::initEngine");
    setDisplayFps(config::debug::DisplayFps);

    return true;
}
Example #2
0
// --------------------------------------------------------------------------------------------------------
void KikiController::saveScreenShot ()
{
    static int counter = -1;
    KSize screenSize = getScreenSize();
    Uint32 rmask, gmask, bmask, amask;

    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x00000000;

    setDisplayFps(false);
    display();

    void * pixels = malloc (screenSize.w * screenSize.h * sizeof(GLuint));

#ifndef WIN32
    glReadPixels (0, 0, screenSize.w, screenSize.h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, pixels);
#else
	glReadPixels (0, 0, screenSize.w, screenSize.h, GL_RGBA, GL_4_BYTES, pixels);
#endif

    //............................................................ reverse order of lines (mirror vertical)
    int scanlineLength = screenSize.w * sizeof(GLuint);
    void * scanline = malloc (scanlineLength);
    for (int lineIndex = 0; lineIndex < screenSize.h/2; lineIndex++)
    {
        memcpy (scanline, 					// copy from bottom to save line
                &((char*)pixels)[lineIndex * scanlineLength], 
                scanlineLength);
        memcpy (&((char*)pixels)[lineIndex * scanlineLength],   // copy from top to bottom
                &((char*)pixels)[(screenSize.h-lineIndex-1) * scanlineLength], 
                scanlineLength);				// copy from save line to top
        memcpy (&((char*)pixels)[(screenSize.h-lineIndex-1) * scanlineLength], 
                scanline, 
                scanlineLength);
    }
    
    //............................................................ create SDL_surface from pixels
    SDL_Surface * saveSurface = SDL_CreateRGBSurfaceFrom (pixels, screenSize.w, screenSize.h, 32,
                                                          screenSize.w * 4, rmask, gmask, bmask, amask);
    
    free (scanline);
    
    if (saveSurface == NULL)
    {
        KConsole::printf("WARNING unable to copy screen surface for screenshot");
        free (pixels);
        return;
    }
    
    std::string screenShotFile;
    //............................................................ search for a free file name
    do  
    {
        counter++;
#ifndef WIN32
        screenShotFile = kStringPrintf("%s/kiki_%03d.bmp", getenv ("HOME"), counter);
#else
		screenShotFile = kStringPrintf("c:/kiki_%03d.bmp", counter);
#endif
    }
    while (kFileExists(screenShotFile));
    
    //............................................................ save the screenshot
    if (SDL_SaveBMP(saveSurface, screenShotFile.c_str()) == 0) 
    {
        KConsole::printf("screenshot saved to file %s", kFileAbsPathName(screenShotFile).c_str());
    }
    else // ooops...
    {
        KConsole::printf("WARNING unable to write screenshot to file %s", screenShotFile.c_str());
    }
    
    SDL_FreeSurface(saveSurface);
    free (pixels);
}