Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I wish to know if there is a way to load a texture which is not in powers of 2, for example 100 X 56 in dimension, in XNA 4.0 and draw it using VertexPositionColorTexture.

share|improve this question
    
Not sure about VertexPositionColorTexture, but this can be done with SpriteBatch and Texture2D. –  Nate May 3 '11 at 18:29
add comment

1 Answer 1

It's very simple using SpriteBatch. Initialize it :

spriteBatch = new SpriteBatch(yourGraphicsDevice);

When you load content just call

image = Content.Load<Texture2D>(@"yourImage");

then you can draw it easily

spriteBatch.Begin();
spriteBatch.Draw(image, dstRect, srcRect, Color.White);
spriteBatch.End();

That's all !

srcRect is juste a rectangle that indicates where your image is in the texture. That way you can have multiple images in one texture.

For the VertexPositionColorTexture, you'll probably want to create your own spriteBatch. See here.

share|improve this answer
    
Thanks for the reply Minishlink. Yes, I know how to do that in spritebatch. Sorry, I didn't mention that. The link to create a custom spritbatch looks interesting. I will surely try that. Thanks again! –  Vijayendra Tripathi May 5 '11 at 18:32
    
The example I gave you is a bit old unfortunately, so you might want to take a look at a more recent piece of code. :) –  Minishlink May 5 '11 at 19:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.