Results 1 to 3 of 3

Thread: How to add dark spots to a surface like that

  1. #1
    Guest

    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)*rscale*deform;
    r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
    x = cos(2*PI*lg/(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*PI*lg/(double) numLongitudes)*r;
    y = sin(2*PI*lg/(double) numLongitudes)*r;
    glNormal3f(x,y,z);
    glVertex3f(x,y,z);
    }
    }
    glEnd();
    }


    glPopMatrix();
    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to add dark spots to a surface like that

    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:
    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)*rscale*deform;
    r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
    x = cos(2*PI*lg/(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*PI*lg/(double) numLongitudes)*r;
    y = sin(2*PI*lg/(double) numLongitudes)*r;
    glNormal3f(x,y,z);
    glVertex3f(x,y,z);
    }
    }
    glEnd();
    }


    glPopMatrix();
    }

  3. #3
    Member Contributor
    Join Date
    Jul 2001
    Location
    Sherbrooke
    Posts
    95

    Re: How to add dark spots to a surface like that

    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*
    Let's have a funny day

Similar Threads

  1. Replies: 0
    Last Post: 10-05-2008, 10:44 PM
  2. The spots
    By Mazy in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-11-2003, 08:17 AM
  3. Dark textures in a dark scene
    By nexusone in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-30-2002, 07:33 AM
  4. HOW CAN I DRAW SPOTS in Visual Basic 6
    By mojiro in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-10-2002, 02:19 AM
  5. Help on Drawpixel or elimination of small black spots
    By jojozhong in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-21-2000, 02:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean