Jump to content
  • Advertisement
Sign in to follow this  
killertypo

D3DX10_SPRITE's without textures

This topic is 2614 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

hey all i'm trying to figure out how I can render a sprite for display that does not contain texture information, only color information.

I know I can set the pTexture = NULL (or 0) to not set a texture; however, when I render the code I will see nothing on screen.

For example lets take the following -hacky- code:

[source lang=cpp]
D3DXMATRIX matScaling;
D3DXMATRIX matTranslation;

D3DXMatrixScaling(&matScaling, WINDOW_WIDTH, WINDOW_HEIGHT, 0);
D3DXMatrixTranslation(&matTranslation,
(float)0 + (WINDOW_WIDTH/2),
(float)(WINDOW_HEIGHT - 0 - (WINDOW_HEIGHT/2)),
0.1f); // ZOrder

// ID3D10Texture2D * ballBounce = NULL;
// ballBounce = TextureHandler::GetTexture2DFromFile(L"../textures/main-menu-1024x768.png", pD3DDevice);
// ID3D10ShaderResourceView * srv;
// TextureHandler::GetResourceViewFromTexture(ballBounce, &srv, pD3DDevice);
// ballBounce->Release();
D3DX10_SPRITE sprite;
sprite.pTexture = NULL; // srv;
sprite.ColorModulate = D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f);
sprite.TexCoord.x = 0;
sprite.TexCoord.y = 0;
sprite.TexSize.x = 1.0f;
sprite.TexSize.y = 1.0f;
sprite.TextureIndex = 0;
sprite.matWorld = matScaling * matTranslation;[/source]

I want this to display a sprite with no texture whose color / alpha is as described in the above struct. However all I get is nothing-ness on the screen. I believe this to be because of the way colormodulate works (it multiplies the pixels of the texture against the D3DXCOLOR passed in).

Is there a way to do this with a D3DX10_SPRITE or do I maybe have something improperly configured? It makes enough sense that I can easily enough create a sprite without a texture, the MSDN even says to set it to 0 or NULL if pTexture does not point to a texture. Though it seems that would imply that I could apply color information and see the color information instead. Maybe I'm just losing my brains today :)

My reason for doing this is so I can simply drop a transparent black sprite over an entire scene and slowly bring up the alpha channel, creating a fade out effect. this would be a lot nicer than changing the visible sprites color modulate each update. I'm of course open to any better suggestions :D

Share this post


Link to post
Share on other sites
Advertisement
I'm pretty sure you need a texture to draw with ID3D10Sprite, since it will build the quad it renders based on the dimensions of your texture. However you should be able to render a white 1x1 texture and tint it whatever color you want.

Share this post


Link to post
Share on other sites

I'm pretty sure you need a texture to draw with ID3D10Sprite, since it will build the quad it renders based on the dimensions of your texture. However you should be able to render a white 1x1 texture and tint it whatever color you want.


Yeah that was also an option, though I would think the quad quad would be built from the matWorld no?

I wanted to stay away from doing that only because it requires I keep around a 1x1 sprite for that specific use, it almost seems there is something wrong with that approach (maybe just in my thinking).

Maybe another option is to just build a quad myself and place it between the viewport and the sprites being rendered. Though my understanding was that behavior might not work as desired with the way viewports work vs. cameras.

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!