Reputation: 8356
I'm learning Racket by writing an SDL application but I don't know how to initialize a rectangle structure. It's defined in racket-sdl as follows:
(define-cstruct _SDL_Rect
([x _int]
[y _int]
[w _int]
[h _int]))
How do I create an instance of a rectangle? Specifically, I want to create a rectangle to pass into the following function as the last parameter:
(SDL_BlitSurface hello-world-surface #f screen-surface #f)
Upvotes: 2
Views: 751
Reputation: 1884
First of all, if you are just starting out with Racket, I would recommend to use some of the packaged libraries for drawing, such as the GUI library's canvas or the OpenGL library.
The racket-sdl project, with only 3 commits (the last one being 2 years old), seems to me as no more than a feasibility test.
Still, your question is valid, so let's give you an answer. (define-cstruct ...)
defines a C struct
essentially as a pointer, so you have no obvious means to change its internals. You can create a small wrapper library in C with a function make_SDL_Rect
, and use that, but it isn't worth the hassle. It would be better to define the SDL_Rect
type using make-cstruct-type
, which allows for the conversion of parameters.
See more info at the FFI manual.
Upvotes: 4