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

Started by
18 comments, last by hellsinn0 19 years, 11 months ago
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...
:P
Advertisement
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"
"I seek knowledge and to help those who also seek it"
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

:P
Where do you bind it?
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]
:P
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.
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??

:P
Post the code on how you convert your video into a texture.
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?
:P
Yes, ID==0 means baaaad
Like I said, make your own texture loading function (check the NeHe tutorials).

This topic is closed to new replies.

Advertisement