PDA

View Full Version : the last of my object troubles



04-03-2002, 08:31 AM
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);
}

kabir
04-03-2002, 08:35 AM
What does the texture.SetActive() function look like? That's a likely candidate for where the problem might be...

04-03-2002, 08:47 AM
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");

04-03-2002, 08:50 AM
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");

nexusone
04-03-2002, 08:51 AM
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[X] ); // 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:
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);
}

nexusone
04-03-2002, 08:55 AM
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:
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");



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

kabir
04-03-2002, 08:59 AM
Originally posted by rev:
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");

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.

coredump
04-03-2002, 09:36 AM
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

04-03-2002, 09:56 AM
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

kabir
04-03-2002, 10:04 AM
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.