Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: some matters on glShadeModel(GL_SMOOTH);

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2010
    Posts
    6

    some matters on glShadeModel(GL_SMOOTH);

    (Sorry ! my english not very good)Does opengl smooth need some prerequisite
    Recently I draw the earth on the computer but I find that my code can't realize antialias.And I am sure that there must someting wrong in blow codes,but I do not know where the error.

    this is my code :
    //////////////////////////////////////////////////////////////

    void DrawEarth(float radius,int h_slip,int l_slip)
    {
    //
    float alpha_step = 2*PI/h_slip;
    float beta_step = PI/l_slip;
    float alpha = 0.0f;
    float beta = PI;
    //
    float x = 0;
    float y = 0;
    float x_step = 1.0f/h_slip;
    float y_step = 1.0f/l_slip;

    int i;
    int j;

    for(i=0;i<l_slip;i++){
    glBegin(GL_TRIANGLE_STRIP);
    for(j=0;j<h_slip;j++)
    {

    }
    glEnd();
    }


    glBegin(GL_QUADS);
    for(i=0;i<l_slip;i++){
    for(j=0;j<h_slip;j++)
    {
    glNormal3f(sin(beta)*cos(alpha),sin(beta)*sin(alph a),cos(beta));
    glTexCoord2f(x,y);
    glVertex3f(radius*sin(beta)*cos(alpha),radius*sin( beta)*sin(alpha),radius*cos(beta));

    alpha += alpha_step;
    glTexCoord2f(x+x_step,y);
    glVertex3f(radius*sin(beta)*cos(alpha),radius*sin( beta)*sin(alpha),radius*cos(beta));

    beta -= beta_step;
    glTexCoord2f(x+x_step,y+y_step);
    glVertex3f(radius*sin(beta)*cos(alpha),radius*sin( beta)*sin(alpha),radius*cos(beta));

    alpha -=alpha_step;
    glTexCoord2f(x,y+y_step);
    glVertex3f(radius*sin(beta)*cos(alpha),radius*sin( beta)*sin(alpha),radius*cos(beta));

    beta += beta_step;
    x += x_step;

    alpha +=alpha_step;
    }
    x =0.0f;
    y += y_step;
    alpha = 0.0f;
    beta -= beta_step;
    }
    glEnd();
    }//endfunc
    //////////////////////////////////////////////////////////////

  2. #2
    Advanced Member Frequent Contributor Ehsan Kamrani's Avatar
    Join Date
    May 2005
    Location
    Iran
    Posts
    547

    Re: some matters on glShadeModel(GL_SMOOTH);

    I guess you mean "smooth shading".
    I have no idea about the algebra used in your code, but in a usual code, each vertex has its own normal vector. In your code you have specified one normal vector for 4 vertexes.
    <span style="color: #006600">-Ehsan-</span>

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    748

    Re: some matters on glShadeModel(GL_SMOOTH);

    glShadeModel(GL_SMOOTH) affects how lights interpolate between vertics, to make it work you have to have gl lights activated and the correct normals set.
    The most common problem with this is that the normals are set to the face normal and not averages with neighboring faces
    This is not anything like antialising

    Looking over your code i can't see anything obviously wrong with it.

  4. #4
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: some matters on glShadeModel(GL_SMOOTH);

    glShadeModel determines how colors between vertices are interpolated.

    To get antialiasing you need to implement that specifically.

    There are several techniques but the simplest most common and most robust for a scene with triangles is multisample.

    Read here:

    http://developer.nvidia.com/object/g...ltisample.html

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2010
    Posts
    6

    Re: some matters on glShadeModel(GL_SMOOTH);

    OK! Thanks!
    Flowing your suggestion I solve the problem. As you said,every vertex has its own normal vetcor!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •