Skip to main content
gamedev.net
🔒 Locked

Weird rendering bug

Started by ravett Apr 26, 2004 at 12:41 PM 1 replies 400+ views
Original Post
ravett
ravett
I''ve got a really weird bug and was hoping someone could point me in the right direction... I''ve made a simple sprite class that splits up a texture into a given number of frames and makes a Vertex Buffer with two triangles with proper tex coords. When I try to render the sprite, it always renders two frames forward. If I ask for frame 0, it gives me frame 2. If there are 16 frames (0-15) and I ask for 13, 14 or 15 I get frame 15. If I only have 2 frames it just makes frames 0 and 1 render frame 1. I can get "around" this problem if I ask for frames -2 for frame 0, frame 10 for frame 12, etc... I checked with D3Dspy and my VB is setup like I expect it''s supposed to be, and when I try to render frame 0 I make this call:
(*dev)->SetStreamSource(0, m_pVB, 0, sizeof(SPR_VERTEX));
(*dev)->SetFVF(D3DFVF_SPR_VERTEX);
int start = m_curFrame * 6;
(*dev)->DrawPrimitive(D3DPT_TRIANGLELIST, start, 6);
D3Dspy shows the DrawPrimitive call is made with start = 0, but yet it draws vertices 12-17 as I see them in D3Dspy''s VB data window. If I set m_curFrame = -2, the DrawPrimitive gets called with start = -12... and it draws vertices 0-5... @!#$@#%! any ideas?
SantaClaws
SantaClaws
Just to make sure you know... I see you''ve supplied 6 as the primitive count to the DrawPrimitive call. This would try to draw 6 triangles using a total of 18 vertexes. This value should be the number of triangles you want to draw, not the number of vertexes.
ravett
ravett
@!#@#%!#%! Thanks, that did it... The strangest bugs have the easiest solutions sometimes. I feel stupid now. I have
a string drawing class that didn''t have this problem and if I just looked at the render code in there I would have noticed the only difference between the two class''s rendering was the
string code was correct (it called 2 * m_sString.size()...)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.