Sign in to follow this  

*sigh* texture related issue.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
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;
int NumberOfBullets;
Player(int a);
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

vector<t_Sprite> spr;

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()


if(update_sprites >= 5){
update_sprites = 0;


glTranslatef(Position.fX, Position.fY, 0);


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);


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]);
//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.

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
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:
^--- 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.

Share this post

Link to post
Share on other sites
well if that's the type of thing that would show me, then no .-. i tried both the error flags it showed on MSDN granted it could be out of date or sumin'. ah well i'll work on it tommorow. often the solutions to these things hit me in my sleep.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this