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(2PIlg/(double) numLongitudes)r;
y = sin(2PIlg/(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(2PIlg/(double) numLongitudes)r;
y = sin(2PIlg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
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(2PIlg/(double) numLongitudes)r;
y = sin(2PIlg/(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(2PIlg/(double) numLongitudes)r;
y = sin(2PIlg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
I’m not sure if this is a good idea…BUT…
maybe you could do this
have a texture with a small dark dot on it…with the rest of the image with
alpha = 0
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 !