new accessors

db4
Doug Coleman 2008-08-29 16:42:12 -05:00
parent 9febce42e6
commit 8f84b4ba32
2 changed files with 16 additions and 16 deletions

View File

@ -1,5 +1,5 @@
USING: help.markup help.syntax io kernel math quotations
opengl.gl assocs vocabs.loader sequences ;
opengl.gl assocs vocabs.loader sequences accessors ;
IN: opengl
HELP: gl-color
@ -91,17 +91,17 @@ HELP: do-attribs
HELP: sprite
{ $class-description "A sprite is an OpenGL texture together with a display list which renders a textured quad. Sprites are used to draw text in the UI. Sprites have the following slots:"
{ $list
{ { $link sprite-dlist } " - an OpenGL display list ID" }
{ { $link sprite-texture } " - an OpenGL texture ID" }
{ { $link sprite-loc } " - top-left corner of the sprite" }
{ { $link sprite-dim } " - dimensions of the sprite" }
{ { $link sprite-dim2 } " - dimensions of the sprite, rounded up to the nearest powers of two" }
{ { $link dlist>> } " - an OpenGL display list ID" }
{ { $link texture>> } " - an OpenGL texture ID" }
{ { $link loc>> } " - top-left corner of the sprite" }
{ { $link dim>> } " - dimensions of the sprite" }
{ { $link dim2>> } " - dimensions of the sprite, rounded up to the nearest powers of two" }
}
} ;
HELP: gray-texture
{ $values { "sprite" sprite } { "pixmap" "an alien or byte array" } { "id" "an OpenGL texture ID" } }
{ $description "Creates a new OpenGL texture from a 1 byte per pixel image whose dimensions are equal to " { $link sprite-dim2 } "." } ;
{ $description "Creates a new OpenGL texture from a 1 byte per pixel image whose dimensions are equal to " { $snippet "dim2" } "." } ;
HELP: gen-dlist
{ $values { "id" integer } }

View File

@ -180,9 +180,9 @@ TUPLE: sprite loc dim dim2 dlist texture ;
: <sprite> ( loc dim dim2 -- sprite )
f f sprite boa ;
: sprite-size2 ( sprite -- w h ) sprite-dim2 first2 ;
: sprite-size2 ( sprite -- w h ) dim2>> first2 ;
: sprite-width ( sprite -- w ) sprite-dim first ;
: sprite-width ( sprite -- w ) dim>> first ;
: gray-texture ( sprite pixmap -- id )
gen-texture [
@ -223,10 +223,10 @@ PRIVATE>
dup top-left dup top-right dup bottom-right bottom-left ;
: draw-sprite ( sprite -- )
dup sprite-loc gl-translate
GL_TEXTURE_2D over sprite-texture glBindTexture
dup loc>> gl-translate
GL_TEXTURE_2D over texture>> glBindTexture
init-texture
GL_QUADS [ sprite-dim2 four-sides ] do-state
GL_QUADS [ dim2>> four-sides ] do-state
GL_TEXTURE_2D 0 glBindTexture ;
: rect-vertices ( lower-left upper-right -- )
@ -243,14 +243,14 @@ PRIVATE>
] do-matrix ;
: init-sprite ( texture sprite -- )
[ set-sprite-texture ] keep
[ make-sprite-dlist ] keep set-sprite-dlist ;
swap >>texture
dup make-sprite-dlist >>dlist drop ;
: delete-dlist ( id -- ) 1 glDeleteLists ;
: free-sprite ( sprite -- )
dup sprite-dlist delete-dlist
sprite-texture delete-texture ;
[ dlist>> delete-dlist ]
[ texture>> delete-texture ] bi ;
: free-sprites ( sprites -- )
[ nip [ free-sprite ] when* ] assoc-each ;