SDL, what am I doing wrong?
-
This is my code for a basic game loop, for now I just wanna draw a rectangle. Now I could cheat and use the examples that use the SDL extensions this particular python package gives me but I wanna learn how to do it probably.
I've basically "Pythoned" the code from here "https://labs.deadbodyoutline.com/2014/05/28/starting-a-sdl2-game-build-system-and-main-loop".
But I dunno what to do next.
I am not a "games programmer" but I am playing around with porting some crap game I did at uni and I am just stuck here because the loop we used at uni wasn't efficient and it was using an older version of SDL that worked with Java (via bindings). Most of the code it pretty simple to translate.
I want to just display a white box and then implement some vector logic and clipping logic to get the basics down. After that I think I should be able to figure it out.
-
I don't know Python but the code here seems fine. To draw a rectangle, set the color with SDL_SetRenderDrawColor and then use SDL_RenderFillRect. Then before you clear the screen with SDL_RenderClear you have to call SDL_SetRenderDrawColor back to the background color. I advise you to read the excellent Lazy Foo SDL tutorials.
-
@magnusmaster I will give it a go. I've been reading most of the extension libs in python in the package I am using but it doesn't really help me. It is too abstracted.
-
Why is the answer before the question in the topic title? It would make more sense as:
What I'm doing wrong: SDL
-
@groo said in SDL, what am I doing wrong?:
Why is the answer before the question in the topic title? It would make more sense as:
What I'm doing wrong: SDL
Are you familiar with any better alternative?
-
Had a chance to have a proper look at this tonight.
In my main loop I need to have this before my SDL_RenderClear() method on line 69:
sdl2.SDL_SetRenderDrawColor(self.renderer, 0x00, 0x00, 0x00, 0x00) sdl2.SDL_RenderClear(self.renderer)
The draw method should look like:
def draw(self): fillRect = sdl2.SDL_Rect(200, 150, 400, 380) sdl2.SDL_SetRenderDrawColor(self.renderer, 0xFF, 0x00, 0x00, 0xFF) sdl2.SDL_RenderFillRect(self.renderer, fillRect)
-
@masonwheeler No, I would say that for any technology
-
Why is that doing
sdl2.SDL_RenderClear(self.render)
? Why isn't that just something more sensible likeself.render.clear()
?But there I go, arguing for a sensible API design. Silly old me.
-
@dkf It mimicks the C++ api. I it probably needs a reference to the renderer.
-
@lucas1 It's smelling to me a C-style API with objects that have behaviours, but where you get to do the organisation by hand. Lazy. Or rather it's probably a SWIGged API; SWIG is nice enough I guess, and I've used it on occasion, but it usually needs an extra layer of wrapping to get something good because natural APIs in different languages are simply arranged differently and it is hard for an automated tool to hide the differences.
-
@lucas1 said in SDL, what am I doing wrong?:
@dkf It mimicks the C++ api. I it probably needs a reference to the renderer.
It mimics the C API. No objects here.
@dkf said in SDL, what am I doing wrong?:
@lucas1 It's smelling to me a C-style API with objects that have behaviours, but where you get to do the organisation by hand.
Yeah, pretty much.
Source: I am a (minor) SDL contributor, and I've spent more time than I care to admit under the hood of the codebase.
-
@dkf They are swig style bindings library. I didn't want to cheat.
I could have just used monogame and c# but tbh I wouldn't have learnt anything. I need to learn python properly and I don't want to be a web dev forever (I've had enough, most of the guys and gals I have to work with are bloody idiots).
They have some sdl extensions that makes things easier, but I want to know what was going on in those helper methods.
-
@lucas1 said in SDL, what am I doing wrong?:
They are swig style bindings library. I didn't want to cheat.
Fair enough, but if you don't want to go crazy, you'll probably want to wrap the code in some classes. You're writing Python, not C. ;) Doing such a wrapping isn't wrong either; it's just dealing with the fact that languages' idioms really do vary.
-
@lucas1 said in SDL, what am I doing wrong?:
I don't want to be a web dev forever (I've had enough, most of the guys and gals I have to work with are bloody idiots).
choose catefully, or like me you'll meet worse levels of wtfs. at least I'm damn hard to replace
-
@dkf once I know how it all should fit together I will probably abstract stuff nicely into something more elegant.