爲了使按鈕,創建和渲染紋理方式:SDL 2.0放大質地
typedef struct{
SDL_Rect pos;
SDL_Texture* texture;
int hovered;
} button;
button getButton(int x, int y, char * label, TTF_Font* font, SDL_Color color){
button btn;
btn.hovered = false;
btn.pos.x = x;
btn.pos.y = y;
SDL_Surface* surface = TTF_RenderText_Solid(font, label, color);
btn.pos.w = surface->w;
btn.pos.h = surface->h;
btn.texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
return btn;
}
void drawButton(button btn){
SDL_RenderCopyEx(renderer, btn.texture, NULL, &btn.pos, 0, NULL, SDL_FLIP_NONE);
if(btn.hovered){
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0x00);
SDL_RenderDrawRect(renderer, &btn.pos);
}
的問題是,我得到的紋理,其大小等於標籤之一。我怎樣才能增加紋理像素的大小而不拉伸它即在它的側面添加空白空間?
到目前爲止您嘗試過了什麼?哪個版本的SDL?渲染按鈕的代碼在哪裏? –
@ E_net4編輯的問題來表示渲染和版本。的SDL。沒有真正嘗試過任何東西,因爲不能提出任何想法 – osamurai