*sigh* texture related issue.

Started by
13 comments, last by AAAP 18 years, 5 months ago
Hi. My project is setup like this: Player class -> Sprite class -> sprite struct ( 1 sprite class instance per player, and a given number of sprite structs for each sprite class, basically 1 for each animation. sprite class contains a GLuint array for texture IDs after they've been loaded) before, I was binding their textures in the main loop, but I wanted to do things more automatically and do it it in the player class's Draw method instead. to my shock, this doesnt work. It should be visible to the Player class, so why can't I do it from that scope :( by doesn't work, i of course mean that no texture is binded which makes me think it can't see the texture ID, but it should. grr.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
Advertisement
What exactly did you try, and what exactly went wrong? Are you getting compiler errors?
No, it compiles fine. It's just the typical white rectangle you get when it doesnt point to the texture in video memory.

when i do this from Main() in my loop, it will bind, but not when I try to bind in the class::draw() method itself.

its like player -> sprite -> sprite[animation #] -> current image
from main
so i assume doing it from inside the player class i can do just
sprite -> sprite[animation #] -> current image
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
can nobody help me with this? It's getting really annoying, i've tried seemingly everything. the player class SHOULD be able to see the texture array
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
You realize you've shown no code, and you haven't even mentioned what programming language you're using?
I do realize... and the language is C++,

and there would be an awful lot of code to show, so I just gave the gist of it?
class Player{int update_sprites; vec2D Position; size2D Size; vector<Bullet> bullet; Text *t_Pos; Sprite sprite; public:        int NumberOfBullets;        Player(int a);        ~Player();        void Bind( int ID );        void Draw();        void DrawBullet();        void Move(int Direction);        void Shoot(float X, float Y);        void Input();        char* GetX();        float Posx(){ return Position.X; }        float Posy(){ return Position.Y; }};

Theres my player class.
typedef struct t_Sprite{        int ID;        int Used;        int Current_Image;        GLuint Image[16];        t_Sprite(int i)        {          ID = i;          Used = -1;          }};


class Sprite{private:      public:      vector<t_Sprite> spr;       Sprite();       ~Sprite();                    void New(int ID);      void Delete(int ID);            void Update(int ID);      void Add(int ID, const char* filename, int ImageNum);      void Bind( int ID );            //void Update();};

theres sprite class and t_Sprite which should be called animation or something, but its not.
void Player::Draw(){     update_sprites++;if(update_sprites >= 5){update_sprites = 0;sprite.Update(0);}     sprite.Bind(0);       glPushMatrix();       glTranslatef(Position.fX, Position.fY, 0);          glBegin(GL_TRIANGLE_STRIP);          glColor4f(1,1,1,1);                                   glTexCoord2f(0,0); glVertex3f(0     ,  0     , 0);                              glTexCoord2f(1,0); glVertex3f(Size.X,  0     , 0);                              glTexCoord2f(0,1); glVertex3f(0     ,  Size.Y, 0);                              glTexCoord2f(1,1); glVertex3f(Size.X,  Size.Y, 0);          glEnd();     glPopMatrix();}

Heres the Player::Draw method, don't ask about the badly done timing thing there, it's temporary -_-;
void Sprite::Bind( int ID ){      glBindTexture(GL_TEXTURE_2D, spr[0].Image[spr[0].Current_Image]);        //glBindTexture(GL_TEXTURE_2D, spr[0].Image[0]);      //Bind_(&spr[ID]);      //int a = Bind_( &spr[ID] );      //return 0;}

heres the Sprite::Bind method, i had tried lots of things to try and get this to work, used pointers and static members, and all kinds of crap. I really think that because an instance of Sprite is a member of Player, then Player should really be able to see members of it's own sprite instance. if you need me to show anything else, just say so, please.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
Hi,

You might want to try wrapping your code in source tags. Check the faq for details.

So the problem is that the Draw() method is not visible for your instance of Player class?

try adding splitting up your class using 'public:' and 'private:'. In general, public features of a class are your interface for using it and private features are class data you don't want people to touch directly. To just test if this is the solution add 'public:' as the first line in your Player class (above int update_sprites;).

Hope this helps.

Tim Cooper - software developer, project manager and occasional iOS app developer.

Creative Shadows Ltd - My hobby company website

no, even when all the members of sprite, player and my image class are public, same thing.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
That's a lot easier to read now. And you're right, I realised just after I posted that I hadn't found the answer, sorry!

Can you just define what the problem is exactly? Is the problem with the implementation of the Bind method, or in the ability to call the method from the Player class?

Tim Cooper - software developer, project manager and occasional iOS app developer.

Creative Shadows Ltd - My hobby company website

It can be called. Everything compiles fine. Problem is that textures aren't applied to surfaces. Binding to these textures outside of the class works just fine, like

P1 being a Player object:
glBindTextures(GL_TEXTURE_2D,P1.spr[P1.CurrentSprite].P1.spr.Image[P1.spr.CurrentImage]);
^--- this code here works fine, textures are applied no problem.
But it's annoying to have to call this from the main loop.

But when I do this in the Player class' own methods, nothing happens, which makes me think it can't find the texture in memory (though it must find the texture array or else it would give a compile error).

so like, within Player::Draw() i can't use the Bind() method i made up, and i can't use like (GL_TEXTURE_2D, spr[CurrentSprite].spr.Image[spr.CurrentImage]);
which is really strange because its essentially the same thing as calling it from main, just relative to the class instead of to main().


This is to say, that the problem is textures aren't being applied to surfaces, resulting in white rectangles!! There is no compiler error, everything works just dandy, with the exception that for the Player class (the others still bind outside of their class, before running their draw function in main()), Player::Draw() makes calls to bind to a texture (from its child instance of Sprite) but no binding takes place, resulting in a white rectangle.

does this make sense? i don't know how to explain it if it doesnt. it seems to make perfect sense to me, but then again i didnt sleep till 5 this morning.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)

This topic is closed to new replies.

Advertisement