2D graphics / KOS tutorials

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
User avatar
finite
Insane DCEmu
Insane DCEmu
Posts: 223
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Jun 15, 2003 12:00 am
Location: melb.vic.au
Has thanked: 0
Been thanked: 0
Contact:

Post by finite »

Pyrosurfer wrote:I am using visual c++ and kos 1.9, and the following "vram_s[x + (y * 640)] = PACK_PIXEL(r, g, b); " would not work for me. Is this method not supported in 1.9?
Did you actually #define the PACK_PIXEL macro, as BlackAura described?

EDIT: Just noticed, when defining it's called "PACK_PIXELS", but used as PACK_PIXEL later. Bit of a bug in your tutorial there BlackAura. :) So yeah, just add or remove the S as you see fit.
Last edited by finite on Sun Aug 10, 2003 12:57 am, edited 1 time in total.
Pyrosurfer
DCEmu Nutter
DCEmu Nutter
Posts: 964
Joined: Sun Aug 11, 2002 5:07 pm
Has thanked: 0
Been thanked: 0

Post by Pyrosurfer »

Yeah i did the #define, but it didn't work. Edit: Changed pack_pixel to pack_pixels and it worked.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

D'oh! Typing error. That's what happens when you change the names of the macros at the last minute - it used to be PACK_RGB565. I'll change it...
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Alrighty... I've converted the tutorials to HTML, and put them up, along with a third tutorial, along with BlueCrab's PVR version. I'm going to be putting Reaper's SDL tutorial up soon too.

I've got two more 2D graphics tutes that I'm working on - one is pretty much done, the other's been coded but not written up. It's enough to do a simple game by now, so I might start doing some tutorials on controller input too. Anyone want to request a specific game to go through? Something simple, line an old arcade game would probably be best.

http://files.frashii.com/~sp00nz/Doom/f ... Aura/tutes
q_006
Mental DCEmu
Mental DCEmu
Posts: 415
Joined: Thu Oct 10, 2002 7:18 pm
Has thanked: 0
Been thanked: 0
Contact:

Requests!

Post by q_006 »

Pong, Breakout, and Pac Man (in that order).

Maybe some time later Super Mario Bros.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Pong's easy - typically just twenty lines of code. That's how long my last version (coded in about twenty minutes) was, I think.

Breakout - also fairly easy. It's just Pong, turned around 90 degrees, with blocks instead of a paddle.

Pac Man - Oddly, I've never done one... I don't think it'd be too hard though. Needs some actual graphics, instead of just boxes and lines, but otherwise it should be fairly easy.
Ian Micheal
Soul Sold for DCEmu
Soul Sold for DCEmu
Posts: 4865
Joined: Fri Jul 11, 2003 9:56 pm
Has thanked: 2 times
Been thanked: 4 times

Post by Ian Micheal »

Hey neat i will enjoy following the game tuts my pong clone was a lot more then 20 lines :oops: but i used AI and grafix. was only a 1 player game. i know tetris is allways good!.
Dreamcast forever!!!
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Well, the entire chunk of code was a lot longer, but most of that was some PVR code to render the bats, the ball, and the score, along with some controller inteface code. I don't consider that to be part of the game itself. The main game loop was very short. Admittedly, it was a little buggy, but it worked quite well - the bugs were just be being really, really lazy.

Space Invaders isn't really that difficult either. I coded a version of that in Visual Basic at school, while I was sitting in class with nothing to do because I'd finished the assignment about four weeks before it was due in. And that was a very complex version of Space Invaders.

So, in my to-do list for these tutorials, I've currently got:
Graphics - Hardware double buffering / animation
Graphics - Image loading and drawing (using KOS's image library)
Graphics - Sprite drawing, RLE accelerated sprites (these are a real pain in the bum)
Graphics - Software double buffering (DMA or store queues)
Game - DC controller support
Games - Pong, Breakout, Pacman, (maybe) Space Invaders, (maybe) Tetris

I might change the layout of the games tutorials a little bit. I don't much like the idea of teaching someone what to do - I prefer to teach them how to do it. So instead of writing a tutorial on how to write a Pong clone, I might instead write a tutorial on basic games programming, and use Pong as an example. That way, people might actually learn something, and can hopefully go on to create a game of their own. And I'd really like to see some more homebrew games.
Alexvrb
DCEmu Ultra Poster
DCEmu Ultra Poster
Posts: 1754
Joined: Wed Jul 17, 2002 11:25 am
Has thanked: 0
Been thanked: 0

Post by Alexvrb »

Sounds like quite a project.
If you have twenty monkeys,
banging randomly on typewriters,
they will in twenty minutes produce the complete source code to World of Warcraft.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Yeah, but I already have most of the code written. I've got hardware double buffering done, and I have code to load images (from Genesis Plus), draw images, draw sprites, use the controllers, and I have fairly simple versions of Pong and Space Invaders I can use.
Synlor
Official DCEMU Stalker
Official DCEMU Stalker
Posts: 1604
Joined: Tue Apr 23, 2002 6:26 pm
Location: South Dakota
Has thanked: 0
Been thanked: 0
Contact:

Post by Synlor »

Hmmm rebirth of dev.dcemulation.org? :) It would be great to get dcdev updated, and then have your tutorials. I think siggy is going to redo the site, but some things such as his own projects are coming in the way, lol. Think you would let dcdev host your tutorials if the site is ever updated? Great job btw
Image
Thanks to Digital Chaos, GoldbergWWE, and ace for the avatar, sig, and badge!
http://devcast.dcemulation.com
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

