Sign in to follow this  
luckyyyyyy

How to change the color of model

Recommended Posts

this is a triangular model.... default color:(light color + material Color) when tool doesn’t touch the surface... color of only cutting part should change when tool touch the surface of model... and when tool move deeper and deeper i want to change the color of cutting part only...i tried but no success... i need to apply color of those vertices that pushed due to the tool sphere....but i want not any effect to whole other model How can i do this...... here is the link of image.....for more detail....please open this URL...thanks http://aycu01.webshots.com/image/40800/2001879489635176397_rs.jpg

Share this post


Link to post
Share on other sites
I would use a static VBO that stores vertex, texture coord, normals
and another VBO that stores color (RGBA).
You update the color array when necessary.
If you aren't using shaders, call this

glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

so that it uses the per vertex color instead of glMaterial

Share this post


Link to post
Share on other sites
what do you mean i dont need to apply the material.....only need to apply a color array......but i am not using the VBO,.. currently i am using glVertex3d.....what you suggest like this

glColor3f(R, G, B);
glNormal3dv((double *)&VertNormals[v1]);
glVertex3dv((double *)&p_VERTICES[v1]);

glColor3f(R, G, B);
glNormal3dv((double *)&VertNormals[v2]);
glVertex3dv((double *)&p_VERTICES[v2]);

glColor3f(R, G, B);
glNormal3dv((double *)&VertNormals[v3]);
glVertex3dv((double *)&p_VERTICES[v3]);

but when i initialize the openGL function....what i need to do...means...do i apply light and as well as material of color...or not.......
please suggest me....

Share this post


Link to post
Share on other sites
do you mean like following code.....
then what kind of initializing.......is there any need to initialize with material......or only initialize with apply light...



//glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiMat);
//glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

glNormal3dv((double *)&VertNormals[v1]);
glVertex3dv((double *)&p_VERTICES[v1]);

//glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiMat);
//glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

glNormal3dv((double *)&VertNormals[v2]);
glVertex3dv((double *)&p_VERTICES[v2]);

//glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiMat);
//glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

glNormal3dv((double *)&VertNormals[v3]);
glVertex3dv((double *)&p_VERTICES[v3]);

Share this post


Link to post
Share on other sites
If you call glEnable(GL_COLOR_MATERIAL);
then that means you want GL to use glColor as your material.

glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
is used to tell it that glColor is for changing the material diffuse.

The alternative is not to do the above and instead use glMaterial.

PS : it's better to use float instead of double. GPUs don't support double yet.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this