Jump to content

TTexture in a class


Rick
 Share

Recommended Posts

I've been out of the LE programming for to long I think :unsure:

 

I have an Actor class that takes a TTexture in it's ctor and stores it in a variable to be drawn later. I then derive other classes from Actor like Knight, Assassin, etc. I then have something like:

 

Knight::Knight(TVec3 position, TVec3 rotation) 
: Actor(LoadMesh("abstract::Knight.gmf"), 
		LoadTexture("abstract::KnightHeadShot.dds"), 
		position, 
		rotation)
{
}

 

So I call LoadTexture() and depending on the class what it loads is different. Then in the Actor::Draw() class I draw the texture. The problem I have is that every draw is drawing the same texture. That TTexture isn't defined as static in Actor so why would I be getting all the same textures being drawn even though I load different textures per class? It's not making sense.

 

Note that I do the same thing with LoadMesh() and that works. I get the correct model loaded. So that's even more confusing as to what is happening.

Link to comment
Share on other sites

Actor::Actor(TEntity model, TTexture headShot, TVec3 position, TVec3 rotation)
{
_model = model;
_headShot = headShot;

PositionEntity(_model, position);
RotateEntity(_model, rotation);
}

class Actor
{
private:
bool _enabled;					// if false they can't do an action
TEntity _model;
TTexture _headShot;
};

Link to comment
Share on other sites

No initial problems here...

 

I assume you're creating objects of the derived classes and that is where you're encountering the issues. What happens when you create objects of the base (actor) class, same result? Or a mix of both base and derived?

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

Yeah I create them with:

 

Actor* actor = new Assassin(pos, rot);

 

 

Nothing is sticking out to me either. I've done stuff like this a hundred times. That's why I'm thinking it might be something with LE's TTexture or LoadTexture() is doing something funky.

 

When I step through the code it's making it into each derived class so it's running each LoadTexture() correctly it seems.

 

Interestingly enough the texture that it's showing for all of them is the Assassin's texture which is the first one loaded.

Link to comment
Share on other sites

try:

'protected:' instead of 'private:' with the base class properties.

 

try:

 

TTexture* _headShot; //as the class property

_headShot = new TTexture(LoadTexture(FileName.c_str())); 
//inside Actor constructor and simply pass "abstract::KnightHeadShot.dds" as a std::string argument

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

I get the same issue with that.

 

Actor::Actor(TEntity model, string headShot, TVec3 position, TVec3 rotation)
{
_model = model;

_headShot = new TTexture(LoadTexture(headShot.c_str()));
}

Assassin::Assassin(TVec3 position, TVec3 rotation) 
: Actor(LoadMesh("abstract::Assassin.gmf"), 
		"abstract::AssassinHeadShot.dds", 
		position, 
		rotation)
{
}

void Actor::DrawHUD(int x, int y, TTexture background)
{
        DrawImage((*_headShot), x, y, imageHeight, imageHeight);
}

Link to comment
Share on other sites

I can't reproduce it Rick, your implementation works for me.

 

Could be some simple oversight like calling the wrong object Draw() method in your loop.

 

Short of sending me your program (which I'd be happy to compile and look through) I'm at a loss.

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...