Page 2 of 3

Re: Beginner's Guide to Game Programming

Posted: Thu Jun 25, 2009 4:25 pm
by MarauderIIC
For OGL, it looks like you have to set a special flag for non-power-of-2 images. Not sure what the effects are. http://www.gamedev.net/community/forums ... _id=466904 has some allusions.

Need moar verification

Posted: Sat Jun 27, 2009 11:15 am
by Moosader
XianForce wrote:doesn't SDL_Quit destroy the buffer (screen) ?
Anyone know?

The buffer/screen is just another SDL_Surface so I thought you had to free it afterwards anyway.

Re: Need moar verification

Posted: Sat Jun 27, 2009 11:49 am
by Bakkon
Moosader wrote:
XianForce wrote:doesn't SDL_Quit destroy the buffer (screen) ?
Anyone know?
When you use SDL_SetVideoMode on a surface, SDL then knows to destroy it within SDL_Quit.
SDL Documentation wrote: Return Value
The framebuffer surface, or NULL if it fails. The surface returned is freed by SDL_Quit() and should not be freed by the caller.
http://www.libsdl.org/docs/html/sdlsetvideomode.html

Re: Beginner's Guide to Game Programming

Posted: Sat Jun 27, 2009 12:24 pm
by Moosader
Bakkon wrote:
Moosader wrote:
XianForce wrote:doesn't SDL_Quit destroy the buffer (screen) ?
Anyone know?
When you use SDL_SetVideoMode on a surface, SDL then knows to destroy it within SDL_Quit.
SDL Documentation wrote: Return Value
The framebuffer surface, or NULL if it fails. The surface returned is freed by SDL_Quit() and should not be freed by the caller.
http://www.libsdl.org/docs/html/sdlsetvideomode.html
Ahh oke, thanks.
So then, does it mess it up if you try to free it again?

Re: Beginner's Guide to Game Programming

Posted: Sat Jun 27, 2009 12:40 pm
by Bakkon
Moosader wrote: Ahh oke, thanks.
So then, does it mess it up if you try to free it again?
Probably nothing too bad, as I use to manually free it before I learned that. Probably equivalent to calling SDL_FreeSurface and the same surface twice. Not sure how SDL handles that.

I take that back. Haha.

Re: Beginner's Guide to Game Programming

Posted: Sat Jun 27, 2009 1:10 pm
by MarauderIIC
Moosader wrote:Ahh oke, thanks.
So then, does it mess it up if you try to free it again?
If you free it and SDL_Quit(), it can cause a crash. I forget if it crashes if you set it to NULL or if you don't, but at least one of those causes a crash.

Re: Beginner's Guide to Game Programming

Posted: Sat Jun 27, 2009 6:28 pm
by lotios611
I'm following the guide, and it's helping me a lot. I have one question. What should I set the maxFrame to? I am using one of your RPG style spritesheets.

Re: Beginner's Guide to Game Programming

Posted: Sat Jun 27, 2009 7:52 pm
by Moosader
lotios611 wrote:I'm following the guide, and it's helping me a lot. I have one question. What should I set the maxFrame to? I am using one of your RPG style spritesheets.
for my sprite sheets, there are four frames of animation (1-2-3-2 loop), so maxFrame will be 4.

When you go to display the sprite, it'll be something like this:

int filmstripx = (int)(player.frame * player.w);
if ( player.frame >= 3 ) // on the 4th frame, which should be frame #2
filmstripx = 2 * player.w;

masked_blit( imgPlayer, buffer, filmstripx, player.direction * player.h, player.x, player.y, player.w, player.h );

If I had put the duplicate middle (both feet down) sprite at the end instead of having the three frames, you wouldn't have to have the if statement, but since I did you have to do a little more work to make up for the 4th frame be the same as the 2nd.

Re: Beginner's Guide to Game Programming

Posted: Sun Jun 28, 2009 1:44 am
by XianForce
Moosader wrote:
Bakkon wrote:
Moosader wrote:
XianForce wrote:doesn't SDL_Quit destroy the buffer (screen) ?
Anyone know?
When you use SDL_SetVideoMode on a surface, SDL then knows to destroy it within SDL_Quit.
SDL Documentation wrote: Return Value
The framebuffer surface, or NULL if it fails. The surface returned is freed by SDL_Quit() and should not be freed by the caller.
http://www.libsdl.org/docs/html/sdlsetvideomode.html
Ahh oke, thanks.
So then, does it mess it up if you try to free it again?

