level 13
savage200
楼主
我准备在一个背景纹理上合并一文字,我有两个思路:
1。思路如下
SUR = IMG_Load(Bkg_Img);
生成表面
Bkg_Texture = SDL_CreateTextureFromSurface(REN, SUR);
生成纹理
SDL_GetClipRect(SUR,&Bkg_Rect);
获取高宽
SDL_Surface *txtsur=TTF_RenderUTF8_Blended(Font,"测试用文字字符串!", SDL_Color {220, 220, 220, 0});
生成文字表面
SDL_BlitSurface(txtsur,NULL,SUR,NULL);
贴合表面
SDL_FreeSurface(txtsur);
清除
Bkg_Texture = SDL_CreateTextureFromSurface(REN, SUR);
生成纹理合并
下边显示
SDL_FreeSurface(SUR);
SDL_RenderClear(REN);
SDL_RenderCopy(REN, Bkg_Texture, &Bkg_Rect , &Screen_Rect);
SDL_RenderPresent(REN);
这个思路,显示一切正常
_______________________________________________________________
2。思路如下
SUR = IMG_Load(Bkg_Img);
生成表面
Bkg_Texture = SDL_CreateTextureFromSurface(REN, SUR);
创建纹理
SDL_QueryTexture(Bkg_Texture, NULL, NULL, &Bkg_Rect.w, &Bkg_Rect.h);
获取高宽
SDL_Surface *txtsur = TTF_RenderUTF8_Blended(Font, "测试用文字字符串!" , SDL_Color {220, 220, 220, 0});
生成文字表面
SDL_Rect rect;
矩形
SDL_GetClipRect(txtsur,&rect);
获取表面矩形
rect.w=Bkg_Rect.w;
约束矩形宽为背景宽
SDL_BlitSurface(txtsur,&rect,SUR,&rect);
贴合表面
SDL_FreeSurface(txtsur);
清除
SDL_UpdateTexture(Bkg_Texture,&rect,SUR->pixels ,SUR->pitch);
更新纹理
下边显示
SDL_FreeSurface(SUR);
SDL_RenderClear(REN);
SDL_RenderCopy(REN, Bkg_Texture, &Bkg_Rect, &Screen_Rect);
SDL_RenderPresent(REN);
这个思路,显示不正常,贴合部分出现循环贴合效果!
理论上这两种方法应该结果是一样的,但是结果去出乎意料,调试很久了,没达预期!请高手指点下!
2016年10月29日 09点10分
1
1。思路如下
SUR = IMG_Load(Bkg_Img);
生成表面
Bkg_Texture = SDL_CreateTextureFromSurface(REN, SUR);
生成纹理
SDL_GetClipRect(SUR,&Bkg_Rect);
获取高宽
SDL_Surface *txtsur=TTF_RenderUTF8_Blended(Font,"测试用文字字符串!", SDL_Color {220, 220, 220, 0});
生成文字表面
SDL_BlitSurface(txtsur,NULL,SUR,NULL);
贴合表面
SDL_FreeSurface(txtsur);
清除
Bkg_Texture = SDL_CreateTextureFromSurface(REN, SUR);
生成纹理合并
下边显示
SDL_FreeSurface(SUR);
SDL_RenderClear(REN);
SDL_RenderCopy(REN, Bkg_Texture, &Bkg_Rect , &Screen_Rect);
SDL_RenderPresent(REN);
这个思路,显示一切正常
_______________________________________________________________
2。思路如下
SUR = IMG_Load(Bkg_Img);
生成表面
Bkg_Texture = SDL_CreateTextureFromSurface(REN, SUR);
创建纹理
SDL_QueryTexture(Bkg_Texture, NULL, NULL, &Bkg_Rect.w, &Bkg_Rect.h);
获取高宽
SDL_Surface *txtsur = TTF_RenderUTF8_Blended(Font, "测试用文字字符串!" , SDL_Color {220, 220, 220, 0});
生成文字表面
SDL_Rect rect;
矩形
SDL_GetClipRect(txtsur,&rect);
获取表面矩形
rect.w=Bkg_Rect.w;
约束矩形宽为背景宽
SDL_BlitSurface(txtsur,&rect,SUR,&rect);
贴合表面
SDL_FreeSurface(txtsur);
清除
SDL_UpdateTexture(Bkg_Texture,&rect,SUR->pixels ,SUR->pitch);
更新纹理
下边显示
SDL_FreeSurface(SUR);
SDL_RenderClear(REN);
SDL_RenderCopy(REN, Bkg_Texture, &Bkg_Rect, &Screen_Rect);
SDL_RenderPresent(REN);
这个思路,显示不正常,贴合部分出现循环贴合效果!
理论上这两种方法应该结果是一样的,但是结果去出乎意料,调试很久了,没达预期!请高手指点下!
