XNA - NeHe Style (Projects 1 - 10) Source Code

Started by
28 comments, last by EnigmaticCoder 16 years, 6 months ago
Hail All, Short Form: I've implemented the first NeHe tutorial in XNA. The project and related files are located here. Features: - 800x600 Resizeable Window - Fullscreen Toggleable (F1 Key) - Mouse is visible in Windowed Mode, Hidden in Full-Screen Mode - Update and Draw only if Window has Focus - 16 bit(565) BackBuffer (Same as NeHe's Tutorials) - Clears BackBuffer and DepthBuffer on Draw Call - Terminates with ESC Key Anyone interested in downloading the zip file, checking out the code, running the program etc...are encouraged. Please provide feedback about coding style, implementation details, etc... Long Form: Through a series of fortunate events I've suddenly found myself in a situation of needing to learn XNA relatively quickly. For me, the best way to learn something new is to just give it a try, "kick the tires" so to speak, and see what I can do with the framework or language. In the spirit of that, I've decided to implement all of the NeHe tutorials in XNA. I'm sure it has probably been done before already, but that doesn't solve my immediate problem of needing to learn the framework, and learning best through experience. At any rate, I just wanted to post here and make my XNA Framework, as implemented in NeHe's Tutorial 1, available to everyone. Please feel free to provide feedback, and as I work my way through the tutorials I'll continue to post my projects, etc... Once again, the download is located here. Updates/Errata: While working on project #2 I found a bug in the ResetProjection() method. I will update it in the downloadable source. However, if you want to make the changes locally, it should read:

protected void ResetProjection()
{
    Viewport viewport = graphics.GraphicsDevice.Viewport;

    // Set the Projection Matrix.  Make sure to cast one of the viewport sides
    // to a FLOAT.  Otherwise it's truncated, and you dont get a correct aspect ratio.
    projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
        (float)viewport.Width / viewport.Height, 0.1f, 100.0f);
}









Cheers! [Edited by - JWalsh on September 25, 2007 1:03:27 PM]
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Advertisement
JWalsh, I'm surprised you have time to get anything job-related done with all the things you do around here [lol]. I love the idea of doing some NeHe-style XNA tutorials (though, hopefully with some better code than NeHe). Can't look at the code ATM but I'll provide more feedback when I can
Project 2 Completed!

I've implemented the second NeHe tutorial in XNA. The project and related files are located here.

Features:
- Displays two white shapes drawn with TriangeStrips

Anyone interested in downloading the zip file, checking out the code, running the program etc...are encouraged. Please provide feedback about coding style, implementation details, etc...

Updates/Errata
9/19/2007, 3:00pm PT
I've discovered that you can embed changes to the effect object, such as transforms, etc...within a call to Begin() on the effect and pass, so long as you call CommitChanges() before rendering additional primitives.

Additionally, I reverted the BackBuffer to it's default value - a 32bit ARGB format, rather than a 16bit BGR. The smooth shading on the triangle of project 3 looks MUCH better.

9/20/2007, 2:00pm PT
Uploaded new source which corrected a problem with resources not being correctly restored when a device was lost.



[Edited by - JWalsh on September 20, 2007 3:41:02 PM]
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Cool. How far do you think you will be going with these tutorials? Just until you know enough to get away with what you were needing to do?

With the increasing popularity of XNA, it might be worth while to continue (or find someone else to continue) the tutorials...

That, and I wouldn't worry about setting it to a 16 bit back buffer. If XNA handles it, let XNA do it. Besides, when is the last time that a video card was released that didn't support at least a 24 bit depth buffer?
Project 3 Completed!

I've implemented the third NeHe tutorial in XNA. The project and related files are located here.

Features:
- The Triangle is drawn with Vertex Coloring enabled
- The Rectangle is drawn with the VC Disabled, but with a specified diffuse material

Anyone interested in downloading the zip file, checking out the code, running the program etc...are encouraged. Please provide feedback about coding style, implementation details, etc...

Updates/Errata
9/20/2007, 2:00pm PT
Uploaded new source which corrected a problem with resources not being correctly restored when a device was lost.



[Edited by - JWalsh on September 20, 2007 3:45:51 PM]
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Keep 'em coming [grin]

I'm gonna stick this to the top for now to avoid it getting 'lost' amongst the flow of other threads. I reckon this sort of thing could be very useful to people...

Cheers,
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

wow... it'd be amazing to see a full series of these.
Project 4 Completed!

I've implemented the fourth NeHe tutorial in XNA. The project and related files are located here.

Features:
- The Triangle is rotated CCW about the Y-Axis
- The Rectangle is rotated CW about the X-Axis

Anyone interested in downloading the zip file, checking out the code, running the program etc...are encouraged. Please provide feedback about coding style, implementation details, etc...

Updates/Errata
9/20/2007, 2:00pm PT
Uploaded new source which corrected a problem with resources not being correctly restored when a device was lost.



[Edited by - JWalsh on September 20, 2007 3:10:18 PM]
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
JWalsh - you must be a mad man! If you keep churning these out at this rate, it'll only take a week to match NeHe!

I'll definitely have to check them out!
Quote:Original post by Moe
JWalsh - you must be a mad man! If you keep churning these out at this rate, it'll only take a week to match NeHe!


Hehe, Thanks Moe.

Unfortunately, the speed at which I'm able to pump these out has more to do with XNA's ease of use than my sanity or mastery of the technology. I'm really just learning as I go along.

As an example, the OpenGL implementation of Project 4 was approximately 425 LoC. XNA, only 230 LoC.

While everyone now realizes "Lines-of-Code" isn't an effective measurement on which to base the efficiency or complexity of an algorithm or API, it does suggest that even with having to create a vertex declaration, a BasicEffect, and Transforms for both the triangle and rectangle (none of which is required in OpenGL), XNA is still a very powerful framework, and does a lot of the heavy lifting for you.

Finally we've got a DirectX technology that matches OpenGL in ease of use.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

This topic is closed to new replies.

Advertisement