[SOLVED] Drawing a model and a terrain goes wrong

Hi guys!

I’m doing an assignment where I need to draw a terrain with light, camera, a tank model and apply movement to the tank.

Everything was fine until I started to draw the tank, for some reason, the texture that I applied to the terrain is not on the terrain anymore.

To be honest I have no idea what’s happening, I’ve already spent a few hours trying to figure out what’s happening but with no progress.

Here’s my git rep
https://github.com/tiagocosta29/IP3D_2017 - develop branch

Terrain without the tank

Terrain with the tank

I’m sorry to bother you guys and thank you for your time!

Is the only difference between those screenshots the addition of the tank.DrawTank(camera); line?

Yes, that’s the only difference

What are those “test” files? Have you tried with a different model?

And can you try with an updated version of MG?

You need to set your Terrain’s buffers before calling DrawIndexedPrimitives.

When you call Terrain::GetVertices() in your Terrain constructor you’re setting the vertex buffer but that isn’t the correct place to do it. You need to do it before you draw your terrain and make sure it is rebound EVERY time you draw your terrain, not in your constructor.

You can still do the work of GetVertices() and such, but don’t bind the buffers - unless it’s a “throwaway” object intended for use in a “using” block you should never be doing that.

In short, your buffer bindings are being scrambled by the tank.

I have no idea what you have going on with the index buffer for the terrain. Looks like you’re not using it and triangle_strip rendering is just figuring things out … which is another way for everything to be mangled if that’s the case as you probably still have your Tank’s index buffer bound as well.

30 second run down on working with graphics APIs: it’s all one big state-machine. Anything you set or activate will remain set or active until you change it. So before you do anything you need to make sure you’ve set the conditions to those that you desire to do what you want.

Here, you’ve set the buffer, but done it in the wrong place - so it worked, until you introduced something (the tank) that exposed that your state sequence was brittle.

1 Like

Thank you! It worked. I changed my index buffer and vertex buffer to the draw method and now works.

You’re a life savior :smiley: