the last of my object troubles

ive being trying unsuccessfully to keep a record of which bitmap is texture mapped to the different objects. The polygon draws fine but without the texture. what am i doing wrong. sorry to bother you again. this is definately the last time.i set up the object something like this and the main code is also below.

typedef struct {
GLfloat x1,y1,x2,y2,x3,y3,x4,y4,z; /* Vertices of polygon */
COGLTexture texture;//texture record
}object_type;

COGLTexture car,car1,car2;

void init_world(world_data ot)
{
/
object 1 - */

ot->object[0].texture = car;
ot->object[0].x1 =  0.0;
ot->object[0].y1 =  0.0;
ot->object[0].x2 =  0.0;
ot->object[0].y2 =  0.2;
ot->object[0].x3 =  0.2;
ot->object[0].y3 =  0.2;
ot->object[0].x4 =  0.2;
ot->object[0].y4 =  0.0;
ot->object[0].z =  0.0;

}

For each object i then call a draw method

void drawPolygon (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3,GLfloat x4, GLfloat y4, GLfloat z, COGLTexture texture)
{
car.LoadFromFile(“tools/car.bmp”);

glEnable(GL_TEXTURE_2D);

texture.SetActive();
glBegin (GL_POLYGON);
glTexCoord2f(1.0,0.0);
glVertex3f (x1, y1, z);
glTexCoord2f(1.0,1.0);
glVertex3f (x2, y2, z);
glTexCoord2f(0.0,1.0);
glVertex3f (x3, y3, z);
glTexCoord2f(0.0,0.0);
glVertex3f (x4, y4, z);
glEnd ();

glDisable(GL_TEXTURE_2D);	

}

What does the texture.SetActive() function look like? That’s a likely candidate for where the problem might be…

that works fine because i had it working before hand when just with polygons before i had to define the object structure. the problem seems that the line ot->object[0].texture = car; doesn’t seem to assign ‘car’ when texture is called. for example when i load in the bitmap “car.LoadFromFile(“tools/car.bmp”);” it doesn’t work but when i load it in like "that works fine because i had it working before hand when just with polygons before i had to define the object structure. the problem seems that the line ot->object[0].texture = car; doesn’t seem to assign ‘car’ when texture is called. for example when i load in the bitmap by “car.LoadFromFile(“tools/car.bmp”);” then it doesn’t work but it works fine if i load it by "texture.LoadFromFile(“tools/car.bmp”);

sorry that came out funny

that works fine because i had it working before hand when just with polygons before i had to define the object structure. the problem seems that the line “ot->object[0].texture = car;” doesn’t seem to assign ‘car’ when ‘texture’ is called. for example when i load in the bitmap by “car.LoadFromFile(“tools/car.bmp”);” then it doesn’t work but it works fine if i load it by "texture.LoadFromFile(“tools/car.bmp”);

You know the texture size has to be of the power of 2. 2, 4, 8, 16, 32, 64, etc.
If it is not the texture will not be drawn.

Also it maybe better for you to load all the textures at once and index them.

example, I have my texture id’s stored in a array:
glBindTexture ( GL_TEXTURE_2D, texture_id ); // where X is the number of the texture that I want to use. You could asign say that car = texture number one.

Draw_object( x, y, z, car ); // then the car is drawn.

Later

Originally posted by rev:
[b]ive being trying unsuccessfully to keep a record of which bitmap is texture mapped to the different objects. The polygon draws fine but without the texture. what am i doing wrong. sorry to bother you again. this is definately the last time.i set up the object something like this and the main code is also below.

typedef struct {
GLfloat x1,y1,x2,y2,x3,y3,x4,y4,z; /* Vertices of polygon */
COGLTexture texture;//texture record
}object_type;

COGLTexture car,car1,car2;

void init_world(world_data ot)
{
/
object 1 - */

ot->object[0].texture = car;
ot->object[0].x1 = 0.0;
ot->object[0].y1 = 0.0;
ot->object[0].x2 = 0.0;
ot->object[0].y2 = 0.2;
ot->object[0].x3 = 0.2;
ot->object[0].y3 = 0.2;
ot->object[0].x4 = 0.2;
ot->object[0].y4 = 0.0;
ot->object[0].z = 0.0;
}

For each object i then call a draw method

void drawPolygon (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3,GLfloat x4, GLfloat y4, GLfloat z, COGLTexture texture)
{
car.LoadFromFile(“tools/car.bmp”);

glEnable(GL_TEXTURE_2D);

texture.SetActive();
glBegin (GL_POLYGON);
glTexCoord2f(1.0,0.0);
glVertex3f (x1, y1, z);
glTexCoord2f(1.0,1.0);
glVertex3f (x2, y2, z);
glTexCoord2f(0.0,1.0);
glVertex3f (x3, y3, z);
glTexCoord2f(0.0,0.0);
glVertex3f (x4, y4, z);
glEnd ();

glDisable(GL_TEXTURE_2D);
}

[/b]

The other thing is it could be a pointer problem, you may have to add * before texture in your object structure.

Originally posted by rev:
[b]sorry that came out funny

that works fine because i had it working before hand when just with polygons before i had to define the object structure. the problem seems that the line “ot->object[0].texture = car;” doesn’t seem to assign ‘car’ when ‘texture’ is called. for example when i load in the bitmap by “car.LoadFromFile(“tools/car.bmp”);” then it doesn’t work but it works fine if i load it by "texture.LoadFromFile(“tools/car.bmp”);[/b]

[This message has been edited by nexusone (edited 04-03-2002).]

Originally posted by rev:
[b]sorry that came out funny

that works fine because i had it working before hand when just with polygons before i had to define the object structure. the problem seems that the line “ot->object[0].texture = car;” doesn’t seem to assign ‘car’ when ‘texture’ is called. for example when i load in the bitmap by “car.LoadFromFile(“tools/car.bmp”);” then it doesn’t work but it works fine if i load it by "texture.LoadFromFile(“tools/car.bmp”);[/b]

Ah, ok, I get it. You might want to check out the copy constructor for your object then… since you’re doing an object to object assignment, rather than an object pointer to object pointer assignment (which just puts the already existing pointer to the already existing object into another containter) what’s actually hapening is that you’re making a copy of your object into the new one.

If you don’t have a copy constructor explicitly declared it will just try to do a binary copy, which usually works ok, but I can’t say what problems it might cause without knowing more about the internals of your objects.

yea…you need to overload the = operator, or do a memcpy, or use pointers. it’s doing a shallow copy the way you have it.

b

thanks, im not really sure about this type of thing, would you know of any good sites that could help.
i was also thinking, would it be a problem having “COGLTexture texture;” in my object definition. all my pictures for texture mapping are declared “COGLTexture pic1, pic2, pic3 etc.” because thats how the texture mapping is all set up and “texture” is not actually a picture

I just did a google search for “C++ tutorials” (no quotes) and it returned what looked like a bunch of good links, “C++ tutorials copy constructor” also seemed to get right at this issue, if you want to skip the rest of the stuff.