Note that there are some explanatory texts on larger screens.

plurals
  1. POdx texture don't change on time?
    primarykey
    data
    text
    <p>I'm rendering 2D sprites with DX9 using a vertex buffer (DrawPrimitive). some animations got different texture files with different sizes. </p> <p>Now I get the following problem: on the very single frame where I'm switching between two animations that have different texture files (for example when start walking or when finish walking and begin standing), it's rendering with the coordinates for the <em>new</em> texture, but still presenting the old texture. This looks as if I did'nt set the texture for the new animation. only problem is - I did.</p> <p>How I understood what's the problem: I took a screenshot right on that frame, and noticed that it renders one texture with coordinates fitting to the other texture.</p> <p>In my rendering function I first get the new texture and send it to DX, than calculating the coords, and in the end I render my vertices with the coords and the new texture set. I checked and debugged it million times and all the values are correct, and yet the bug happens.</p> <p>any ideas why this might happen?</p> <p>thanks!</p> <p>Edit: added some code:</p> <pre><code> // Render a quad using the vertex buffer void CGraphicsManager::RenderQuadViaVertexBuffer(const SVertex* pVertices) const { // Increase renders count this-&gt;m_RenderCount++; // vb_vertices now points to our vertices inside the Vertex buffer, so // to fill in our VB, we copy to vb_vertices. memcpy(this-&gt;m_pVertexBufferBuffPtr + this-&gt;m_OffsetInVertexBuffer, pVertices, sizeof(SVertex) * (VERTICES_IN_QUAD)); // Render the rectanlge using the vertices we got. this-&gt;m_pD3dDevice-&gt;DrawPrimitive(D3DPT_TRIANGLESTRIP, this-&gt;m_OffsetInVertexBuffer, PRIMITIVES_IN_QUAD); // Increment the offset in the vertex buffer this-&gt;m_OffsetInVertexBuffer += VERTICES_IN_QUAD; } // Render a quad void CGraphicsManager::Render(const STexture&amp; p_Texture, SLocation p_RenderLocation, SSize p_RenderSize, const SQuad&amp; p_TextureQuad, SfColor p_RenderColor, ERenderEffects p_RenderEffect) const { // Set render effect this-&gt;SetRenderEffect(p_RenderEffect); // Set texture this-&gt;SetTexture(p_Texture); // Set the vertex needed for the rendering VerticesForQuadRender[0].Position.x = p_RenderLocation.x; VerticesForQuadRender[0].Position.y = p_RenderLocation.y; VerticesForQuadRender[0].Position.z = 0.0f; VerticesForQuadRender[0].color = p_RenderColor; VerticesForQuadRender[0].tv = p_TextureQuad.left; VerticesForQuadRender[0].tu = p_TextureQuad.top; VerticesForQuadRender[1].Position.x = p_RenderLocation.x + p_RenderSize.x; VerticesForQuadRender[1].Position.y = p_RenderLocation.y; VerticesForQuadRender[1].Position.z = 0.0f; VerticesForQuadRender[1].color = p_RenderColor; VerticesForQuadRender[1].tv = p_TextureQuad.right; VerticesForQuadRender[1].tu = p_TextureQuad.top; VerticesForQuadRender[2].Position.x = p_RenderLocation.x; VerticesForQuadRender[2].Position.y = p_RenderLocation.y + p_RenderSize.y; VerticesForQuadRender[2].Position.z = 0.0f; VerticesForQuadRender[2].color = p_RenderColor; VerticesForQuadRender[2].tv = p_TextureQuad.left; VerticesForQuadRender[2].tu = p_TextureQuad.bottom; VerticesForQuadRender[3].Position.x = p_RenderLocation.x + p_RenderSize.x; VerticesForQuadRender[3].Position.y = p_RenderLocation.y + p_RenderSize.y; VerticesForQuadRender[3].Position.z = 0.0f; VerticesForQuadRender[3].color = p_RenderColor; VerticesForQuadRender[3].tv = p_TextureQuad.right; VerticesForQuadRender[3].tu = p_TextureQuad.bottom; this-&gt;RenderQuadViaVertexBuffer(VerticesForQuadRender); } // Starts a rendering frame bool CGraphicsManager::StartFrame() { // Clear texture this-&gt;ClearTexture(); // Zero renders count this-&gt;m_RenderCount = 0; // Clear screen if (!this-&gt;ClearScreen()) { this-&gt;ResetDevice(); return false; } // Begin new rendering scene if (FAILED(this-&gt;m_pD3dDevice-&gt;BeginScene())) { this-&gt;ResetDevice(); return false; } // Set render from our vertex buffer this-&gt;BeginRenderFromVertexBuffer(); return true; } // Finish rendering bool CGraphicsManager::EndFrame() { // Unlock vertex buffer this-&gt;m_pVertexBuffer-&gt;Unlock(); // Notify the device that we're finished rendering for this frame if (FAILED(this-&gt;m_pD3dDevice-&gt;EndScene())) { this-&gt;ResetDevice(); return false; } // Present scene if(FAILED(this-&gt;m_pD3dDevice-&gt;Present(NULL, //Source rectangle to display, NULL for all of it NULL, //Destination rectangle, NULL to fill whole display NULL, //Target window, if NULL uses device window set in CreateDevice NULL ))) //Dirty Region, set it to NULL { this-&gt;ResetDevice(); return false; } // Finish rendering return true; } // This function must be called before rendering textured surfaces void CGraphicsManager::BeginRenderFromVertexBuffer() const { // Lock the vertex buffer (unlock on release) and get the pointer to the begining of the buffer HRESULT hr = this-&gt;m_pVertexBuffer-&gt;Lock (0, // Offset, we want to start at the beginning 0, //SizeToLock, 0 means lock the whole thing (void**)&amp;this-&gt;m_pVertexBufferBuffPtr, //If successful, this will point to the data in the vertex buffer 0); ASSERT(SUCCEEDED(hr), "Failed to lock vertex buffer! (err: " &lt;&lt; hr &lt;&lt; ")"); // Set offset in vertex buffer back to 0 this-&gt;m_OffsetInVertexBuffer = 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload