mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-02-19 01:48:21 +00:00
SDL_RenderTexture() and SDL_RenderTextureRotated() take floating point source coordinates
See the discussion at https://discourse.libsdl.org/t/sdl-rendercopyf-uses-ints/36732/8
This commit is contained in:
@@ -330,8 +330,8 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_FRect *ds
|
||||
{
|
||||
SDL_Texture *texture;
|
||||
const Uint32 textureID = codepoint / UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
SDL_Rect srcrect;
|
||||
srcrect.w = srcrect.h = 16;
|
||||
SDL_FRect srcrect;
|
||||
srcrect.w = srcrect.h = 16.0f;
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT) {
|
||||
return 0;
|
||||
}
|
||||
@@ -343,8 +343,8 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_FRect *ds
|
||||
texture = unifontTexture[UNIFONT_NUM_TEXTURES * rendererID + textureID];
|
||||
if (texture != NULL) {
|
||||
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
srcrect.x = cInTex % UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
srcrect.y = cInTex / UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
srcrect.x = (float)(cInTex % UNIFONT_GLYPHS_IN_ROW * 16);
|
||||
srcrect.y = (float)(cInTex / UNIFONT_GLYPHS_IN_ROW * 16);
|
||||
SDL_RenderTexture(state->renderers[rendererID], texture, &srcrect, dst);
|
||||
}
|
||||
return unifontGlyph[codepoint].width;
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef struct LoadedPicture
|
||||
const char *name;
|
||||
} LoadedPicture;
|
||||
|
||||
void render(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect texture_dimensions)
|
||||
void render(SDL_Renderer *renderer, SDL_Texture *texture, SDL_FRect texture_dimensions)
|
||||
{
|
||||
SDL_FRect dst;
|
||||
|
||||
@@ -35,10 +35,10 @@ void render(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect texture_dimen
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Render the texture. */
|
||||
dst.x = (float)texture_dimensions.x;
|
||||
dst.y = (float)texture_dimensions.y;
|
||||
dst.w = (float)texture_dimensions.w;
|
||||
dst.h = (float)texture_dimensions.h;
|
||||
dst.x = texture_dimensions.x;
|
||||
dst.y = texture_dimensions.y;
|
||||
dst.w = texture_dimensions.w;
|
||||
dst.h = texture_dimensions.h;
|
||||
SDL_RenderTexture(renderer, texture, &texture_dimensions, &dst);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
@@ -58,8 +58,8 @@ int main(int argc, char **argv)
|
||||
unsigned int current_picture;
|
||||
int button_down;
|
||||
Uint32 pixelFormat = 0;
|
||||
int access = 0;
|
||||
SDL_Rect texture_dimensions;
|
||||
int w, h, access = 0;
|
||||
SDL_FRect texture_dimensions;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
@@ -158,13 +158,13 @@ int main(int argc, char **argv)
|
||||
should_exit = 0;
|
||||
current_picture = 0;
|
||||
button_down = 0;
|
||||
texture_dimensions.h = 0;
|
||||
texture_dimensions.w = 0;
|
||||
texture_dimensions.x = 0;
|
||||
texture_dimensions.y = 0;
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &texture_dimensions.w, &texture_dimensions.h);
|
||||
SDL_SetWindowSize(window, texture_dimensions.w, texture_dimensions.h);
|
||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
|
||||
texture_dimensions.x = 0.0f;
|
||||
texture_dimensions.y = 0.0f;
|
||||
texture_dimensions.h = (float)w;
|
||||
texture_dimensions.w = (float)h;
|
||||
SDL_SetWindowSize(window, w, h);
|
||||
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
||||
while (should_exit == 0) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
@@ -182,8 +182,10 @@ int main(int argc, char **argv)
|
||||
current_picture = 0;
|
||||
}
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &texture_dimensions.w, &texture_dimensions.h);
|
||||
SDL_SetWindowSize(window, texture_dimensions.w, texture_dimensions.h);
|
||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
|
||||
texture_dimensions.h = (float)w;
|
||||
texture_dimensions.w = (float)h;
|
||||
SDL_SetWindowSize(window, w, h);
|
||||
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
||||
}
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
|
||||
Reference in New Issue
Block a user