X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela_draw.lisp;h=5e93e77b18b55906213707ec73101c4817a60dc4;hb=485e401435dd0c9d443299cb04b1576e0f15f43f;hp=3149f4d89cb1ae5013a650fa296b293cbf4f519f;hpb=0e67e98bfd1eedf78f3e9c27a6d9726f225deac1;p=gacela.git diff --git a/gacela_draw.lisp b/gacela_draw.lisp index 3149f4d..5e93e77 100644 --- a/gacela_draw.lisp +++ b/gacela_draw.lisp @@ -42,15 +42,23 @@ (defun load-texture (filename &optional (min-filter GL_LINEAR) (mag-filter GL_LINEAR)) (init-textures) (init-video-mode) - (let ((image (IMG_Load filename)) - (texture (car (glGenTextures 1)))) + (let ((image (IMG_Load filename))) (cond ((/= image 0) - (glBindTexture GL_TEXTURE_2D texture) - (glTexImage2D GL_TEXTURE_2D 0 3 (surface-w image) (surface-h image) 0 GL_BGR GL_UNSIGNED_BYTE (surface-pixels image)) - (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER min-filter) - (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER mag-filter) - (SDL_FreeSurface image))) - texture)) + (let ((width (surface-w image)) (height (surface-h image)) + (texture (car (glGenTextures 1)))) + (glBindTexture GL_TEXTURE_2D texture) + (glTexImage2D GL_TEXTURE_2D 0 3 width height 0 GL_RGB GL_UNSIGNED_BYTE (surface-pixels image)) + (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER min-filter) + (glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER mag-filter) + (SDL_FreeSurface image) + (values texture width height)))))) + +(defun draw-image-function (filename) + (multiple-value-bind + (texture width height) (load-texture filename) + (cond (texture + (lambda (&optional (f 0.0172)) + (draw-rectangle (* f width) (* f height) :texture texture)))))) (defun draw-quad (v1 v2 v3 v4 &key texture color) (cond (texture (glBindTexture GL_TEXTURE_2D texture) @@ -63,9 +71,12 @@ (t (cond (color (draw-color color))) (draw v1 v2 v3 v4)))) -(defun draw-square (&key size texture color) - (let ((-size (neg size))) - (draw-quad (list -size size 0) (list size size 0) (list size -size 0) (list -size -size 0) :texture texture :color color))) +(defun draw-rectangle (width height &key texture color) + (let* ((w (/ width 2)) (-w (neg w)) (h (/ height 2)) (-h (neg h))) + (draw-quad (list -w h 0) (list w h 0) (list w -h 0) (list -w -h 0) :texture texture :color color))) + +(defun draw-square (&key (size 1) texture color) + (draw-rectangle size size :texture texture :color color)) (defun draw-cube (&key size texture color) (let ((-size (neg size)))