void LinuxmotoSdlGraphicsManager::internUpdateScreen() { SDL_Surface *srcSurf, *origSurf; int height, width; ScalerProc *scalerProc; int scale1; #if defined (DEBUG) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?) assert(_hwscreen != NULL); assert(_hwscreen->map->sw_data != NULL); #endif // If the shake position changed, fill the dirty area with blackness if (_currentShakePos != _newShakePos) { SDL_Rect blackrect = {0, 0, _videoMode.screenWidth * _videoMode.scaleFactor, _newShakePos * _videoMode.scaleFactor}; if (_videoMode.aspectRatioCorrection && !_overlayVisible) blackrect.h = real2Aspect(blackrect.h - 1) + 1; SDL_FillRect(_hwscreen, &blackrect, 0); _currentShakePos = _newShakePos; _forceFull = true; } // Check whether the palette was changed in the meantime and update the // screen surface accordingly. if (_screen && _paletteDirtyEnd != 0) { SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart, _paletteDirtyStart, _paletteDirtyEnd - _paletteDirtyStart); _paletteDirtyEnd = 0; _forceFull = true; } #ifdef USE_OSD // OSD visible (i.e. non-transparent)? if (_osdAlpha != SDL_ALPHA_TRANSPARENT) { // Updated alpha value const int diff = SDL_GetTicks() - _osdFadeStartTime; if (diff > 0) { if (diff >= kOSDFadeOutDuration) { // Back to full transparency _osdAlpha = SDL_ALPHA_TRANSPARENT; } else { // Do a linear fade out... const int startAlpha = SDL_ALPHA_TRANSPARENT + kOSDInitialAlpha * (SDL_ALPHA_OPAQUE - SDL_ALPHA_TRANSPARENT) / 100; _osdAlpha = startAlpha + diff * (SDL_ALPHA_TRANSPARENT - startAlpha) / kOSDFadeOutDuration; } SDL_SetAlpha(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _osdAlpha); _forceFull = true; } } #endif if (!_overlayVisible) { origSurf = _screen; srcSurf = _tmpscreen; width = _videoMode.screenWidth; height = _videoMode.screenHeight; scalerProc = _scalerProc; scale1 = _videoMode.scaleFactor; } else { origSurf = _overlayscreen; srcSurf = _tmpscreen2; width = _videoMode.overlayWidth; height = _videoMode.overlayHeight; scalerProc = Normal1x; scale1 = 1; } // Add the area covered by the mouse cursor to the list of dirty rects if // we have to redraw the mouse. if (_mouseNeedsRedraw) undrawMouse(); // Force a full redraw if requested if (_forceFull) { _numDirtyRects = 1; _dirtyRectList[0].x = 0; _dirtyRectList[0].y = 0; _dirtyRectList[0].w = width; _dirtyRectList[0].h = height; } // Only draw anything if necessary if (_numDirtyRects > 0 || _mouseNeedsRedraw) { SDL_Rect *r; SDL_Rect dst; uint32 srcPitch, dstPitch; SDL_Rect *lastRect = _dirtyRectList + _numDirtyRects; for (r = _dirtyRectList; r != lastRect; ++r) { dst = *r; dst.x++; // Shift rect by one since 2xSai needs to access the data around dst.y++; // any pixel to scale it, and we want to avoid mem access crashes. if (SDL_BlitSurface(origSurf, r, srcSurf, &dst) != 0) error("SDL_BlitSurface failed: %s", SDL_GetError()); } SDL_LockSurface(srcSurf); SDL_LockSurface(_hwscreen); srcPitch = srcSurf->pitch; dstPitch = _hwscreen->pitch; for (r = _dirtyRectList; r != lastRect; ++r) { register int dst_y = r->y + _currentShakePos; register int dst_h = 0; register int dst_w = r->w; register int orig_dst_y = 0; register int dst_x = r->x; register int src_y; register int src_x; if (dst_y < height) { dst_h = r->h; if (dst_h > height - dst_y) dst_h = height - dst_y; orig_dst_y = dst_y; src_x = dst_x; src_y = dst_y; if (_videoMode.aspectRatioCorrection && !_overlayVisible) dst_y = real2Aspect(dst_y); assert(scalerProc != NULL); if (_videoMode.mode == GFX_HALF && scalerProc == DownscaleAllByHalf) { if (dst_x%2==1) { dst_x--; dst_w++; } if (dst_y%2==1) { dst_y--; dst_h++; } if (dst_w&1) dst_w++; if (dst_h&1) dst_h++; src_x = dst_x; src_y = dst_y; dst_x = dst_x / 2; dst_y = dst_y / 2; } scalerProc((byte *)srcSurf->pixels + (src_x * 2 + 2) + (src_y + 1) * srcPitch, srcPitch, (byte *)_hwscreen->pixels + dst_x * 2 + dst_y * dstPitch, dstPitch, dst_w, dst_h); } if (_videoMode.mode == GFX_HALF && scalerProc == DownscaleAllByHalf) { r->w = r->w / 2; r->h = dst_h / 2; } else { r->w = r->w; r->h = dst_h; } r->x = dst_x; r->y = dst_y; #ifdef USE_SCALERS if (_videoMode.aspectRatioCorrection && orig_dst_y < height && !_overlayVisible) r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1); #endif } SDL_UnlockSurface(srcSurf); SDL_UnlockSurface(_hwscreen); // Readjust the dirty rect list in case we are doing a full update. // This is necessary if shaking is active. if (_forceFull) { _dirtyRectList[0].y = 0; _dirtyRectList[0].h = (_videoMode.mode == GFX_HALF) ? effectiveScreenHeight()/2 : effectiveScreenHeight(); } drawMouse(); #ifdef USE_OSD if (_osdAlpha != SDL_ALPHA_TRANSPARENT) { SDL_BlitSurface(_osdSurface, 0, _hwscreen, 0); } #endif // Finally, blit all our changes to the screen SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList); } _numDirtyRects = 0; _forceFull = false; _mouseNeedsRedraw = false; }
void WINCESdlGraphicsManager::internUpdateScreen() { SDL_Surface *srcSurf, *origSurf; static bool old_overlayVisible = false; int numRectsOut = 0; int16 routx, routy, routw, routh, stretch, shakestretch; assert(_hwscreen != NULL); // bail if the application is minimized, be nice to OS if (!_hasfocus) { Sleep(20); return; } // If the shake position changed, fill the dirty area with blackness if (_currentShakePos != _newShakePos) { SDL_Rect blackrect = {0, 0, _videoMode.screenWidth *_scaleFactorXm / _scaleFactorXd, _newShakePos *_scaleFactorYm / _scaleFactorYd}; if (_videoMode.aspectRatioCorrection) blackrect.h = real2Aspect(blackrect.h - 1) + 1; SDL_FillRect(_hwscreen, &blackrect, 0); _currentShakePos = _newShakePos; _forceFull = true; } // Make sure the mouse is drawn, if it should be drawn. drawMouse(); // Check whether the palette was changed in the meantime and update the // screen surface accordingly. if (_paletteDirtyEnd != 0) { SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart, _paletteDirtyStart, _paletteDirtyEnd - _paletteDirtyStart); _paletteDirtyEnd = 0; _forceFull = true; } if (!_overlayVisible) { origSurf = _screen; srcSurf = _tmpscreen; } else { origSurf = _overlayscreen; srcSurf = _tmpscreen2; } if (old_overlayVisible != _overlayVisible) { old_overlayVisible = _overlayVisible; update_scalers(); } // Force a full redraw if requested if (_forceFull) { _numDirtyRects = 1; _dirtyRectList[0].x = 0; if (!_zoomDown) _dirtyRectList[0].y = 0; else _dirtyRectList[0].y = _videoMode.screenHeight / 2; _dirtyRectList[0].w = _videoMode.screenWidth; if (!_zoomUp && !_zoomDown) _dirtyRectList[0].h = _videoMode.screenHeight; else _dirtyRectList[0].h = _videoMode.screenHeight / 2; _toolbarHandler.forceRedraw(); } // Only draw anything if necessary if (_numDirtyRects > 0) { SDL_Rect *r, *rout; SDL_Rect dst; uint32 srcPitch, dstPitch; SDL_Rect *last_rect = _dirtyRectList + _numDirtyRects; bool toolbarVisible = _toolbarHandler.visible(); int toolbarOffset = _toolbarHandler.getOffset(); for (r = _dirtyRectList; r != last_rect; ++r) { dst = *r; dst.x++; // Shift rect by one since 2xSai needs to access the data around dst.y++; // any pixel to scale it, and we want to avoid mem access crashes. // NOTE: This is also known as BLACK MAGIC, copied from the sdl backend if (SDL_BlitSurface(origSurf, r, srcSurf, &dst) != 0) error("SDL_BlitSurface failed: %s", SDL_GetError()); } SDL_LockSurface(srcSurf); SDL_LockSurface(_hwscreen); srcPitch = srcSurf->pitch; dstPitch = _hwscreen->pitch; for (r = _dirtyRectList, rout = _dirtyRectOut; r != last_rect; ++r) { // always clamp to enclosing, downsampled-grid-aligned rect in the downscaled image if (_scaleFactorXd != 1) { stretch = r->x % _scaleFactorXd; r->x -= stretch; r->w += stretch; r->w = (r->x + r->w + _scaleFactorXd - 1) / _scaleFactorXd * _scaleFactorXd - r->x; } if (_scaleFactorYd != 1) { stretch = r->y % _scaleFactorYd; r->y -= stretch; r->h += stretch; r->h = (r->y + r->h + _scaleFactorYd - 1) / _scaleFactorYd * _scaleFactorYd - r->y; } // transform shakestretch = _currentShakePos * _scaleFactorYm / _scaleFactorYd; routx = r->x * _scaleFactorXm / _scaleFactorXd; // locate position in scaled screen routy = r->y * _scaleFactorYm / _scaleFactorYd + shakestretch; // adjust for shake offset routw = r->w * _scaleFactorXm / _scaleFactorXd; routh = r->h * _scaleFactorYm / _scaleFactorYd - shakestretch; // clipping destination rectangle inside device screen (more strict, also more tricky but more stable) // note that all current scalers do not make dst rect exceed left/right, unless chosen badly (FIXME) if (_zoomDown) routy -= 240; // adjust for zoom position if (routy + routh < 0) continue; if (routy < 0) { routh += routy; r->y -= routy * _scaleFactorYd / _scaleFactorYm; routy = 0; r->h = routh * _scaleFactorYd / _scaleFactorYm; } if (_orientationLandscape) { if (routy > OSystem_WINCE3::getScreenWidth()) continue; if (routy + routh > OSystem_WINCE3::getScreenWidth()) { routh = OSystem_WINCE3::getScreenWidth() - routy; r->h = routh * _scaleFactorYd / _scaleFactorYm; } } else { if (routy > OSystem_WINCE3::getScreenHeight()) continue; if (routy + routh > OSystem_WINCE3::getScreenHeight()) { routh = OSystem_WINCE3::getScreenHeight() - routy; r->h = routh * _scaleFactorYd / _scaleFactorYm; } } // check if the toolbar is overwritten if (toolbarVisible && r->y + r->h >= toolbarOffset) _toolbarHandler.forceRedraw(); // blit it (with added voodoo from the sdl backend, shifting the source rect again) _scalerProc((byte *)srcSurf->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch, (byte *)_hwscreen->pixels + routx * 2 + routy * dstPitch, dstPitch, r->w, r->h - _currentShakePos); // add this rect to output rout->x = routx; rout->y = routy - shakestretch; rout->w = routw; rout->h = routh + shakestretch; numRectsOut++; rout++; } SDL_UnlockSurface(srcSurf); SDL_UnlockSurface(_hwscreen); } // Add the toolbar if needed SDL_Rect toolbar_rect[1]; if (_panelVisible && _toolbarHandler.draw(_toolbarLow, &toolbar_rect[0])) { // It can be drawn, scale it uint32 srcPitch, dstPitch; SDL_Surface *toolbarSurface; ScalerProc *toolbarScaler; if (_videoMode.screenHeight > 240) { if (!_toolbarHighDrawn) { // Resize the toolbar SDL_LockSurface(_toolbarLow); SDL_LockSurface(_toolbarHigh); Normal2x((byte *)_toolbarLow->pixels, _toolbarLow->pitch, (byte *)_toolbarHigh->pixels, _toolbarHigh->pitch, toolbar_rect[0].w, toolbar_rect[0].h); SDL_UnlockSurface(_toolbarHigh); SDL_UnlockSurface(_toolbarLow); _toolbarHighDrawn = true; } toolbar_rect[0].w *= 2; toolbar_rect[0].h *= 2; toolbarSurface = _toolbarHigh; } else toolbarSurface = _toolbarLow; drawToolbarMouse(toolbarSurface, true); // draw toolbar mouse if applicable // Apply the appropriate scaler SDL_LockSurface(toolbarSurface); SDL_LockSurface(_hwscreen); srcPitch = toolbarSurface->pitch; dstPitch = _hwscreen->pitch; toolbarScaler = _scalerProc; if (_videoMode.scaleFactor == 2) toolbarScaler = Normal2x; else if (_videoMode.scaleFactor == 3) toolbarScaler = Normal3x; toolbarScaler((byte *)toolbarSurface->pixels, srcPitch, (byte *)_hwscreen->pixels + (_toolbarHandler.getOffset() * _scaleFactorYm / _scaleFactorYd * dstPitch), dstPitch, toolbar_rect[0].w, toolbar_rect[0].h); SDL_UnlockSurface(toolbarSurface); SDL_UnlockSurface(_hwscreen); // And blit it toolbar_rect[0].y = _toolbarHandler.getOffset(); toolbar_rect[0].x = toolbar_rect[0].x * _scaleFactorXm / _scaleFactorXd; toolbar_rect[0].y = toolbar_rect[0].y * _scaleFactorYm / _scaleFactorYd; toolbar_rect[0].w = toolbar_rect[0].w * _scaleFactorXm / _scaleFactorXd; toolbar_rect[0].h = toolbar_rect[0].h * _scaleFactorYm / _scaleFactorYd; SDL_UpdateRects(_hwscreen, 1, toolbar_rect); drawToolbarMouse(toolbarSurface, false); // undraw toolbar mouse } // Finally, blit all our changes to the screen if (numRectsOut > 0) SDL_UpdateRects(_hwscreen, numRectsOut, _dirtyRectOut); _numDirtyRects = 0; _forceFull = false; }
alpp::Scale{ 0.05f * display.width/(float)image.width, 0.05f * display.height/(float)image.height }, alpp::Color{ 255, 255, 255}, alpp::Rad{ (float)std::atan2( boid.vy, boid.vx ) } ); }; process = [](auto const& oldWorld, auto const& display, auto dt){ World newWorld = oldWorld; auto interactWithMouse = makeAttractor(mouseX, mouseY, display, -3000, 1); auto attractToCenter = makeAttractor(400, 400, display, 10, 2); auto follow = seekSibling(world, 20); auto repulse = makeRepulser(world, 0.1); drawMouse(display, mouseX, mouseY); for(auto& boid: newWorld) { boid= limitSpeed(boid, 0.5); boid= clipToWorld(boid); boid= follow(boid, dt); boid= interactWithMouse(boid, dt); boid= attractToCenter(boid, dt); boid= limitForces(boid, 1); boid= speedUpBoid(boid, dt); boid= moveBoid(boid, dt); } for(auto& boid: newWorld) { drawBoid(boid, display); }
void GPHGraphicsManager::internUpdateScreen() { SDL_Surface *srcSurf, *origSurf; int height, width; ScalerProc *scalerProc; int scale1; #if defined(DEBUG) assert(_hwScreen != NULL); assert(_hwScreen->map->sw_data != NULL); #endif // If the shake position changed, fill the dirty area with blackness if (_currentShakePos != _newShakePos || (_cursorNeedsRedraw && _mouseBackup.y <= _currentShakePos)) { SDL_Rect blackrect = {0, 0, _videoMode.screenWidth *_videoMode.scaleFactor, _newShakePos *_videoMode.scaleFactor}; if (_videoMode.aspectRatioCorrection && !_overlayVisible) blackrect.h = real2Aspect(blackrect.h - 1) + 1; SDL_FillRect(_hwScreen, &blackrect, 0); _currentShakePos = _newShakePos; _forceRedraw = true; } // Check whether the palette was changed in the meantime and update the // screen surface accordingly. if (_screen && _paletteDirtyEnd != 0) { SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart, _paletteDirtyStart, _paletteDirtyEnd - _paletteDirtyStart); _paletteDirtyEnd = 0; _forceRedraw = true; } if (!_overlayVisible) { origSurf = _screen; srcSurf = _tmpscreen; width = _videoMode.screenWidth; height = _videoMode.screenHeight; scalerProc = _scalerProc; scale1 = _videoMode.scaleFactor; } else { origSurf = _overlayscreen; srcSurf = _tmpscreen2; width = _videoMode.overlayWidth; height = _videoMode.overlayHeight; scalerProc = Normal1x; scale1 = 1; } // Add the area covered by the mouse cursor to the list of dirty rects if // we have to redraw the mouse. if (_cursorNeedsRedraw) undrawMouse(); #ifdef USE_OSD updateOSD(); #endif // Force a full redraw if requested if (_forceRedraw) { _numDirtyRects = 1; _dirtyRectList[0].x = 0; _dirtyRectList[0].y = 0; _dirtyRectList[0].w = width; _dirtyRectList[0].h = height; // HACK: Make sure the full hardware screen is wiped clean. SDL_FillRect(_hwScreen, NULL, 0); } // Only draw anything if necessary if (_numDirtyRects > 0 || _cursorNeedsRedraw) { SDL_Rect *r; SDL_Rect dst; uint32 srcPitch, dstPitch; SDL_Rect *lastRect = _dirtyRectList + _numDirtyRects; for (r = _dirtyRectList; r != lastRect; ++r) { dst = *r; dst.x++; // Shift rect by one since 2xSai needs to access the data around dst.y++; // any pixel to scale it, and we want to avoid mem access crashes. if (SDL_BlitSurface(origSurf, r, srcSurf, &dst) != 0) error("SDL_BlitSurface failed: %s", SDL_GetError()); } SDL_LockSurface(srcSurf); SDL_LockSurface(_hwScreen); srcPitch = srcSurf->pitch; dstPitch = _hwScreen->pitch; for (r = _dirtyRectList; r != lastRect; ++r) { int dst_y = r->y + _currentShakePos; int dst_h = 0; int dst_w = r->w; int orig_dst_y = 0; int dst_x = r->x; int src_y; int src_x; if (dst_y < height) { dst_h = r->h; if (dst_h > height - dst_y) dst_h = height - dst_y; orig_dst_y = dst_y; src_x = dst_x; src_y = dst_y; if (_videoMode.aspectRatioCorrection && !_overlayVisible) dst_y = real2Aspect(dst_y); assert(scalerProc != NULL); if ((_videoMode.mode == GFX_HALF) && (scalerProc == DownscaleAllByHalf)) { if (dst_x % 2 == 1) { dst_x--; dst_w++; } if (dst_y % 2 == 1) { dst_y--; dst_h++; } src_x = dst_x; src_y = dst_y; dst_x = dst_x / 2; dst_y = dst_y / 2; scalerProc((byte *)srcSurf->pixels + (src_x * 2 + 2) + (src_y + 1) * srcPitch, srcPitch, (byte *)_hwScreen->pixels + dst_x * 2 + dst_y * dstPitch, dstPitch, dst_w, dst_h); } else { scalerProc((byte *)srcSurf->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch, (byte *)_hwScreen->pixels + r->x * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h); } } if (_videoMode.mode == GFX_HALF && scalerProc == DownscaleAllByHalf) { r->w = r->w / 2; r->h = dst_h / 2; } else { r->w = r->w; r->h = dst_h; } r->x = dst_x; r->y = dst_y; #ifdef USE_SCALERS if (_videoMode.aspectRatioCorrection && orig_dst_y < height && !_overlayVisible) r->h = stretch200To240((uint8 *) _hwScreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1); #endif } SDL_UnlockSurface(srcSurf); SDL_UnlockSurface(_hwScreen); // Readjust the dirty rect list in case we are doing a full update. // This is necessary if shaking is active. if (_forceRedraw) { _dirtyRectList[0].y = 0; _dirtyRectList[0].h = (_videoMode.mode == GFX_HALF) ? _videoMode.hardwareHeight / 2 : _videoMode.hardwareHeight; } drawMouse(); #ifdef USE_OSD drawOSD(); #endif // Finally, blit all our changes to the screen SDL_UpdateRects(_hwScreen, _numDirtyRects, _dirtyRectList); } _numDirtyRects = 0; _forceRedraw = false; _cursorNeedsRedraw = false; }
void glutDisplay() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); loadGlobalCoord(); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, AMBIENT_LIGHT); glLightfv(GL_LIGHT0, GL_DIFFUSE, DIFFUSE_LIGHT); glLightfv(GL_LIGHT0, GL_SPECULAR, SPECULAR_LIGHT); glLightfv(GL_LIGHT0, GL_POSITION, LIGHT_POSITION); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_AMBIENT, AMBIENT_SUB_LIGHT); glLightfv(GL_LIGHT1, GL_DIFFUSE, DIFFUSE_SUB_LIGHT); glLightfv(GL_LIGHT1, GL_SPECULAR, SPECULAR_LIGHT); glLightfv(GL_LIGHT1, GL_POSITION, SUB_LIGHT_POSITION); glEnable(GL_COLOR_MATERIAL); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, MATERIAL_AMBIENT); glMaterialfv(GL_FRONT, GL_SPECULAR, MATERIAL_SPECULAR); glMateriali(GL_FRONT, GL_SHININESS, 48); glTranslatef(0, 0, baseTrans); glRotatef(bodyRot, 0, 0, 1); glRotatef(90.0f, 1, 0, 0); glColor3f(1.0, 1.0, 0); // Yellow color GLUquadricObj* body = gluNewQuadric(); gluCylinder(body, 5.5, 7.0, 17, 100, 10); gluDeleteQuadric(body); glPushMatrix(); drawLeftArm(); glPopMatrix(); glPushMatrix(); drawRightArm(); glPopMatrix(); glPushMatrix(); drawLeftLeg(); glPopMatrix(); glPushMatrix(); drawRightLeg(); glPopMatrix(); glPushMatrix(); drawTail(); glPushMatrix(); drawBall(); glPopMatrix(); glPopMatrix(); glPushMatrix(); drawHead(); glPushMatrix(); drawLeftEye(); glPopMatrix(); glPushMatrix(); drawRightEye(); glPopMatrix(); glPushMatrix(); drawLeftCheek(); glPopMatrix(); glPushMatrix(); drawRightCheek(); glPopMatrix(); glPushMatrix(); drawMouse(); glPopMatrix(); glPushMatrix(); drawLeftEar(); glPopMatrix(); glPushMatrix(); drawRightEar(); glPopMatrix(); glPopMatrix(); glutSwapBuffers(); }