# HG changeset patch # User Michael Pavone # Date 1427647404 25200 # Node ID 577406b25f899b7ad19017027fd54b03bb9ca2de # Parent ead24192ed4588d38023b58a083710fa58ec31b8 Added binding for SDL_SetTextureColorMod and SDL_GetTextureColorMod and updated the Freetype sample to use it for setting the color of text diff -r ead24192ed45 -r 577406b25f89 modules/sdl.tp --- a/modules/sdl.tp Sat Mar 28 14:21:22 2015 -0700 +++ b/modules/sdl.tp Sun Mar 29 09:43:24 2015 -0700 @@ -589,10 +589,47 @@ llMessage: blendMode withVars: { mode <- obj_uint32 ptr } andCode: { - mode <-make_object: (addr_of: obj_uint32_meta) NULL 0 + mode <- make_object: (addr_of: obj_uint32_meta) NULL 0 SDL_GetTextureBlendMode: texture (addr_of: (mode num)) mode } + + llMessage: colorMod! withVars: { + color <- object ptr + tmp <- object ptr + r <- obj_uint8 ptr + g <- obj_uint8 ptr + b <- obj_uint8 ptr + intret <- obj_int32 ptr + } andCode: :color { + tmp <- mcall: r 1 color + r <- (mcall: uint8 1 tmp) castTo: (obj_uint8 ptr) + tmp <- mcall: g 1 color + g <- (mcall: uint8 1 tmp) castTo: (obj_uint8 ptr) + tmp <- mcall: b 1 color + b <- (mcall: uint8 1 tmp) castTo: (obj_uint8 ptr) + intret <- make_object: (addr_of: obj_int32_meta) NULL 0 + intret num!: (SDL_SetTextureColorMod: texture (r num) (g num) (b num)) + intret + } + + llMessage: colorMod withVars: { + color <- object ptr + r <- obj_uint8 ptr + g <- obj_uint8 ptr + b <- obj_uint8 ptr + rescode <- int32_t + } andCode: { + r <- make_object: (addr_of: obj_uint8_meta) NULL 0 + g <- make_object: (addr_of: obj_uint8_meta) NULL 0 + b <- make_object: (addr_of: obj_uint8_meta) NULL 0 + rescode <- SDL_GetTextureColorMod: texture (addr_of: (r num)) (addr_of: (g num)) (addr_of: (b num)) + if: rescode { + mcall: none 1 option + } else: { + mcall: value 2 option (mcall: r:g:b 4 sdl r g b) + } + } llMessage: destroy withVars: {} andCode: { SDL_DestroyTexture: texture diff -r ead24192ed45 -r 577406b25f89 samples/freetype.tp --- a/samples/freetype.tp Sat Mar 28 14:21:22 2015 -0700 +++ b/samples/freetype.tp Sun Mar 29 09:43:24 2015 -0700 @@ -186,11 +186,11 @@ //FIXME: This will probably only work on little endian machines bytearr set: dstIdx (pixels get: idx) dstIdx <- dstIdx + 1 - bytearr set: dstIdx (color r) + bytearr set: dstIdx 255u8 //(color r) dstIdx <- dstIdx + 1 - bytearr set: dstIdx (color g) + bytearr set: dstIdx 255u8 (color g) dstIdx <- dstIdx + 1 - bytearr set: dstIdx (color b) + bytearr set: dstIdx 255u8 (color b) dstIdx <- dstIdx + 1 idx <- idx + 1 @@ -227,11 +227,11 @@ //FIXME: This will probably only work on little endian machines bytearr set: dstIdx (pixels get: idx) dstIdx <- dstIdx + 1 - bytearr set: dstIdx (color r) + bytearr set: dstIdx 255u8 //(color r) dstIdx <- dstIdx + 1 - bytearr set: dstIdx (color g) + bytearr set: dstIdx 255u8 (color g) dstIdx <- dstIdx + 1 - bytearr set: dstIdx (color b) + bytearr set: dstIdx 255u8 (color b) dstIdx <- dstIdx + 1 idx <- idx + 1 @@ -260,6 +260,7 @@ foreach: glyphs :idx glyph { glyphDict set: (glyph charCode) glyph } + drawTex colorMod!: color _pixelFactor <- ((face unitsPerEm) f64) * 72.0 / (fontSize * (dpi f64)) option value: #{ texture <- drawTex