00:00
00:00
View Profile kiwi-kiwi
My two passions are gaming and programming and my hobby is combining them.

Age 34, Male

Student

Polytechnic University

Joined on 3/6/09

Level:
9
Exp Points:
735 / 900
Exp Rank:
88,806
Vote Power:
5.09 votes
Rank:
Scout
Global Rank:
44,048
Blams:
61
Saves:
141
B/P Bonus:
4%
Whistle:
Normal
Medals:
1,217

Game Development w/ Qt

Posted by kiwi-kiwi - July 4th, 2010


Well, I thought I'd give linux gamedev a try, so after careful consideration I thought why not use Qt, it's cross-platform enough and there seems to be a reasonable amount of documentation, plus you can totally style your app with CSS, how awesome is that, not that it would actually matter, because I use OpenGL but still.
Now the problem is that Qt has a internal main loop for its applications and being thought for event driven programming I had some problems with making the game realtime.

Problem #1: It won't update :(

There is no repaint scheduled, by default, QGLWidget just paints the window the first time and then maybe if you resize the window, I basically had two solutions, either set a timer and onTimeout call paint, or schedule a repaint right after the last one is over. I went for the last option because I had no way of knowing the reliability of the timer event on different machines/situations, this is easily solved by overriding the paintEvent method

Solution: Override the paintEvent method and call update inside it, just be sure to construct a QGLWdiget::paintEvent before to be sure that the parent gets the message as well

Problem #2: It's not realtime

Well this is not actually related to Qt, but to gcc and linux. Because I thought it would be easier for me this way, I just ported an older project of mine that I made under windows. Thing is I used clock to make sure animations are independent from the framerate. Problem is that under gcc 4.4.4 at least, the clock function returns the number of milliseconds rounded to seconds for some reason, so it was out of the question.
After a quick search on the internet I found the gettimeofday function which isn't actually cross-platform , but on the other hand gives microsecond precision (I was little bit skeptical at first, but in a empty console application it seems to actually give values below a millisecond).

Solution: Don't use clock, use gettimeofday instead
And that's it for today maybe I'll post some more if I run into more trouble.


Comments

Comments ain't a thing here.