Archived

This topic is now archived and is closed to further replies.

I 'm not able to aply the texture to my 3D object

This topic is 4953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, ok, I''ll put you into the situation. I have a window where I render the images captured from a web cam, and at the same time where I overlay a 3D object, which I can successfully load from a .3ds file; this is I''m mixing the camera images and the object==>I look for a reference in the captured image and I obtain the matrix for positioning the object (like ARToolkit does...if somebody knows about it) The problem is that I''m also loading the texture (a .bmp file) for that object but when drawing the object, I just can see a plane color object, of course with shades and light effects, but ..no texture. I''ve been surfing on the web and I could find some examples for mapping textures using OpenGl and actually I could get an example to work...soooo, this is making me think that there must be some option when drawing the video frame or even when creating the window that disable the texture for the object, or probably I don''t draw the object in the proper order.....did anyone try it before?? I don''t know too much about OpenGl so.... please help!!!! I can post some of the code if somebody needs to take a look for some mistake...

Share this post


Link to post
Share on other sites
Possibilties i can think of:
1. Didn''t enable GL_TEXTURE_2D
2. Didn''t bind the texture
3. Didn''t specifiy UV texture coords
4. The image is not a power of 2, remember it must be a power of two
5. incorrect uploading of texture to opengl
6. Didn''t change Texture filtering to GL_LINEAR, because opengl Defaults to mipmaps, and you may/mayynot have these generated.


well thats all the things I can think up.

"I seek knowledge and to help those who also seek it"

Share this post


Link to post
Share on other sites
this is what I''m doing:

/*loading the .bmp file*/

MyTextura.LoadFromFile(archivo_textura);//this is working ok!!
glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

*once a get my matrix for positioning I do this everytime after capturing a video frame:
1.- i get the matrix for positioning ==>trans
2.- and execute this routine:
{
GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0};
GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0};
GLfloat mat_flash_shiny[] = {50.0};
GLfloat light_position[] = {100.0,-200.0,200.0,0.0};
GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1};
GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1};

GLfloat LightPos[] = {0.25f,0.4f,1.0f,0.0f};
GLfloat LightAmb[] = {0.0, 0.0, 0.0, 0.0};
GLfloat LightDif[]= {1.0f,1.0f,1.0f,1.0f};
GLfloat LightSpc[]= {1.0f,1.0f,1.0f,1.0f};





glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);


argDraw3dCamera( 0, 0 );/*==>(this function comes like this and in this case it does the following:*/
// ________________________________________________________
//glViewport(0, gWinYsize-(int)(gZoom*gImYsize),
// (int)(gZoom*gImXsize), (int)Zoom*gImYsize));
//
// glMatrixMode(GL_PROJECTION);
// glLoadMatrixd( gl_cpara );
// glDisable(GL_STENCIL_TEST);
// glStencilFunc (GL_ALWAYS, 0, 0);
// glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
// _________________________________________________________

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity()
glEnable(GL_TEXTURE_2D);
MyTextura.SetActive();



/* load the camera transformation matrix */
argConvGlpara(trans, gl_para);//just converts into an array
//glLoadMatrixd( gl_para );
glMultMatrixd(gl_para);



glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDif);
glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpc);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);


/* this is for drawing the object*/

for (i=0;i {
for (k=0; kGetFaceCount(); k++)
{
face = scene.GetMesh(i)->GetFace(k);
glBegin(GL_TRIANGLES);
glTexCoord2f(face.uv[0].u,face.uv[0].v);
glNormal3f(face.normals[0].x, face.normals[0].y, face.normals[0].z);
glVertex3f(face.vertices[0].x, face.vertices[0].y, face.vertices[0].z);
glTexCoord2f(face.uv[1].u,face.uv[1].v);
glNormal3f(face.normals[1].x, face.normals[1].y, face.normals[1].z);
glVertex3f(face.vertices[1].x, face.vertices[1].y, face.vertices[1].z);
glTexCoord2f(face.uv[2].u,face.uv[2].v);
glNormal3f(face.normals[2].x, face.normals[2].y, face.normals[2].z);
glVertex3f(face.vertices[2].x, face.vertices[2].y, face.vertices[2].z);
glEnd();
}
}
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH_TEST );
glDisable(GL_CULL_FACE);
}

3.- after that I go back to capture a new frame and begin in 1.- again

Share this post


Link to post
Share on other sites
ok, sorry. Can you see in the code a function called MyTexture.SetActive()?, I bind the texture there:

void COGLTexture::SetActive()
{
glBindTexture( GL_TEXTURE_2D, ID);
}


-------------------------------
inside the function Mytextura.LoadFromFile("texture.bmp"). This does the following:

