Gabriel Pariat
3 years ago
8 changed files with 69 additions and 16 deletions
@ -1,11 +1,14 @@
@@ -1,11 +1,14 @@
|
||||
#version 330 core |
||||
layout (location = 0) in vec3 aPos; |
||||
layout (location = 1) in vec3 aColor; |
||||
layout (location = 2) in vec2 aTexCoord; |
||||
|
||||
out vec3 ourColor; |
||||
out vec2 TexCoord; |
||||
|
||||
void main() |
||||
{ |
||||
gl_Position = vec4(aPos, 1.0); |
||||
ourColor = aColor; |
||||
} |
||||
TexCoord = aTexCoord; |
||||
} |
||||
|
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
(defpackage #:texture |
||||
(:shadow #:load) |
||||
(:use #:cl) |
||||
(:export #:load #:bind)) |
||||
|
||||
(in-package :texture) |
||||
|
||||
(defclass texture () |
||||
((id :accessor texture-id :initarg :id))) |
||||
|
||||
(defun load (png-image-path) |
||||
(let* ((texture (gl:gen-texture)) |
||||
(image (png-read:read-png-file png-image-path)) |
||||
(image-data (png-read:image-data image)) |
||||
(image-dimensions (array-dimensions image-data)) |
||||
(data (loop for w below (first image-dimensions) |
||||
nconc (loop for h below (second image-dimensions) |
||||
nconc (loop for c below (third image-dimensions) |
||||
collect (aref image-data w h c))))) |
||||
(format (case (png-read:colour-type image) |
||||
(:truecolor-alpha :rgba) |
||||
(:truecolor :rgb)))) |
||||
(gl:bind-texture :texture-2d texture) |
||||
(gl:tex-parameter :texture-2d :texture-wrap-s :repeat) |
||||
(gl:tex-parameter :texture-2d :texture-wrap-t :repeat) |
||||
(gl:tex-parameter :texture-2d :texture-min-filter :linear) |
||||
(gl:tex-parameter :texture-2d :texture-mag-filter :linear) |
||||
(gl:tex-image-2d :texture-2d |
||||
0 |
||||
:rgba |
||||
(png-read:width image) |
||||
(png-read:height image) |
||||
0 |
||||
format |
||||
:unsigned-byte |
||||
(coerce data 'vector)) |
||||
(gl:generate-mipmap :texture-2d) |
||||
(make-instance 'texture :id texture))) |
||||
|
||||
(defmethod bind ((self texture)) |
||||
(gl:bind-texture :texture-2d (texture-id self))) |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 252 KiB |
After Width: | Height: | Size: 571 KiB |
Loading…
Reference in new issue