[PyOpenGL-Users] Coloring Nurb Surface
Brought to you by:
mcfletch
From: Michka P. <mic...@gm...> - 2011-02-23 14:34:32
|
Hello I have managed to display a nurb surface. Now I want it to be colored in function of the height (with a color gradient). The documentation doesn't help me a lot, and the tutorials found on the internet are mostly to old or not adapted to my case. (Since most of them are written in C, not adapted to pyOpenGL or not using Nurbs) So here is my code which displays the surface (the controlpoints are random, only here to test if it works) : mat_diffuse = ( 0.7, 0.4, 0.1, 1.0 ) mat_specular = ( 1.0, 1.0, 1.0, 1.0 ) mat_shininess = 100.0 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular) glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_DEPTH_TEST) glEnable(GL_AUTO_NORMAL) glEnable(GL_NORMALIZE) nurb = gluNewNurbsRenderer() gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 20.0) # Space between polygons gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL) ctrlpts = [] grid_size = 15 for u in range(grid_size): ctrlpts.append([]) for v in range(grid_size): ctrlpts[u].append([u, v, 0.0]) ctrlpts[3][3][2] = 1.0 ctrlpts[4][4][2] = 1.0 ctrlpts[3][4][2] = 1.0 ctrlpts[4][3][2] = 1.0 ctrlpts[2][3][2] = 1.0 ctrlpts[4][2][2] = 1.0 degree=3 knot_num = len(ctrlpts) + degree knots = [ float(i)/(knot_num-1) for i in range( knot_num ) ] # Render glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse) gluBeginSurface(nurb) gluNurbsSurface(nurb, knots, knots, ctrlpts, GL_MAP2_VERTEX_3) gluEndSurface(nurb) Now, I have read about GL_MAP2_COLOR_4, but I don't know how and where to use it ? Some say I should tessellate my nurb surface, use a callback function and try to change the color of the vertexes. But How ? Perhaps somebody has a tutorial or some good hints for me ? Thank you Michka Popoff |