X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela_draw.lisp;h=93575a36b578178f578e4ab5ab6d425d7f875ed1;hb=4f2a527eb9aec9616363c098bc9974db1b5cf3b8;hp=a3a19c74bb7b7aa0d62c6d81ef68778a72fb2894;hpb=00abf12486704814b6aa12d8b162135df6637141;p=gacela.git diff --git a/gacela_draw.lisp b/gacela_draw.lisp index a3a19c7..93575a3 100644 --- a/gacela_draw.lisp +++ b/gacela_draw.lisp @@ -71,13 +71,25 @@ (cond ((/= image 0) (let* ((width (surface-w image)) (height (surface-h image)) (power-2 (nearest-power-of-two (min width height))) - (zoomx (/ power-2 width)) (zoomy (/ power-2 height)) zoomed-image) - (cond ((and (= zoomx 1) (= zoomy 1)) (values image width height)) - (t (setq zoomed-image (zoomSurface image zoomx zoomy 0)) + (cond ((and (= width power-2) (= height power-2)) (values image width height)) + (t (setq zoomed-image (resize-image image power-2 power-2)) (SDL_FreeSurface image) (cond ((/= zoomed-image 0) (values zoomed-image width height)))))))))) +(defun resize-image (image width height) + (let ((old-width (surface-w image)) (old-height (surface-h image))) + (cond ((and (= width old-width) (= height old-height)) image) + (t (let ((zoomx (/ width old-width)) (zoomy (/ height old-height)) zoomed-image) + (setq zoomed-image (zoomSurface image zoomx zoomy 0)) + (let ((new-width (surface-w zoomed-image)) (new-height (surface-h zoomed-image))) + (cond ((or (and (= width new-width) (= height new-height)) + (and (= old-width new-width) (= old-height new-height))) zoomed-image) + (t (let (rezoomed) + (setq rezoomed (resize-image zoomed-image width height)) + (SDL_FreeSurface zoomed-image) + rezoomed))))))))) + (defun load-texture (filename &key (min-filter GL_LINEAR) (mag-filter GL_LINEAR) static) (let ((key (make-resource-texture :filename filename :min-filter min-filter :mag-filter mag-filter))) (cond ((get-resource key) key) @@ -91,9 +103,10 @@ (cond (image (let ((width (surface-w image)) (height (surface-h image)) (byteorder (if (= (SDL_ByteOrder) SDL_LIL_ENDIAN) - (if (= (surface-format-BytesPerPixel image) 3) GL_RGB GL_RGBA) - (if (= (surface-format-BytesPerPixel image) 3) GL_BGR GL_BGRA))) + (if (= (surface-format-BytesPerPixel image) 3) GL_BGR GL_BGRA) + (if (= (surface-format-BytesPerPixel image) 3) GL_RGB GL_RGBA))) (texture (car (glGenTextures 1)))) + (glBindTexture GL_TEXTURE_2D texture) (glTexImage2D GL_TEXTURE_2D 0 3 width height 0 byteorder GL_UNSIGNED_BYTE (surface-pixels image)) (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER min-filter)