Re: FAO Andy P, SDL2 library.

new topic     » goto parent     » topic index » view thread      » older message » newer message
ChrisB said...

Hi Andy.

Playing with your SDL2 library now, got it working with Phix, apart from font colouring which I am tearing my hair out at.

See the FontTest.exw, I have fiddled, so the line numbers may not be exact, lines 39 40

atom h = TTF_RenderText_Solid(f,"Hello World",255,0,0,100)  --<--colour set here to red, alpha 100 
atom ht = SDL_CreateTextureFromSurface(ren,h) 
atom h = TTF_RenderText_Solid(f,"Hello World",0,255,0,100)  --<--colour set here to green, alpha 100 
                                                            --but this doesn't work, text now black. 
                                                            --in fact setting the red channel to anything, only shows the  
                                                            --strength of that red 
atom ht = SDL_CreateTextureFromSurface(ren,h) 

I've done lots of reading of the SDL2 docs, the SDL2TTF docs, and I can't see what I'm missing. I've also tried setTextureColorMod to change the color chanels of ht, but again only the red channel was modified.

Any ideas?

I think the root problem here may be that SDL2 passes structs by value and not by pointer. TTF_RenderText_Solid expects an SDL_Color struct which is four UInt8 (or C_UCHAR in std/dll.e) values but Andy's wrapper is just passing them as four separate C_UINT values: But we should be able to pack the four values into a single unsigned int and pass it that way instead. (Also the fourth value should be "a" for alpha, not "u"). I haven't tested this but I can at least confirm that sizeof(SDL_Color) is 4 which means the values are indeed each a single byte. Give this a shot and see how it goes:

public constant xTTF_RenderText_Solid = define_c_func(ttf,"+TTF_RenderText_Solid",{C_POINTER,C_POINTER,C_UINT},C_POINTER) 
--SDLColor is a struct of four UInt8 values, so pack them into a single unsigned int. 
public function TTF_RenderText_Solid(atom font,sequence text,atom r,atom g,atom b,atom a) 
 atom str = allocate_string(text,1) 
 atom color = bytes_to_int({r,g,b,a}) 
 return c_func(xTTF_RenderText_Solid,{font,str,color}) 
end function 


new topic     » goto parent     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu