Plans on building a 2D level editor with SDL & WXWidgets - which one handles the window?

Started by
7 comments, last by Aldacron 10 years, 7 months ago

Hi all,

As the title suggests, I plan on making a pretty simple 2D level editor with SDL for rendering and wxWidgets for the GUI.

I've used SDL before, but I haven't used wxWidgets.

The biggest question to me is which library should handle the window? I imagine that I should let wxWidgets handle the window and let SDL render inside - would this be too complicated?

I'm open to any alternative suggestions.

Thanks!

Advertisement

My alternative suggestion is not to build a level editor *at all*.

You didn't say what kind of level editor it needs to be - tilemap, vector etc, but there are plenty of existing editors which do most of what you need with much less coding.

Instead maybe you need to write conversion tools to convert from a different format.

For object-placement, or other tricky stuff, it might be better to build the editor into your game:

* An editor built into the game requires less code than implementing some fancy UI

* You can see how the layout looks using the in-game view, as you go.

For tilemaps, you can use: Text editors, Bitmap graphics editors (e.g. gimp), standard tilemap editors.

For vectors you can use: 2d vectors such as Flash, Inkscape etc, 3d vectors such as Blender or whatever-tool-you-want.

For things like colour-mapping, you can use a bitmap graphics editor.

For things like game logic, e.g. triggers, wiring logic up to make doors open when the button is pressed, monster stats, you might need a custom editor. Build it into your game if possible, or use an existing editor.

For such a simple thing as a 2d tilemap I wouldnt bother with writing an editor, too.

You just start LibreOffice Calc or Excel, write id numbers into a table, save as csv.

Then you maybe create a simple converter command line program to translate it into some binary format.

Then read it into your game and verify its right.

WxWidgets will do the windows and controls. SDL could be used for blitting, and then transfer the SDL buffer to your map window.

I almost used WxWidgets for my map editor, but ended up going with FLTK because it makes a small standalone .exe rather than needing a monster .dll somewhere (annoying when you want to share it). But basically the same functionality, just a little less fancy.

And in my game engine, I do all graphics in software, and only use SDL to dump the completed image to the screen. Same code works in the editor, except I dump it to the map window. No SDL necessary.

As others have said, writing an editor is a lot of work and possibly not necessary. Mine is 16K lines of code, but I don't regret writing it. Really nice being able to quickly add anything I need, rather than having my game designs influenced by what my editor can do. It's a little over the top fancy, so you could certainly make something useful with a lot less effort. But definitely not trivial.

IMO, the primary purpose of the editor is to place entities on the map, and input any data pertaining to them (e.g. destination map and spawn point for a door, or what dialog to display when talking to an NPC). Second purpose is to define collision data. Third is the actual tilemap editing.

I'm fully aware that there are plenty of editors - I'd just like to write a really simple one myself.

@DekuTree64, could you explain more about transferring the SDL buffer to a map window?

If you decide wxWidgets isn't to your taste, I find Qt more in line with my own liking.

On the flip side, Qt isn't a small library by any means... it's a huge collection of libraries that covers quite alot more than just GUI widgets.

In answer to your question - I think wxWidgets is supposed to manage the window IIRC, and SDL render to it. Same with Qt.

I'm fully aware that there are plenty of editors - I'd just like to write a really simple one myself.

@DekuTree64, could you explain more about transferring the SDL buffer to a map window?

I've never actually used SDL this way, or used WxWidgets for more than a day of learning to see how I liked it, so I'm half guessing here. But I think you'd initialize SDL video to render to a software surface. Then each frame after you're done rendering everything, lock the surface, and copy the pixel data over to your WxWidgets window. Not sure exactly how the copying would be done. Quick check of the documentation, it doesn't look like it will be very straightforward. Possibly a combination of wxGraphicsContext and wxBitmap (copy the SDL surface pixels to the bitmap, then draw the bitmap to the window)

One more point in favor of FLTK. Just call fl_draw_image, give it the SDL surface's pixel pointer, and bam, done :) There may be something similar in WxWidgets that I didn't find, though. Perhaps someone more experienced with it will come along and enlighten us.

I guess you can use only SDL for the whole editor. Maybe using a GUI library like SDL-widgets...

Still, as posted before, there's also the possibility of using programs like Tiled and write a simple addon to configure it for your desired output format.

In SDL 2.0, you can create your render window in wxWidgets, get the native window handle, then pass it to SDL_CreateWindowFrom. Beyond that, I'm not clear on all the details. I know you should be able to use the Surface API for drawing, but for the accelerated API using SDL_Renderer I can only guess.

Most definitely you'll need to make sure a proper rendering context is set up on the window. I assume wxWidgets provides a means to create an OpenGL context (and it has to be a compatibility profile, not core), so that will need to be done before passing the window handle to SDL. Then when creating the renderer you'll need to explicitly request the OpenGL renderer. Similar for using D3D, if wxWidgets enables that.

Then there's events. I think it's safe to assume that you will handle events on the wxWidgets side, but I have no idea if SDL tries to hook into the event proc of windows it didn't create.

At any rate, it may be a lot simpler than I make it appear here. It's probably a good idea to ask in the SDL forum for the details if you decide to go that route.

This topic is closed to new replies.

Advertisement