创建纹理时,确保纹理与渲染器的像素格式兼容。可以使用SDL_QueryTexture函数获取纹理的实际像素格式。 SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC,640,480); // 查询纹理的实际像素格式 Uint32 format; SDL_QueryTexture(texture, &format,NULL,NULL,NULL)...
(); // 计算合适的宽度和高度 int texWidth = 0; int texHeight = 0; uint format = 0; int access = 0; // 下面这行代码解决字体虚浮不清问题 SDL.SDL_QueryTexture(texture, out format, out access, out texWidth, out texHeight); //设置纹理的数据 SDL.SDL_Rect destrect; destrect.x = 0...
SDL_FreeSurface(loadedImage); } else { std::cout << SDL_GetError() << std::endl; } return texture; } void ApplySurface(int x, int y, SDL_Texture *texture, SDL_Renderer *render) { SDL_Rect pos; pos.x = x; pos.y = y; SDL_QueryTexture(texture, nullptr, nullptr, &pos.w, &...
SDL_QueryTexture(Draw_Texture, NULL, NULL, &w, &h);Draw_Render_Rect.w = w;Draw_Render_Rect.h = h;// 本部分函数可变性极强。// 有兴趣的同学可以自行更改SDL_RenderCopy(Draw_Render, Draw_Texture, NULL, &Draw_Render_Rect);}int DestroyAll(){// 释放SDL_DestroyTexture(fonts);SDL_Destroy...
SDL_QueryTexture(texture,NULL,NULL,&w,&h); SDL_Delay(20); horizontalFormer.x++; if(horizontalFormer.x > 639){ horizontalFormer.x = -639; } horizontalLatter.x++; if(horizontalLatter.x > 639){ horizontalFormer.x = -639; } verticalFormer.y++; ...
SDL_QueryTexture(t, NULL, NULL, &tr.w, &tr.h);if(x==-1)tr.x = (w - tr.w) / 2;elsetr.x=x;if(y==-1)tr.y = (h - tr.h) / 2;elsetr.y=y;SDL_RenderCopy(ren, t, NULL, &tr);SDL_DestroyTexture(t);}//显示文字到屏幕中间(在渲染过程中使用会闪屏)void showText(SDL_...
SDL_FreeSurface(pTempSurface); SDL_QueryTexture(m_pTexture,NULL,NULL,&m_sourceRectangle.w,&m_sourceRectangle.h); m_sourceRectangle.w=128; m_sourceRectangle.h=82; voidGame::update() { m_sourceRectangle.x = 128 *int(((SDL_GetTicks()/100)%6)); ...
void apply_surface(int x, int y, SDL_Texture *texture, SDL_Renderer *render, SDL_Rect *clip=NULL){SDL_Rect rect;rect.x=x;rect.y=y;SDL_QueryTexture(texture,NULL,NULL,&rect.w,&rect.h);SDL_RenderCopy(render,texture,clip,&rect);}bool Init(){if(SDL_Init(SDL_INIT_EVERYTHING)==-1)...
SDL_QueryTexture(tb1, NULL, NULL, &tbW, &tbH); SDL_QueryTexture(tb2, NULL, NULL, &tbW, &tbH); SDL_QueryTexture(tb3, NULL, NULL, &tbW, &tbH); SDL_QueryTexture(tb4, NULL, NULL, &tbW, &tbH); SDL_QueryTexture(tb5, NULL, NULL, &tbW, &tbH); SDL_QueryTexture(tb6, NULL, NULL,...
SDL_QueryTexture(pi, NULL, NULL, &pos.w, &pos.h); SDL_RenderCopy(p_Renderer, pi, NULL, &pos); SDL_RenderPresent(p_Renderer); //重新渲染 }//看着个括号到哪 SDL_DestroyWindow(p_Window); SDL_DestroyRenderer(p_Renderer); SDL_DestroyTexture(img); ...