Jump to content
  • Advertisement
Sign in to follow this  
AnotherRandomNewbie

Spritebatch scaling using destrect not working.

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a weird issue with scaling a texture 2d during the draw.

I'm using http://xnadsplayer.codeplex.com/ to play videos. The player has a Texture2D member which is updated for each frame(outputframe).

Playing any movies is no problem but for some reason I'm not able to scale the frame when drawing. When I try to scale the texture during the spritebatch (using a destination rectangle) nothing will be drawn on the screen.

[color="green"]//works (native width and height will be drawn)
spriteBatch.Draw(m_videoPlayer.OutputFrame, [color="blue"]new [color="#2b91af"]Vector2(0,0), [color="#2b91af"]Color.White); [color="green"]

//works but no scaling (native width and height will be drawn which is expected as the outputframes texture is used to set the height and width of the rectangle)
spriteBatch.Draw(m_videoPlayer.OutputFrame, [color="blue"]new [color="#2b91af"]Rectangle(0, 0, m_videoPlayer.OutputFrame.Width, m_videoPlayer.OutputFrame.Height), [color="#2b91af"]Color.White);
[color="green"]
//doesnt work(no texture being drawn on the screen)
spriteBatch.Draw(m_videoPlayer.OutputFrame, [color="blue"]new [color="#2b91af"]Rectangle(0, 0, 320, 240), [color="#2b91af"]Color.White);


I have tried scaling another random texture with the same spritebatch.draw overload. This worked without any issues.

Does anyone have any idea?

Share this post


Link to post
Share on other sites
Advertisement
I have an update on this.

Stupid that I didnt try this sooner but here goes.


The Texture2D I was trying to strech was quite big. So I figured i would just half the size. Its a 640*480 movie so I ended up stretching it to 320*240. So I figured I would try and stretch it only 1 pixel. Wow that actually worked. Then I tried stretching some more and then I noticed what was going on. The more I downsize the texture the more transparent it becomes.

Now the thing is that I have no idea why the texture becomes more transparant when I downscale it. Within the movieplayer the alpha channel is set to 255 for each frame.

Anyone any ideas?

Share this post


Link to post
Share on other sites
Another update.

I noticed that the texture2d in the videoplayer was created with MipMap set to true. When I tried setting mipmap to false the image would no longer get transparant when downscaling the image.


outputFrame = [color=blue]new [color=#2b91af]Texture2D(graphicsDevice, videoWidth, videoHeight, [color=blue]true, [color=#2b91af]SurfaceFormat.Color);


This texture2D will remain instanciated throughout the whole video. Only the data is set upon each frame update like this:

void Update()
[color=blue] for ([color=blue]int y = 0, y2 = videoHeight - 1; y < videoHeight; y++, y2--)
{
[color=blue] for ([color=blue]int x = 0; x < videoWidth; x++)
{
samplePosRGBA = (((y2 * videoWidth) + x) * 4);
samplePosRGB24 = ((y * videoWidth) + x) * 3;

videoFrameBytes[samplePosRGBA + 0] = bgrData[samplePosRGB24 + 2];
videoFrameBytes[samplePosRGBA + 1] = bgrData[samplePosRGB24 + 1];
videoFrameBytes[samplePosRGBA + 2] = bgrData[samplePosRGB24 + 0];
videoFrameBytes[samplePosRGBA + 3] = alphaTransparency;
}
}
}
outputFrame.SetData<[color=blue]byte>(videoFrameBytes);

The bgrData is copied from the directShowNet Samplegrabber. Alpha transparancy is set to 255.


So what I think is happening: The Texture2D is created with MipMap enabled. Somewhere in the constructor smaller MipMap images are generated. Due to the fact that there is no image data yet in the texture (this will at the very first be set in the next update call) all the pixels in the MipMap images are rgba 0,0,0,0.
So as soon as I tried to resize the texture when drawing it to the screen it got lineairly interpolated with the nearest mipmap image.

Some questions:
1. Does this make any sence?
2. Would there be ANY reason to have mipmap enabled for a texture2D that will only be used to draw videoframes (that change 30 times per second anyway).
3. If the answer to 1 and 2 is "yes" and "no" then it is safe to assume that the "setData" function of the Texture2D class does not regenerate MipMap. why wouldnt it?

I would have used code blocks as I did in my previous posts. But for some reason I couldnt find the dropbox when creating this post.. temp disabled perhaps?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!