user2081554
user2081554

Reputation:

OpenGL and GL_SMOOTH shading

I'm having problems with my shading.

I exported my model from SolidWorks to .wrl file. I read this file and show it with glShadeModel(GL_SMOOTH), result is not smooth object joust like in GL_FLAT mode.

RESULT: http://shrani.si/f/2y/Ah/E8gXzGH/model.png

Its funny beacuse when i draw glutSolidSphere(1,10,10) the sphere is smooth. Im wondering what im doing wrong? Do i have to calculate shading colour for every vertex at the time or i have to change something globaly in my program? It should be easy fix right?

Code for initializing OpenGL :

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(31, float(screen_px[0])/screen_px[1],0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0,0,0,0,0,-1,0,1,0)
glEnable(GL_DEPTH_TEST)
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glDepthFunc(GL_LESS)
glShadeModel(GL_SMOOTH)
glClearColor(0.5, 0.5, 1, 1)
glMaterial(GL_FRONT, GL_AMBIENT,  (0.5, 0.5, 0.5, 1))
glMaterial(GL_FRONT, GL_DIFFUSE,  (0.8,0.8,0.8,0.8))
glMaterial(GL_FRONT, GL_SPECULAR, (0.4, 0.4, 0.4, 1))
glMaterial(GL_FRONT, GL_SHININESS, (128))
glLight(GL_LIGHT0, GL_POSITION,  (100, 100, 0, 1))
glLight(GL_LIGHT0, GL_AMBIENT,  (0.4,0.4,0.4,0.4))
glLight(GL_LIGHT0, GL_DIFFUSE,  (0.4,0.4,0.4,0.4))
glLight(GL_LIGHT0, GL_SPECULAR, (0.4,0.4,0.4,0.4))

Code for drawing

Upvotes: 0

Views: 2966

Answers (1)

genpfault
genpfault

Reputation: 52167

single glNormal() call per face

If you want smooth shading you have to provide a different normal for each vertex of a triangle.

EDIT: If all you have are face normals you can average the face normals for a vertex to get smoother per-vertex normals.

Upvotes: 2

Related Questions