void COGLTexture::LoadFromFile(char *filename)
{
Image = auxDIBImageLoad( (const char*) filename );
if (Image==NULL)
exit(0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1,&ID);
glBindTexture( GL_TEXTURE_2D, ID);
Width = Image->sizeX;
Height = Image->sizeY;
gluBuild2DMipmaps(GL_TEXTURE_2D,3,Image->sizeX,
Image->sizeY,GL_RGB, GL_UNSIGNED_BYTE,Image->data);
delete Image;
}





[edited by - hellsinn0 on May 20, 2004 3:32:41 AM]

Share this post


Link to post
Share on other sites
What is the size of your texture?
Also, you might want to use a better way to load textures, rather than GLAUX. I think there are some tutorials on nehe.gamedev.net about making your custom texture loader.

Share this post


Link to post
Share on other sites
ok, I''ve checked again about this, and the size of the image is not a power of , I have Width=283 and height=212. But, and here comes the newbeen question. Why am I able to see the same texture in a very simple example, I mean,I just make the window and show a sphere turning around with the texture on it, but I cannot see it when I try to overlay it with the captured video images using the code I posted above????

is there anything wrong in the way I''m doing it??

Share this post


Link to post
Share on other sites
Hey, I discovered something new

When loading the textures in my code with this:
//filename is "texture.bmp"
{
Image = auxDIBImageLoad((const char*) filename );
if (Image==NULL)
exit(0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1,&ID); ==>after this line I always get ID=0;
.
.
.
.bla bla bla...
}

and in the example I can get to work I always get ID=1.
I read somewhere ID=0 is the default OpenGl texture, so...is this probably why I cannot see the texture??

How can I fix it?

Share this post


Link to post
Share on other sites
quote:
Original post by Raduprv
Yes, ID==0 means baaaad
Like I said, make your own texture loading function (check the NeHe tutorials).


could you tell me exactly where to find it, an easy way I mean. It just mean to me a bounch of code lines and I don''t know exactly what I need to make my own loader.
By the way, why am I getting ID=0? if I''m loading the texture in the same way than in the example??

Share this post


Link to post
Share on other sites
heyyyyyyyyyyyyyy , I got a diferent number!!! yeahhh

ok, my fisrt error was==> I was loading the texture before CREATE THE WINDOW!!!! uppss...didn''t think it was important!!! as you guys can see I''m totally bad in this...ok now I''m getting after loading the texture ID=5, let''s see if it works now!!! I''ll let you know it!! hehehehe :D

Share this post


Link to post
Share on other sites
quote:
Original post by Raduprv
I don''t even think GL_TEXTURE exists.


It''s defined as 0x1702... at least in my version of gl.h.

I could''ve sworn that fixed the problem I was having once, but then again, it''s quite possible I modified something else at the same time.

Share this post


Link to post
Share on other sites
it''s not working!!! why????
I don''t understand anything.....I''m getting an ID=5, but when binding the texture I just can see a totally plane white circle shape. If don''t bind the texture at least a can see the 3D sphere!!! I''m desperated!!

Share this post


Link to post
Share on other sites
One thing I noticed is that when you first load your texture, you're using mipmaps to build your texture:

gluBuild2DMipmaps(GL_TEXTURE_2D,3,Image->sizeX,
Image->sizeY,GL_RGB, GL_UNSIGNED_BYTE,Image->data);


However, you're specifying GL_LINEAR for both *MIN_FILTER and *MAG_FILTER. I'm not sure if this would cause the problem, but try using this instead of gluBuild2DMipmaps:

glTexImage2D(GL_TEXTURE_2D, 0, 3, Image->sizeX,
Image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Image->data);

~Urayami

[edited by - urayami on May 20, 2004 3:12:04 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by hellsinn0
it''s not working!!! why????
I don''t understand anything.....I''m getting an ID=5, but when binding the texture I just can see a totally plane white circle shape. If don''t bind the texture at least a can see the 3D sphere!!! I''m desperated!!


Is your texture now a power of 2 in size? thats generally what you get when the texture isnt a power of 2 in size.

Share this post


Link to post
Share on other sites
GUYS!!!!!!! I could make it!!! guys!!!!! and don't know why but this thing suddenly worked !!!!


now, I'm able to see the texture in the simple sphere...so my challenge will be mapping different textures in a virtual laboratory I have made using 3ds max. wish me luck!!! otherwise I'll be around here bothering people, you guys. Thanks a lot to all you guys!!!

sincerely

Begoña.- the happiest one, right now!! hehe yeeeep!!

by the way....I can also render bmp files that are not power of 2!!! isn't it weird???

[edited by - hellsinn0 on May 20, 2004 4:06:53 PM]

the last thing...is it normal to loose the shading efects?? now when I'm able to see the texture, the sphere looks kinda artificial, i don't have shades any more

[edited by - hellsinn0 on May 20, 2004 4:21:56 PM]

Share this post


Link to post
Share on other sites