PDA

View Full Version : some matters on glShadeModel(GL_SMOOTH);



mycral
03-16-2010, 05:15 AM
(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
//////////////////////////////////////////////////////////////

Ehsan Kamrani
03-16-2010, 07:32 AM
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.

zeoverlord
03-16-2010, 11:14 AM
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.

dorbie
03-16-2010, 12:22 PM
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/gdc_ogl_multisample.html

mycral
03-16-2010, 07:02 PM
OK! Thanks!
Flowing your suggestion I solve the problem. As you said,every vertex has its own normal vetcor!