PDA

View Full Version : Opengl Color And Lighting



senem
11-18-2007, 07:30 AM
I use glColor3fv and glVertex3fv functions to render object. I used fallowing parameters before rendering.
There are some problems with colors and lighting. Object doesn't seem as a solid object. It seems as if it is transparent.
And colors are sliding.

How can I change these fallowing parameters to make the object solid and correct colors?


glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);

Zengar
11-18-2007, 08:14 AM
What does "seems like transparent" and "colors are sliding" mean? It is is transparent, disable the blending. Also, you are enabling texturing but aren't using any (as fas I understood)?

senem
11-19-2007, 04:04 AM
I use texture for some vertexes and colors for some vertexes at the same object. I use them partially at the same object.
But, there are some problems texture mapping and colors when I use them together at the same object.
Colors seems to be foggy and object seems to be transparent.
Texture mapping side is mixed with colors.
I want to make them clear (some parts in colors, some parts in texture mapping).

How can it be ?

Zengar
11-19-2007, 04:20 AM
If texturing is enabled, texture and vertex color are mixed together. You can't just enable the texture on some vertices and disable it on the others. I recommend you separating your object into triangles that need texturing and triangles that don't, and draw them separately. Or you can edit your texture, so it will emulate vertex colors.

Another (but probably very messy, as it will require vertex duplication) implementation would be this:

1. use the GL_MODULATE texture envoronment (glTexEnv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) - this couses the texture and vertex colors to be multiplied
2. for triangles that should be textured, use white vertex color
3. for triangles that should be only colored using vertex color use white texture parts

senem
11-20-2007, 02:36 PM
Texture (with .tga mapped) is mixed with color parts. And object seems to be transparent. But vertex coordinates are correct. What can be the problem and solution?

Code is like following :
glPushMatrix();
glPushMatrix();
glDisable(GL_TEXTURE_2D);
glBegin (GL_TRIANGLES);
glColor3fv;
glVertex3fv;
glEnd ();
glPopMatrix();

glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBegin (GL_TRIANGLES);
glTexCoord2f;
glVertex3fv;
glEnd ();
glPopMatrix();
glPopMatrix;

senem
11-21-2007, 02:29 PM
When I use two colors in one object(some parts of object is red, some parts of object is yellow for example), colors are mixed.
Because object seems to be transparent. So colors are mixed. If I make object as a solid, I don't think it will be a problem with colors.

How can I make the object as a solid?


{ So one side of object will be red, other side will be yellow for example }

senem
11-21-2007, 02:40 PM
When I use fallowing procs, and object is not transparent, then colors are mixed again.
How can I prevent mixed colors?
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(TRUE);

ZbuffeR
11-22-2007, 10:52 AM
It is very hard to understand your problems.
If you can not explain in english, please post images (not too big !) showing the problem, and the result you want to get.

senem
11-22-2007, 02:06 PM
Texture image(.tga) has pink flowers on it. Some parts of object are covered with this texture image. Some parts of object have red color. When I rendered this object, texture image color is changed. Pink flowers changed as red. I think colors are mixed.

I want to see texture image correctly.

That's the problem.

ZbuffeR
11-22-2007, 04:20 PM
Try the DECAL texture mode : where the texture is, only the texture show up, outside the texture or for alpha parts, it is the object color. You need to have proper rgba texture, with alpha "holes" if you need it.
glTexEnvi( GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);

Can you please post images if you still have problems ?

senem
11-23-2007, 02:01 AM
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

This proc call solved the problem for texture image.
So texture image doesn't mix with color.

Some parts of object are covered with texture image(.tga). Some parts of object are red color, some parts of object are yellow.
The problem is solved on texture image.

But there is still same problem for color. Red color and yellow color are mixed in same object.

1-) What can be solution for it ?
2-) How can I send .jpg file? I don't see any attachment on this forum.

ZbuffeR
11-23-2007, 03:55 AM
You need to upload your image to a website (you can find plenty, search for "image hosting", ie try http://imageshack.us/ , then :
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=faq#image

To avoid color interpolation between vertices, use glShadeModel(GL_FLAT);, each polyon color will be from its last vertex color. Search the man pages for details.

http://www.opengl.org/sdk/docs/man/