I'd let them host the tutorials - I have no problems with that. Tutorials on drawing text, and hardware double buffering are coming up - I'm writing the double buffering one up in HTML, and writing the code for the text one (basically reusing KOS code)
Pyrosurfer
DCEmu Nutter
DCEmu Nutter
Posts: 964
Joined: Sun Aug 11, 2002 5:07 pm
Has thanked: 0
Been thanked: 0

Post by Pyrosurfer »

Any progress yet on new tutorials? I would really like to learn how to input from the controller and keyboard. Great job so far Everyone!
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Well, I have an extremely rough and insufficiently tested double buffering tutorial in text format. I'll test it and upload it later, probably tomorrow morning (late Tuesday night US time)

Controller input isn't really that hard - I'll try to do a tutorial on it in a bit.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Post by BlueCrab »

Controller Input:

I actually had some stuff for a contoller input tutorial written up already, so I figured I'd post it. (Feel free to add to this BlackAura)

With newer versions of KOS (up to 1.2.0), you have two methods you can choose from for controller input. Both are very similar, and easy to understand. First I will tell what is the same between the two, and then get into the differences.

Button Codes:

Both methods of polling the controllers (for lack of a better term), use the same button names. They are self explanatory, and listed below:
Most common:

Code: Select all

CONT_A
CONT_B
CONT_X
CONT_Y
CONT_START
CONT_DPAD_UP
CONT_DPAD_DOWN
CONT_DPAD_LEFT
CONT_DPAD_RIGHT
Here are a few others that don't appear on most controllers, but still can be used:

Code: Select all

CONT_C
CONT_D
CONT_Z
CONT_DPAD2_UP
CONT_DPAD2_DOWN
CONT_DPAD2_LEFT
CONT_DPAD2_RIGHT
Remember, all the button codes are used in both methods of controller polling.

Now lets move on to some differences:

Method 1: The old Maple API:

This method of controller input uses the older Maple API of KOS. This method is slightly easier (no use of pointers, one less function call), but may not be available in future versions of KOS. This is, by far, the most common way you will see controller code, as of right now.

To hold the controller information, we need a simple variable. This is a cont_cond_t in this case.

Code: Select all

cont_cond_t cond;
Will get a variable set up for you.

Now, to see what's being pushed, and react to it, you would put the following code in your game's main loop:

Code: Select all

cont_get_cond(maple_first_controller, &cond);

if(!(cond.buttons & CONT_A))	{
	/* Do anything that needs to be done for pressing the A button here */
}

/* Put any buttons you will need in here, just like the A one above */
This just grabs what is being pushed on the 1st controller, and puts it in our variable we set up. All you have to do is test that variable for what ever button constant you want, as directed above. Simple, eh?

Method 2: The new Maple API:

This next method of controller polling relies on the new Maple API in newer versions of KOS. I believe that this API was available beginning with KOS 1.1.8, but I'm not positive.

This method involves two different variables, and is slightly easier to deal with multiple variables. Here are our two variables:

Code: Select all

cont_state_t * state;
maple_device_t * addr;
Our cont_state_t pointer will hold what buttons are pushed, and the maple_device_t pointer will point to a Maple address.

Before we try to get controller info, we need to initialize the address variable. This is done like so:

Code: Select all

addr = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
This will set the address variable to point to the first found Maple device that reports itself as a controller. You can change the 0 in the function to allow for other controllers to be used, just make sure to have multiple address variables.

Now to poll the controllers, put the following code in your game's main loop:

Code: Select all

state = maple_dev_status(addr);
if(state->buttons & CONT_A)	{
	/* Do any A button stuff here */
}
Once again feel free to add other buttons, and take A out. Just make sure they all look similar to the code snippet above.

That's all for right now, because I can't think of anything else to say! Feel free to leave any comments/questions and I'll try to remember to respond.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Cool, thanks. Saves me from having to do it from scratch.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Post by BlueCrab »

BlackAura wrote:Cool, thanks. Saves me from having to do it from scratch.
Heh. Glad I could help. BTW, I think you should rename this thread KOS tutorials, or something.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Yeah, probably...

Edit: I don't currently have a Dreamcast dev kit set up, so I can't do any tutorials that rely on me having a Dreamcast to test them on. That's no big deal though - most of the stuff I've got planned is fairly generic anyway, and will work just fine on a PC using SDL or on a Dreamcast. It just means that they won't actually be properly tested on a Dreamcast.

I'm HTMLifying Bluecrab's controller tutorial, and editing it a little bit. Should be done soon.
q_006
Mental DCEmu
Mental DCEmu
Posts: 415
Joined: Thu Oct 10, 2002 7:18 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by q_006 »

How are those tutorials going?

Also thanks a lot for taking the time to provide them!
(That goes out to Bluecrab, Im(r)eaper, and Blackaura)

edit: sorry the comics screen i'm using has everything in caps.
so i didn't realize. also please be a little more informant than "capslock".
Last edited by q_006 on Mon Aug 25, 2003 4:27 am, edited 1 time in total.
Alexvrb
DCEmu Ultra Poster
DCEmu Ultra Poster
Posts: 1754
Joined: Wed Jul 17, 2002 11:25 am
Has thanked: 0
Been thanked: 0

Post by Alexvrb »

capslock
If you have twenty monkeys,
banging randomly on typewriters,
they will in twenty minutes produce the complete source code to World of Warcraft.
Post Reply