Jump to content
  • Advertisement


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 5241 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!!

*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};


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


/* load the camera transformation matrix */
argConvGlpara(trans, gl_para);//just converts into an array
//glLoadMatrixd( 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);
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);
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);
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);
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH_TEST );

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)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture( GL_TEXTURE_2D, ID);
Width = Image->sizeX;
Height = Image->sizeY;
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)
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
Yes, ID==0 means baaaad
Like I said, make your own texture loading function (check the NeHe tutorials).

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!