OpenGL texture issue

Hi,

I am trying color a wavefront OBJ 3D model using a PNG file. The model is superimposed on a background and the PNG file is extracted from the background image. I notice that the blending could be better, though the texture parameters seem to work fine. I have given the code below. Any pointers as to which other parameters I could use? Appreciate any help in this matter.

John


glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glShadeModel(GL_SMOOTH);

Since want to use mipmaps, your filering could be set to:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

…You should use glGenerateMipmap (GL_TEXTURE_2D) to actually create the mipmaps for you.

Also, you have not mentioned how you are doing the blending and what blend state you have set.

Here’s what I do to blend -

… called after above parameters are set …

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

“I notice that the blending could be better”
Then you will have to describe what happens and what you expect instead in more precise manners.

The model is a NURB surface and I notice that the surface slightly to the back are a bit darker. Well, to be more precise, imagine the 3D object as a nose… i see the nostril edges and the top of the nose (near the eyes) are a shade darker. I have checked the normals and they are correct.

Do you need lighting ? Otherwise disable it. And make sure you draw everything with pure white color.

Thanks for the clues. When I disable lighting, I see only see the nose outline with the color from the PNG file filled in. But the color is now uniform and shaded equally. Is there a way to keep this uniformity but also see the NURB surfaces properly (I mean see the nostrils, the top of the nose etc)

I need a screenshot, with both the unmodified png texture, and the current render result.

2 screenshots attached -

  1. With lighting - entire surface visible but surfaces at the back are darker(the edges of the nostrils).

  2. No lighting - entire surface uniformly colored but cant make out 1 surface from another.

Both results are expected.
In fact I still do not understand what you want instead.

Maybe move the lighting above the head, so it looks more realistic ? We humans are used to have the sun up in the sky.

Here’s what I want - I want to overlay the NURB surface (the nose in this case) on top of a 3D human face and blend it. I extract the color from the background, use CGContextDrawImage and use the image to color the nose surface. The blending function I use is given below
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

Any ideas how I can better it? May be I could use another blending function?

Appreciate your help thus far.

By “better it” I mean the color that is rendered is a shade darker than what is expected. Can it be interpolated with a white color? Can I use a shader? If so, how?

Thanks in advance for your help.