How to add dark spots to a surface like that

Hey,
I have a function that draws an egg, but I would like to add some dark spots to it.
I am first of all having problems finding a good way to describe where do I want the spots to be (oh they must have variable radius too) and the of course coding it.

If you could give moe some hints that could help me get started I would really appreciate.
Thanks
Joan

void egg()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
int lt, lg, numLatitudes=16, numLongitudes=16;
double x,y,z,r=10,rscale=1.5,deform=1.5;
glPushMatrix();
glRotatef(90.0,0.0,1.0,0.0);
//////////1
int jj;
for(lt=0; lt<numLatitudes/2; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscaledeform;
r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscale;
x = cos(2
PIlg/(double) numLongitudes)r;
y = sin(2
PI
lg/(double) numLongitudes)r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
///////////2
for( ; lt<numLatitudes; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI
(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscale;
r = cos(PI
(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscale;
x = cos(2
PIlg/(double) numLongitudes)r;
y = sin(2
PI
lg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}

glPopMatrix();

}

How about looking into texture mapping the spots, I think this would be the best way.

maybe also bump mapping would also improve the image.

Look at a site like nehe.gamedev.net for a tutor on it…

Originally posted by jpuig:
[b]Hey,
I have a function that draws an egg, but I would like to add some dark spots to it.
I am first of all having problems finding a good way to describe where do I want the spots to be (oh they must have variable radius too) and the of course coding it.

If you could give moe some hints that could help me get started I would really appreciate.
Thanks
Joan

void egg()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
int lt, lg, numLatitudes=16, numLongitudes=16;
double x,y,z,r=10,rscale=1.5,deform=1.5;
glPushMatrix();
glRotatef(90.0,0.0,1.0,0.0);
//////////1
int jj;
for(lt=0; lt<numLatitudes/2; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscaledeform;
r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscale;
x = cos(2
PIlg/(double) numLongitudes)r;
y = sin(2
PI
lg/(double) numLongitudes)r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
///////////2
for( ; lt<numLatitudes; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI
(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscale;
r = cos(PI
(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)rscale;
x = cos(2
PIlg/(double) numLongitudes)r;
y = sin(2
PI
lg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}

glPopMatrix();

}[/b]

I’m not sure if this is a good idea…BUT…
maybe you could do this

  1. have a texture with a small dark dot on it…with the rest of the image with
    alpha = 0
  2. draw you egg with mutliple pass
    first pass with the egg texture
    other pass with the dot texture with different rotation and scale in the texture matrix (glMatrixMode(GL_TEXTURE))

the dot textures should blend on the egg texture if you correctly set your texture environnement mode…

This could be a valid solution if you only want to draw some eggs…but maybe it’s suuuuper slow I’m not sure

Good luck it’s an interesting question
please post back when you found an adequate solution to your prob !


Evil-Dog
Let’s have a funny day