Jump to content
  • Advertisement
Sign in to follow this  

VertexBuffer not setting properly?

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

So I'm looking into porting a unity project to XNA (familiar with directX, just not XNA).

Testing a custom mesh type that I'm using by rendering some simple quads and have ran into a problem.

Edit: I think I'm just misunderstanding how this whole drawCall thing works in XNA. Messing with different commenting out arrangements is given me a lot of results compared to what I expected. Does it have something to do with Pass? Is there a way to like commit it?

First frame rendered looks this:


All others this:


Well first off all the red color data is in the otherchild item or the one that doesn't render the first time through for some reason. If I remove the otherchild draw call it becomes white like it should be. If I draw only 1 of the buffers it works fine, but not with 2.

Evidence that otherchild should be Red but not sprite is in the code below. I have also thoroughly verified with a debugger that the data in the VertexBuffer when I call SetData() is correct. So I am positive the issue is with how I am setting the buffers because it is rendering each sprite with the wrong buffer and their is no reference that exists between the 2 sprites that exists.

Sprite sprite = new Sprite();
Sprite otherchild = new Sprite();
Effect basic;
Camera2D camera;
protected override void Initialize()
new GameEngine(this, graphics);
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("SegoeUIMono");
GameEngine.settings = Content.Load<Settings>("XMLFile1");
basic = Content.Load<Effect>("Basic");
otherchild.quad.color = Color.Red;
sprite.transform.scale = new Vector2(2.5f, 2.5f);
otherchild.transform.scale = new Vector2(2.0f,1.0f);
otherchild.transform.localPosition = new Vector3(3.0f, 0.0f, 0.0f);
camera = new Camera2D(0.1f,100.0f,50.0f,50.0f);
camera.transform.localPosition = new Vector3(0.0f, 0.0f, -10.0f);

protected override void Draw(GameTime gameTime)
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Gray,1.0f,0);


SpriteClass Draw() looks like this

public void Draw()
if (quad.hasBuffers)
GameEngine.graphicsDevice.Indices = quad.IndexBuffer;
GameEngine.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,quad.vertices.Length, 0,2);

Any reason that the wrong buffer would be used like that? I'm running out of things to check : / Edited by ChaseRLewis73003

Share this post

Link to post
Share on other sites
Hi there welcome to gamedev.

I notice your using a custom effect file called Basic, however the code above doesn't show how you tell the shader to use the colour for each quad. Also I'm wondering why your calling GraphicsDevice.Present();

Could you show us the code for your Sprite class, it may help us better answer your question.


Share this post

Link to post
Share on other sites
[sub]its just a.wrong order. try this:[/sub]
[sub]-set effect params[/sub]
[sub]-call Pass.Apply()[/sub]
[sub]and you dont have to call present as this is done in base.Draw().[/sub]

[sub]Edit: [/sub]
[sub]its enaugh to set the params one time per frame, Apply() and draw two or more times, if all params stay the same. otherwise you can update only the per object changing values, Apply again and draw. [/sub] Edited by majorbrot

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!