IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]SDL_LockSurface和SDL_UnlockSurface函数

    caimouse发表于 2016-12-05 17:51:44
    love 0

    用这两个函数实现对表面进行锁住,可以对surface->pixels进行读写。

    例子:

    	//
    	// 锁住表面
    	//
    	if (SDL_MUSTLOCK(gpScreenReal))
    	{
    		if (SDL_LockSurface(gpScreenReal) < 0)
    			return;
    	}
    
    	if (!bScaleScreen)
    	{
    		screenRealHeight -= offset;
    		screenRealY = offset / 2;
    	}
    
    	if (lpRect != NULL)
    	{
    		dstrect.x = (SHORT)((INT)(lpRect->x) * gpScreenReal->w / gpScreen->w);
    		dstrect.y = (SHORT)((INT)(screenRealY + lpRect->y) * screenRealHeight / gpScreen->h);
    		dstrect.w = (WORD)((DWORD)(lpRect->w) * gpScreenReal->w / gpScreen->w);
    		dstrect.h = (WORD)((DWORD)(lpRect->h) * screenRealHeight / gpScreen->h);
    
    		SDL_SoftStretch(gpScreen, (SDL_Rect *)lpRect, gpScreenReal, &dstrect);
    		if (SDL_MUSTLOCK(gpScreenReal))
    		{
    			SDL_UnlockSurface(gpScreenReal);
    		}
    
    		SDL_UpdateRect(gpScreenReal, dstrect.x, dstrect.y, dstrect.w, dstrect.h);
    	}


    老蔡学堂



沪ICP备19023445号-2号
友情链接