XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

Compiler error

Last post 7/8/2007 12:53 PM by getviewsnow. 6 replies.
  • 7/7/2007 1:56 PM

    Compiler error

    Hello,

    You probably remember me because of that stupid question ( DX10 on DX9 gpu).

    Anyway I decided to try XNA (I am not a game developer so I think I dont need to know DX10 for beginning.

    So I've learned some C# basics and started with XNA.
    I have choosed "New game project" and I got the basic code and assembly configuration provided by C# Express. (very cool feature).

    So, I folowed a tutorial (mostly) and edited code on style I like (variable names and spaccing).
    Now when I try to compile I get a compiler error:
    Error  1  'Microsoft.Xna.Framework.GraphicsDeviceManager' does not contain a definition for 'VertexDeclaration'  C:\Users\jan\Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\Game1.cs  133  22  WindowsGame1
    Error  2  The best overloaded method match for 'Microsoft.Xna.Framework.Graphics.VertexDeclaration.VertexDeclaration(Microsoft.Xna.Framework.Graphics.GraphicsDevice, Microsoft.Xna.Framework.Graphics.VertexElement[])' has some invalid arguments  C:\Users\jan\Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\Game1.cs  133  42  WindowsGame1
    Error  3  Argument '1': cannot convert from 'Microsoft.Xna.Framework.GraphicsDeviceManager' to 'Microsoft.Xna.Framework.Graphics.GraphicsDevice'  C:\Users\jan\Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\Game1.cs  133  64  WindowsGame1
    Error  4  'Microsoft.Xna.Framework.GraphicsDeviceManager' does not contain a definition for 'DrawUserPrimitives'  C:\Users\jan\Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\Game1.cs  134  20  WindowsGame1
    The following lines are underlined:
      graphics.VertexDeclaration = new VertexDeclaration(graphics, VertexPositionColor.VertexElements);
    graphics.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
    Hope you guys can help me :)
  • 7/7/2007 2:06 PM In reply to

    Re: Compiler error

    Answer
    Reply Quote

    I'm pretty sure you have to replace "graphics.VertexDeclaration = " and the first argument to:

    graphics.GraphicsDevice;

    'Cause what is XNA gonna do with the thing that manages the graphics device? It wants the graphics device itself, thus: Graphics.GraphicsDevice;

    Blah. I wanna pet the kitty.

  • 7/7/2007 3:38 PM In reply to

    Re: Compiler error

    Answer
    Reply Quote
    thanks.

    What about graphics.DrawUserPrimitives ?
  • 7/7/2007 6:30 PM In reply to

    Re: Compiler error

    Same thing. The graphics variable is of type GraphicsDeviceManager. You need to access the GraphicsDevice member. e.g.:

    graphics.GraphicsDevice.DrawUserPrimitives(...)

     

  • 7/8/2007 5:48 AM In reply to

    Re: Compiler error

    Sorry, but when I readed this phrase "I'm pretty sure you have to replace "graphics.VertexDeclaration = " and the first argument to:" I tought that I have to delete VertexDeclaration and write graphics.GraphicsDevice instead.

    Now I have
     graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(graphics, VertexPositionColor.VertexElements);
    graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
    But I still get a compiler error:

    Error    1    The best overloaded method match for 'Microsoft.Xna.Framework.Graphics.VertexDeclaration.VertexDeclaration(Microsoft.Xna.Framework.Graphics.GraphicsDevice, Microsoft.Xna.Framework.Graphics.VertexElement[])' has some invalid arguments    C:\Users\jan\Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\Game1.cs    133    57    WindowsGame1
    Error    2    Argument '1': cannot convert from 'Microsoft.Xna.Framework.GraphicsDeviceManager' to 'Microsoft.Xna.Framework.Graphics.GraphicsDevice'    C:\Users\jan\Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\Game1.cs    133    79    WindowsGame1


  • 7/8/2007 11:35 AM In reply to

    Re: Compiler error

    Answer
    Reply Quote

    Once again, a GraphicsDeviceManager is NOT a GraphicsDevice. The first parameter to the VertexDeclaration constructor is supposed to be a GraphicsDevice object, but you've passed a GraphicsDeviceManager object.

    graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionColor.VertexElements);

  • 7/8/2007 12:53 PM In reply to

    Re: Compiler error

    Thank you.

    I understand now.(providing a code snippet helped) Sorry, but I am still an english learner :)

    SOLVED
Page 1 of 1 (7 items) Previous Next