Jump to content
  • Advertisement
Sign in to follow this  

Smaller quad makes the dynamic texture disappear ...

This topic is 2777 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 People,

I am creating a simple window that renders two pre-transformed triangles that form a quad. These triangles are textured with a dynamic texture that I manually fill.

Everything works fine when rendering with a fixed pipeline, however the weirdness starts when using a shader. If my quad is around 256x256 everything is fine, but if I change this to 128x128 the texture does not get updated and just renders a greyish quad instead.

Any ideas about what could be happening?

My code to initialize DirectX is:

d3d = Direct3DCreate9(D3D_SDK_VERSION);
d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode);

ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.Windowed = TRUE;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = screenWidth;
d3dpp.BackBufferHeight = screenHeight;


I create the dynamic texture like this:

D3DXCreateTexture(device_, simulationSize_, simulationSize_, 0, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture_);

D3DLOCKED_RECT lockedRect;
HRESULT hResult = texture_->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD);
BYTE* pData = (BYTE*)lockedRect.pBits;
for(int y=0; y<simulationSize_; ++y) {
for(int x=0; x<simulationSize_; ++x) {
pData[y*lockedRect.Pitch + x*4] = 255;
pData[y*lockedRect.Pitch + x*4 + 1] = 0;
pData[y*lockedRect.Pitch + x*4 + 2] = 0;
pData[y*lockedRect.Pitch + x*4 + 3] = 255;

I make the quad like this:

float size = 128; /// If this is 256 it works fine
Vertex vertices[] = {
{0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
{size, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f},
{0.0f, size, 0.0f, 1.0f, 0.0f, 1.0f},

{0.0f, size, 0.0f, 1.0f, 0.0f, 1.0f},
{size, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f},
{size, size, 0.0f, 1.0f, 1.0f, 1.0f}

device_->CreateVertexBuffer(6*sizeof(Vertex), 0, vertexFormat, D3DPOOL_MANAGED, &vertexBuffer_, NULL);
device_->SetStreamSource(0, vertexBuffer_, 0, sizeof(Vertex));

VOID* pVoid;
vertexBuffer_->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));

Finally, the shader:

float4 DrawTexture(INPUT input) : COLOR {
return tex2D(colorMap, input.coords);

Thanks a lot for any help ...

EDIT: Simplified the code

[Edited by - gabzuka on October 20, 2010 8:04:31 AM]

Share this post

Link to post
Share on other sites
Original post by Nik02
You're filling only the first mip level of the texture.

Wow Nik02, that was it ... thanks a lot, you have no idea how long I spent trying to see where my error was.

I just changed

D3DXCreateTexture(device_, simulationSize_, simulationSize_, 0, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture_);


D3DXCreateTexture(device_, simulationSize_, simulationSize_, 1, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture_);

and it worked, really thanks a lot.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!