Reputation:
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
model[2]=normal vectors for model[0]
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLight(GL_LIGHT0, GL_POSITION,(10, 10,10, 1))
glBegin(GL_TRIANGLES)
j=0
for i in range(0,len(model[2]),1):
glNormal3f(model[2][i][0],model[2][i][1],model[2][i][2])
k=model[1][j]
glVertex3f(model[0][k][0],model[0][k][1],model[0][k][2])
j=j+1
k=model[1][j]
glVertex3f(model[0][k][0],model[0][k][1],model[0][k][2])
j=j+1
k=model[1][j]
glVertex3f(model[0][k][0],model[0][k][1],model[0][k][2])
j=j+1
glEnd()
pygame.display.flip()
Upvotes: 0
Views: 2966
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