Texture2D and GraphicsDevice

Started by
3 comments, last by LilithAnn 14 years, 8 months ago
Seems I can't find a clear explanation of this. In trying to create an impromptu texture on which I can draw . I'm finding several examples but one thing remains unclear. texture = new Texture2D (GraphicsDevice,....... When I input my code based on the examples I see "GraphicsDevice" and input it exactly that way despite the fact that I was pretty sure GraphicsDevice is a type. And sure enough, that's what the compiler says too. Other code shows "graphicsDevice" which otherwise doesn't seem to be declared in the code but it may be buried in a parent class somewhere. Regardless, this doesn't appear to be in scope for the class I'm creating nor can I seem to coerce it out of the Game class. Notably the example deals with a Texture2D object declared in the Game class. So, let me ask.... Does a GraphicsDevice object have to be declared for each texture within the scope of the code that creates the texture? In all my reading on Windows programming (of which I'm a very poor student/researcher) it seems the literature always talks about graphic devices and device contexts as if the programmer knows what they are exactly but I've never seen a basic description of what they are from it's relationship to the graphic system. Color me unlearned.
Ŀ
Advertisement
Unless you're doing something fancy (like rendering to multiple monitors), you're only ever going to have one instance of GraphicsDevice in your app. When you create a new Texture2D, you have to pass it a reference to that GraphicsDevice instance.

The example code you've been reading has most likely been accessing the GraphicsDevice property of the Game class, which you typically inherit from to create your own Game class. If you're creating this Texture2D elsewhere, then you can pass a reference this other class through its constructor so that it also has a reference to the GraphicsDevice instance created by the Game class.
Got it. I've revised this post since I played around with the code, trying to make my thoughts clear before answering and finally got it to compile successfully. Strangely enough I still seem to be passing what was is a type but it's not complaining now.

Thanks for your help.

Lil
Ŀ
Are you happy with your understanding of what is going on?

If not, post some of your code and maybe you can get a better explanation.
I think I am at the moment. That's not to say that something won't pop up later, but for now I think I can further my progress.

Thanks for your help. I appreciate it greatly.

Lil
Ŀ

This topic is closed to new replies.

Advertisement