Well I would think if something bad was going to happen, you would've noticed =p?

Re: Beginner's Guide to Game Programming

Posted: Sun Jun 28, 2009 7:55 am
by lotios611
Moosader wrote:
lotios611 wrote:I'm following the guide, and it's helping me a lot. I have one question. What should I set the maxFrame to? I am using one of your RPG style spritesheets.
for my sprite sheets, there are four frames of animation (1-2-3-2 loop), so maxFrame will be 4.

When you go to display the sprite, it'll be something like this:

int filmstripx = (int)(player.frame * player.w);
if ( player.frame >= 3 ) // on the 4th frame, which should be frame #2
filmstripx = 2 * player.w;

masked_blit( imgPlayer, buffer, filmstripx, player.direction * player.h, player.x, player.y, player.w, player.h );

If I had put the duplicate middle (both feet down) sprite at the end instead of having the three frames, you wouldn't have to have the if statement, but since I did you have to do a little more work to make up for the 4th frame be the same as the 2nd.
Thanks for your help. :)

Re: Beginner's Guide to Game Programming

Posted: Sun Jun 28, 2009 2:21 pm
by dandymcgee
XianForce wrote:Well I would think if something bad was going to happen, you would've noticed =p?
Not necessarily.. it took me and Andrew about 15 minutes to figure out that Lusikka's level editor was crashing because of a huge memory leak (the only reason we even noticed it was because it was so bad that the OS was terminating it at 200KB). Sometimes task manager tells you things the compiler doesn't. ;)

Re: Beginner's Guide to Game Programming

Posted: Sun Jun 28, 2009 4:54 pm
by XianForce
dandymcgee wrote:
XianForce wrote:Well I would think if something bad was going to happen, you would've noticed =p?
Not necessarily.. it took me and Andrew about 15 minutes to figure out that Lusikka's level editor was crashing because of a huge memory leak (the only reason we even noticed it was because it was so bad that the OS was terminating it at 200KB). Sometimes task manager tells you things the compiler doesn't. ;)
Well it was crashing, hence there's something wrong? So after coding in SDL for a while, I think you would notice it repeatedly doing something its not supposed to do.

Re: Beginner's Guide to Game Programming

Posted: Sun Jun 28, 2009 6:33 pm
by dandymcgee
XianForce wrote: Well it was crashing, hence there's something wrong? So after coding in SDL for a while, I think you would notice it repeatedly doing something its not supposed to do.
That's why it was easy to find, but not all memory leaks cause a crash (or any visible error) within the first 10 seconds. I was just saying it could certainly be causing something bad to happen that you're not aware of.

Re: Beginner's Guide to Game Programming

Posted: Mon Jun 29, 2009 12:33 pm
by Moosader
:P You guys

stereo123 wrote:Do you think OOP has any place in simple games? I made a pong in allegro with C. I'm now starting to get into actionscript (easier to share, no downloads) and the 2 books i got are full of OOP. I knew i'd have to learn it sooner or later, but i remember reading that it just wasn't needed for the kind of simple retro games that interest me.
Opinions?

Re: Beginner's Guide to Game Programming

Posted: Mon Jun 29, 2009 3:10 pm
by dandymcgee
Moosader wrote::P You guys

stereo123 wrote:Do you think OOP has any place in simple games? I made a pong in allegro with C. I'm now starting to get into actionscript (easier to share, no downloads) and the 2 books i got are full of OOP. I knew i'd have to learn it sooner or later, but i remember reading that it just wasn't needed for the kind of simple retro games that interest me.
Opinions?
I tend to be one of those "OOP Whores" as Falco would say. I'm not saying I think it's a good thing, but I find it much easier than other programming techniques. For projects as small as pong you certainly don't need to use strict OOP standards, if any at all. It just makes things more complicated as a beginner, but I find it tends to neaten things up if you fully understand what you're doing.

[Random] In my most recent project I made a few of my Object class's member variables public!!! It made things so much easier to not have a load of accessors that served absolutely no error-checking purpose:

Code: Select all

public:
     //Completely pointless accessor.
     void GetXAccel(){ return xAccel; }
[/Random]