Beginner's Guide to Game Programming

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Beginner's Guide to Game Programming

Post 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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Need moar verification

Post 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.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Need moar verification

Post 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
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: Beginner's Guide to Game Programming

Post 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?
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Beginner's Guide to Game Programming

Post 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.
Last edited by Bakkon on Sat Jun 27, 2009 1:41 pm, edited 1 time in total.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Beginner's Guide to Game Programming

Post 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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Beginner's Guide to Game Programming

Post 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.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: Beginner's Guide to Game Programming

Post 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.
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Beginner's Guide to Game Programming

Post 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?
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Beginner's Guide to Game Programming

Post 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. :)
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Beginner's Guide to Game Programming

Post 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. ;)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Beginner's Guide to Game Programming

Post 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.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Beginner's Guide to Game Programming

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: Beginner's Guide to Game Programming

Post 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?
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Beginner's Guide to Game Programming

Post 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]
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply