SDL2: how to assign values to SDL_Color structure?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
Case
Posts: 2
Joined: Dec 09, 2017 22:10

SDL2: how to assign values to SDL_Color structure?

Post by Case »

I'm trying to understand how to use SDL2 from FreeBasic (I'm new to FB). I'm trying to follow this C tutorial for displaying some text using a TTF font opened with SDL_ttf, but I have no idea how to assign values to a SDL_COLOR structure?

The C version looks like this:

Code: Select all

SDL_Color color = { 255, 255, 255 };
How do I do that with FB? I declare the variable using 'dim shared fontColor as SDL_COLOR', but how do I assign values to it?
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: SDL2: how to assign values to SDL_Color structure?

Post by paul doe »

You can define the following:

Code: Select all

#define SDL_rgb( r, g, b )	type<SDL_Color>( r, g, b )
Then, you can call the function(s) that expects a color like this:

Code: Select all

var surfaceHello = TTF_RenderText_Solid( font, TEXT, SDL_rgb( 255, 0, 0 ) )
Post Reply