Jump to content
  • Advertisement
Sign in to follow this  
shadowayex

Multi-platform game programming with wxWidgets

This topic is 2601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm developing a small game at the moment, and I'm using wxWidgets and it's abundance of features. The basis of the code I've written is pretty simple. I have the core GUI, some abstract classes for game graphics, and then two branches of sorts. I have it set up so I can develop both 2D and 3D classes that implement certain functions (based on the abstract classes). The core GUI uses and interacts with these classes seeing them only as the abstract ones. For example, I have a MapPanel that draws the current Map and all of the Players on the Map. But, I have Player2D and Map2D classes (and *3D classes) that are created and stored in the Map and Player references (the ones chosen are based on a #define who's value I set to 2 or 3).

Anyway, I've developed the code in Ubuntu 10.04 using Code::Blocks 8.02. The "rendering loop" is set up via a wxTimer set to launch a function every 10 milliseconds. In Ubuntu, this runs great. I took the code onto a Windows Vista Ultimate installation with Code::Blocks 10.05 and (after some work) compiled it, and the results weren't so pretty. The graphics were flickery and one of my objects (a little image that was to be moved around via the arrow keys) wasn't even being drawn (that I could see).

I chopped this problem up to one of three problems (although it could still be something else I didn't think of):

1) The difference in IDEs and/or compilers could have created issues. I sort of casted this one aside, because I figured since I was using wxWidgets and standard C++ code, that shouldn't be a big deal.

2) A general design flaw in my code. This one is very plausible, as I'm not too experienced in game programming.

3) wxWidgets itself not being a good toolkit to develop a game in.

I'm looking to confirm or invalidate number 3 before I get too into whether or not my design is flawed. I read somewhere that wxWidgets is not well suited for high end game rendering loops, but the features and portability of it is just too enticing to just let it go without consulting some knowledgeable people, first.

Share this post


Link to post
Share on other sites
Advertisement
If you are using wxDC to paint, did you try wxAutoBufferedPaintDC, or any similar thing for "double buffer" paint?
I used wxAutoBufferedPaintDC to avoid flicker quite well.

If you are using OpenGL, I can see no reason for flicker, because wxGLCanvas has supported double buffer? I didn't try any OpenGL in wxWidgets though.

What type of game are you making? A simple "application like" (i.e, use common GUI to draw, use GUI controls) or a "real game like" (i.e, use OpenGL to draw all things except some simple GUI such as menus)?

For your third question, in any way, wxWidgets should not be "not good" for you.
If you are making "application like" game, wxWidgets is good for making GUI applications, if you are making a "real game like", you don't get too much good or bad from wxWidgets because you need to to do most things by yourself.

I'm using wxWidgets to make some small application which also needs to paint some customized thing and I'm quite happy with it up to now.

And for such very wxWidgets specified question, maybe wxForum is a good place to ask for help

Share this post


Link to post
Share on other sites
For now, I'm using wxDC to paint the 2D graphics. I haven't gotten into the 3D graphics yet.

The wxAutoBufferPaintDC did not change the flicker problem. It is probably also worth noting the the application crashes on close, so it's looking more like a flaw in design to me.

The paint process is like so:

I have a wxTimer that launches a function called render every 10 milliseconds. In that function, I call move on my Player, and that takes care of the player response to movement keys. Then it calls Refresh on the main wxFrame.

In the MapPanel, there's a function called Paint that is Connected to the PaintEvent. This function loops through an array that holds all of the tiles, and then draws the tiles on the screen. After that, it's supposed to draw the player on top of them, but it doesn't ever seem to do that.

The code is located on a different computer, but if you need to see samples, let me know and I'll log on it and post what you need to see.

Share this post


Link to post
Share on other sites
1, Need the code of the paint function and timer event handler
2, Try to change the timer to 30ms (or 50, or 100) instead of 10ms to see if it works. Not sure if wxDC can afford 100FPS game on Windows...
3, I used wxAutoBufferPaintDC, it works quite well, no flicker. But I don't repaint periodically, I only repaint on demand.

Note: if you are making a serious game, only use wxAutoBufferPaintDC for *test*. After it works, you need to avoid it and do double buffer manually.
I think wxAutoBufferPaintDC will recreate the back buffer (bitmap) each time when drawing, that's a performance hit. You need to maintain the back buffer by yourself. That's a future concern though.

Also note when using wxAutoBufferPaintDC, you need to draw the whole background by yourself. System background is not drawn with wxAutoBufferPaintDC.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!