diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index ffd2a052..a2428592 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -22,8 +22,8 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height); void Backend_FreeSurface(Backend_Surface *surface); BOOL Backend_IsSurfaceLost(Backend_Surface *surface); void Backend_RestoreSurface(Backend_Surface *surface); -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch); -void Backend_UnlockSurface(Backend_Surface *surface); +unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height); +void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height); void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key); void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue); BOOL Backend_SupportsSubpixelGlyphs(void); diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 16abe92f..ec010ee5 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -474,17 +474,17 @@ void Backend_RestoreSurface(Backend_Surface *surface) (void)surface; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) +unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { if (surface == NULL) return NULL; - surface->pixels = (unsigned char*)malloc(surface->width * surface->height * 3); - *pitch = surface->width * 3; + surface->pixels = (unsigned char*)malloc(width * height * 3); + *pitch = width * 3; return surface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface) +void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) { if (surface == NULL) return; @@ -493,7 +493,7 @@ void Backend_UnlockSurface(Backend_Surface *surface) glGetIntegerv(GL_TEXTURE_BINDING_2D, &previously_bound_texture); glBindTexture(GL_TEXTURE_2D, surface->texture_id); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surface->width, surface->height, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); free(surface->pixels); glBindTexture(GL_TEXTURE_2D, previously_bound_texture); diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index b12ff349..b603b0ec 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -105,7 +105,7 @@ void Backend_RestoreSurface(Backend_Surface *surface) (void)surface; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) +unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { if (surface == NULL) return NULL; @@ -114,7 +114,7 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch return (unsigned char*)surface->sdlsurface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface) +void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) { (void)surface; } diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 05ae0eca..32f62e89 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -147,32 +147,32 @@ void Backend_RestoreSurface(Backend_Surface *surface) surface->lost = FALSE; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) +unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { if (surface == NULL) return NULL; - *pitch = surface->width * 3; + *pitch = width * 3; - surface->pixels = (unsigned char*)calloc(surface->width * surface->height * 3, 1); // Make sure these are initialized + surface->pixels = (unsigned char*)malloc(width * height * 3); return surface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface) +void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) { if (surface == NULL) return; - unsigned char *buffer = (unsigned char*)malloc(surface->width * surface->height * 4); - unsigned char *buffer_pointer = buffer; + unsigned char *buffer = (unsigned char*)malloc(width * height * 4); const unsigned char *src_pixel = surface->pixels; // Convert the SDL_Surface's colour-keyed pixels to RGBA32 - for (unsigned int y = 0; y < surface->height; ++y) + for (unsigned int y = 0; y < height; ++y) { + unsigned char *buffer_pointer = &buffer[y * width * 4]; - for (unsigned int x = 0; x < surface->width; ++x) + for (unsigned int x = 0; x < width; ++x) { *buffer_pointer++ = src_pixel[0]; *buffer_pointer++ = src_pixel[1]; @@ -189,7 +189,8 @@ void Backend_UnlockSurface(Backend_Surface *surface) free(surface->pixels); - SDL_UpdateTexture(surface->texture, NULL, buffer, surface->width * 4); + SDL_Rect rect = {0, 0, width, height}; + SDL_UpdateTexture(surface->texture, &rect, buffer, width * 4); free(buffer); } diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 6a51907d..f916cb1f 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -112,8 +112,11 @@ void Backend_RestoreSurface(Backend_Surface *surface) (void)surface; } -unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) +unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height) { + (void)width; + (void)height; + if (surface == NULL) return NULL; @@ -121,9 +124,11 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch return surface->pixels; } -void Backend_UnlockSurface(Backend_Surface *surface) +void Backend_UnlockSurface(Backend_Surface *surface, unsigned int width, unsigned int height) { (void)surface; + (void)width; + (void)height; } void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key) diff --git a/src/Draw.cpp b/src/Draw.cpp index 3a689262..687c89d1 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -165,7 +165,7 @@ static BOOL ScaleAndUploadSurface(SDL_Surface *surface, SurfaceID surf_no) // IF YOU WANT TO ADD HD SPRITES, THIS IS THE CODE YOU SHOULD EDIT unsigned int pitch; - unsigned char *pixels = Backend_LockSurface(surf[surf_no], &pitch); + unsigned char *pixels = Backend_LockSurface(surf[surf_no], &pitch, converted_surface->w * magnification, converted_surface->h * magnification); if (magnification == 1) { @@ -206,7 +206,7 @@ static BOOL ScaleAndUploadSurface(SDL_Surface *surface, SurfaceID surf_no) } } - Backend_UnlockSurface(surf[surf_no]); + Backend_UnlockSurface(surf[surf_no], converted_surface->w * magnification, converted_surface->h * magnification); SDL_FreeSurface(converted_surface); return TRUE;