Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Suggestion to change a few lines
  Posted by: Insomnica
  When: 06/09/2010 at 14:37:05

 Collision with series 1
  Posted by: radulph
  When: 05/09/2010 at 13:33:14

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 17:26:26

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 16:52:02

 HLSL calculating normals
  Posted by: Rich_Zap
  When: 04/09/2010 at 15:00:20

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 12:28:41

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 08:46:31

 Walk along a wall
  Posted by: Anonymous
  When: 03/09/2010 at 10:28:02

 model problems
  Posted by: muffinman
  When: 03/09/2010 at 06:47:32

 Vertices problem
  Posted by: Anonymous
  When: 03/09/2010 at 05:48:35

 OcTree Question
  Posted by: Zorzomezz
  When: 03/09/2010 at 04:07:03

 error x3000:syntax error
  Posted by: Anonymous
  When: 02/09/2010 at 06:55:17

 Reflection problem in corners ...
  Posted by: Anonymous
  When: 31/08/2010 at 20:53:30

 OcTree Question
  Posted by: radulph
  When: 31/08/2010 at 18:00:04

 model problems
  Posted by: Archenon
  When: 30/08/2010 at 05:54:27

 Changing computer breaks my game
  Posted by: Archenon
  When: 30/08/2010 at 05:49:50

 model problems
  Posted by: muffinman
  When: 28/08/2010 at 16:58:10

 Vertices problem
  Posted by: Anonymous
  When: 27/08/2010 at 15:35:36

 Changing computer breaks my game
  Posted by: radulph
  When: 27/08/2010 at 07:12:24

 effects file and XNA 4.0 (Beta)
  Posted by: radulph
  When: 26/08/2010 at 06:33:33




Topic: noob question on tutorial 1 of XNA



  
Goto parent category
  
Create a new user account


   noob question on tutorial 1 of XNA
 Poster : stealthcoder
 Posts: 7
 Country : Canada
 City: Montreal

  
Posted by stealthcoder on 19/01/2008 at 02:00:46
Hello,

I just found this site, and it is really amzing how much material is covered. I am definitely going to work through all of these XNA tutorials.

I looked over the first tutorial "Opening a window". I am just learning C# and object oriented programming, so I hope what I am about to ask is not too stupid.

The code that was added to the base XNA template file was

1) declaring the global variable:


GraphicsDevice device;


2) Adding the method:


private void SetUpXNADevice()
{
    device = graphics.GraphicsDevice;
        
    graphics.PreferredBackBufferWidth = 500;
    graphics.PreferredBackBufferHeight = 500;
    graphics.IsFullScreen = false;
    graphics.ApplyChanges();
    Window.Title = "Riemer's XNA Tutorials";
}


3) Calling the above method from the Initialize() method:


SetUpXNADevice();


NOW HERE IS MY QUESTION FINALLY:

Why are we declaring the global variable "device"?

I can get this code to compile no problem, but I don't see what the use of the following two lines of code:


GraphicsDevice device;


and


device = graphics.GraphicsDevice;


If I comment out these two lines of code the program still compiles fine and give the same result.

Am I right that the lines of code


graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Window.Title = "Riemer's XNA Tutorials";


have no effect on the variable "device" that was declared at the start of the method SetUpXNADevice(). If this is true then why are we bothering with the variable "device"


Any clarification would be really appreciated.
Thank you.
 Poster : stealthcoder
 Posts: 7
 Country : Canada
 City: Montreal

  
Posted by stealthcoder on 19/01/2008 at 02:10:13
Oops, I meant to say that the name of the tutorial is "Staring a Project", not "Opening a window".
 Poster : Anonymous
 Posts:
 Country :
 City:

  
Posted by Anonymous on 18/08/2008 at 20:44:37
We create an instance of a graphics device. It's used starting from part 3:

device.VertexDeclaration = myVertexDeclaration;
                device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
 Poster : radulph
 Posts: 218
 Country : germany
 City: hamburg

  
Posted by radulph on 19/08/2008 at 06:16:56
First, in OO there is nothing like global variables - only member variables. These can be accessed within the whole class they are declared in.

You're right: We don't neccessery need th device variable. Our class "Game1" extends the class XNA.Game and by this inherits the member "graphics".

Device is just a member of graphics, so you could access the device any time by writing:
graphics.device
instead of just device. And so, there would be no need to declare device in the head of you class.

So why t.h. we are doing this?! Simple:
Less typing. It's just a short cut. As you will see in the further tutorials, the device will be often accesed and you save some chars, not needing to write graphics. ... every time ;)

greets
 Poster : riemer
 Posts: 1388
 Country : Belgium
 City: Antwerp

  
Posted by riemer on 19/08/2008 at 12:38:21
That's right, the only reason is: less typing. Nothing else. I was thinking about simply using GraphicsDevice, but I simply couldn't. Bad habit ;)

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 3.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)