2.5
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 4c621c6ec63bd005c25455b71640f1445cb7d44d..bcb2b8b8e359e389375c629328f833aef7088dd4 100644 (file)
@@ -133,10 +133,8 @@ void EM_init_index_arrays(int x, int y, int z) {} // XXX
 void EM_free_index_arrays(void) {}             // XXX
 #define EM_FGON        0
 EditFace *EM_get_actFace(int x) {return NULL;} // XXX
-int draw_armature(Base *base, int x, int y) {return 0;}        // XXX
-int em_solidoffs;      // XXX
-int em_wireoffs;
-int em_vertoffs;
+
+extern unsigned int em_vertoffs, em_solidoffs, em_wireoffs;
 
 /* check for glsl drawing */
 
@@ -1202,30 +1200,30 @@ static void drawlattice(View3D *v3d, Object *ob)
 
 static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
 {
-       struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
-       ARegion *ar= NULL; // XXX
-       View3D *v3d= NULL; // XXX
+       struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
        EditVert *eve = EM_get_vert_for_index(index);
        short s[2];
 
        if (eve->h==0) {
                if (data->clipVerts) {
-                       view3d_project_short_clip(ar, v3d, co, s, data->pmat, data->vmat);
+                       view3d_project_short_clip(data->ar, data->v3d, co, s, data->pmat, data->vmat);
                } else {
-                       view3d_project_short_noclip(ar, co, s, data->pmat);
+                       view3d_project_short_noclip(data->ar, co, s, data->pmat);
                }
 
                data->func(data->userData, eve, s[0], s[1], index);
        }
 }
-void mesh_foreachScreenVert(void (*func)(void *userData, EditVert *eve, int x, int y, int index), void *userData, int clipVerts)
+
+void mesh_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditVert *eve, int x, int y, int index), void *userData, int clipVerts)
 {
-       struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
-       View3D *v3d= NULL; // XXX
+       struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
        DerivedMesh *dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
 
        data.func = func;
        data.userData = userData;
+       data.ar= ar;
+       data.v3d= v3d;
        data.clipVerts = clipVerts;
 
        view3d_get_object_project_mat(v3d, G.obedit, data.pmat, data.vmat);
@@ -1239,23 +1237,21 @@ void mesh_foreachScreenVert(void (*func)(void *userData, EditVert *eve, int x, i
 
 static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co)
 {
-       struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
-       ARegion *ar= NULL; // XXX
-       View3D *v3d= NULL; // XXX
+       struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
        EditEdge *eed = EM_get_edge_for_index(index);
        short s[2][2];
 
        if (eed->h==0) {
                if (data->clipVerts==1) {
-                       view3d_project_short_clip(ar, v3d, v0co, s[0], data->pmat, data->vmat);
-                       view3d_project_short_clip(ar, v3d, v1co, s[1], data->pmat, data->vmat);
+                       view3d_project_short_clip(data->ar, data->v3d, v0co, s[0], data->pmat, data->vmat);
+                       view3d_project_short_clip(data->ar, data->v3d, v1co, s[1], data->pmat, data->vmat);
                } else {
-                       view3d_project_short_noclip(ar, v0co, s[0], data->pmat);
-                       view3d_project_short_noclip(ar, v1co, s[1], data->pmat);
+                       view3d_project_short_noclip(data->ar, v0co, s[0], data->pmat);
+                       view3d_project_short_noclip(data->ar, v1co, s[1], data->pmat);
 
                        if (data->clipVerts==2) {
-                if (!(s[0][0]>=0 && s[0][1]>= 0 && s[0][0]<ar->winx && s[0][1]<ar->winy)) 
-                                       if (!(s[1][0]>=0 && s[1][1]>= 0 && s[1][0]<ar->winx && s[1][1]<ar->winy)) 
+                if (!(s[0][0]>=0 && s[0][1]>= 0 && s[0][0]<data->ar->winx && s[0][1]<data->ar->winy)) 
+                                       if (!(s[1][0]>=0 && s[1][1]>= 0 && s[1][0]<data->ar->winx && s[1][1]<data->ar->winy)) 
                                                return;
                        }
                }
@@ -1263,13 +1259,15 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0
                data->func(data->userData, eed, s[0][0], s[0][1], s[1][0], s[1][1], index);
        }
 }
-void mesh_foreachScreenEdge(void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts)
+
+void mesh_foreachScreenEdge(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts)
 {
-       struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
-       View3D *v3d= NULL; // XXX
+       struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
        DerivedMesh *dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
 
        data.func = func;
+       data.ar= ar;
+       data.v3d= v3d;
        data.userData = userData;
        data.clipVerts = clipVerts;
 
@@ -1284,25 +1282,25 @@ void mesh_foreachScreenEdge(void (*func)(void *userData, EditEdge *eed, int x0,
 
 static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *cent, float *no)
 {
-       struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; float pmat[4][4], vmat[4][4]; } *data = userData;
-       ARegion *ar= NULL; // XXX
-       View3D *v3d= NULL; // XXX
+       struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; float pmat[4][4], vmat[4][4]; } *data = userData;
        EditFace *efa = EM_get_face_for_index(index);
        short s[2];
 
        if (efa && efa->h==0 && efa->fgonf!=EM_FGON) {
-               view3d_project_short_clip(ar, v3d, cent, s, data->pmat, data->vmat);
+               view3d_project_short_clip(data->ar, data->v3d, cent, s, data->pmat, data->vmat);
 
                data->func(data->userData, efa, s[0], s[1], index);
        }
 }
-void mesh_foreachScreenFace(void (*func)(void *userData, EditFace *efa, int x, int y, int index), void *userData)
+
+void mesh_foreachScreenFace(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditFace *efa, int x, int y, int index), void *userData)
 {
-       struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; float pmat[4][4], vmat[4][4]; } data;
+       struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; float pmat[4][4], vmat[4][4]; } data;
        DerivedMesh *dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
-       View3D *v3d= NULL; // XXX
 
        data.func = func;
+       data.ar= ar;
+       data.v3d= v3d;
        data.userData = userData;
 
        view3d_get_object_project_mat(v3d, G.obedit, data.pmat, data.vmat);
@@ -1314,10 +1312,8 @@ void mesh_foreachScreenFace(void (*func)(void *userData, EditFace *efa, int x, i
        dm->release(dm);
 }
 
-void nurbs_foreachScreenVert(void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y), void *userData)
+void nurbs_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y), void *userData)
 {
-       ARegion *ar= NULL; // XXX
-       View3D *v3d= NULL; // XXX
        float pmat[4][4], vmat[4][4];
        short s[2];
        Nurb *nu;
@@ -1375,7 +1371,7 @@ void nurbs_foreachScreenVert(void (*func)(void *userData, Nurb *nu, BPoint *bp,
 
 static void draw_dm_face_normals__mapFunc(void *userData, int index, float *cent, float *no)
 {
-       Scene *scene= NULL; // XXX
+       Scene *scene= (Scene *)userData;
        EditFace *efa = EM_get_face_for_index(index);
 
        if (efa->h==0 && efa->fgonf!=EM_FGON) {
@@ -1385,9 +1381,10 @@ static void draw_dm_face_normals__mapFunc(void *userData, int index, float *cent
                                        cent[2] + no[2]*scene->editbutsize);
        }
 }
-static void draw_dm_face_normals(DerivedMesh *dm) {
+static void draw_dm_face_normals(Scene *scene, DerivedMesh *dm) 
+{
        glBegin(GL_LINES);
-       dm->foreachMappedFaceCenter(dm, draw_dm_face_normals__mapFunc, 0);
+       dm->foreachMappedFaceCenter(dm, draw_dm_face_normals__mapFunc, scene);
        glEnd();
 }
 
@@ -1409,7 +1406,7 @@ static void draw_dm_face_centers(DerivedMesh *dm, int sel)
 
 static void draw_dm_vert_normals__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
 {
-       Scene *scene= NULL; // XXX
+       Scene *scene= (Scene *)userData;
        EditVert *eve = EM_get_vert_for_index(index);
 
        if (eve->h==0) {
@@ -1426,9 +1423,10 @@ static void draw_dm_vert_normals__mapFunc(void *userData, int index, float *co,
                }
        }
 }
-static void draw_dm_vert_normals(DerivedMesh *dm) {
+static void draw_dm_vert_normals(Scene *scene, DerivedMesh *dm) 
+{
        glBegin(GL_LINES);
-       dm->foreachMappedVert(dm, draw_dm_vert_normals__mapFunc, NULL);
+       dm->foreachMappedVert(dm, draw_dm_vert_normals__mapFunc, scene);
        glEnd();
 }
 
@@ -1806,7 +1804,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em)
        if(v3d->zbuf && (v3d->flag & V3D_ZBUF_SELECT)==0)
                glDisable(GL_DEPTH_TEST);
 
-       if(v3d->zbuf) bglPolygonOffset(5.0);
+       if(v3d->zbuf) bglPolygonOffset(v3d->dist, 5.0);
        
        if(G.f & G_DRAW_EDGELEN) {
                UI_GetThemeColor3fv(TH_TEXT, col);
@@ -1941,7 +1939,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em)
        
        if(v3d->zbuf) {
                glEnable(GL_DEPTH_TEST);
-               bglPolygonOffset(0.0);
+               bglPolygonOffset(v3d->dist, 0.0);
        }
 }
 
@@ -2016,7 +2014,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
                // write to show selected edge wires better
                UI_ThemeColor(TH_WIRE);
 
-               bglPolygonOffset(1.0);
+               bglPolygonOffset(v3d->dist, 1.0);
                glDepthMask(0);
        } 
        else {
@@ -2106,11 +2104,11 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
 
                if(G.f & G_DRAWNORMALS) {
                        UI_ThemeColor(TH_NORMAL);
-                       draw_dm_face_normals(cageDM);
+                       draw_dm_face_normals(scene, cageDM);
                }
                if(G.f & G_DRAW_VNORMALS) {
                        UI_ThemeColor(TH_NORMAL);
-                       draw_dm_vert_normals(cageDM);
+                       draw_dm_vert_normals(scene, cageDM);
                }
 
                if(G.f & (G_DRAW_EDGELEN|G_DRAW_FACEAREA|G_DRAW_EDGEANG))
@@ -2119,7 +2117,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
 
        if(dt>OB_WIRE) {
                glDepthMask(1);
-               bglPolygonOffset(0.0);
+               bglPolygonOffset(v3d->dist, 0.0);
                GPU_disable_material();
        }
 
@@ -2351,7 +2349,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
                                * otherwise this wire is to overlay solid mode faces so do some depth buffer tricks.
                                */
                if (dt!=OB_WIRE && draw_wire==2) {
-                       bglPolygonOffset(1.0);
+                       bglPolygonOffset(v3d->dist, 1.0);
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
                }
                
@@ -2359,7 +2357,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
                
                if (dt!=OB_WIRE && draw_wire==2) {
                        glDepthMask(1);
-                       bglPolygonOffset(0.0);
+                       bglPolygonOffset(v3d->dist, 0.0);
                }
        }
 
@@ -2390,7 +2388,7 @@ static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int f
                if(dt>OB_WIRE) {
                        // no transp in editmode, the fancy draw over goes bad then
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
-                       GPU_set_object_materials(scene, ob, glsl, NULL);
+                       GPU_set_object_materials(v3d, scene, ob, glsl, NULL);
                }
 
                draw_em_fancy(scene, v3d, ob, G.editMesh, cageDM, finalDM, dt);
@@ -2409,7 +2407,7 @@ static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int f
                        check_alpha = check_material_alpha(base, ob, glsl);
 
                        if(dt==OB_SOLID || glsl) {
-                               GPU_set_object_materials(scene, ob, glsl,
+                               GPU_set_object_materials(v3d, scene, ob, glsl,
                                        (check_alpha)? &do_alpha_pass: NULL);
                        }
 
@@ -2724,7 +2722,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        }
                        else {
                                if(draw_glsl_material(scene, ob, v3d, dt)) {
-                                       GPU_set_object_materials(scene, ob, 1, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 1, NULL);
                                        drawDispListsolid(lb, ob, 1);
                                }
                                else if(dt == OB_SHADED) {
@@ -2732,7 +2730,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                        drawDispListshaded(lb, ob);
                                }
                                else {
-                                       GPU_set_object_materials(scene, ob, 0, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 0, NULL);
                                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                        drawDispListsolid(lb, ob, 0);
                                }
@@ -2762,7 +2760,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        if(dl->nors==NULL) addnormalsDispList(ob, lb);
                        
                        if(draw_glsl_material(scene, ob, v3d, dt)) {
-                               GPU_set_object_materials(scene, ob, 1, NULL);
+                               GPU_set_object_materials(v3d, scene, ob, 1, NULL);
                                drawDispListsolid(lb, ob, 1);
                        }
                        else if(dt==OB_SHADED) {
@@ -2770,7 +2768,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                drawDispListshaded(lb, ob);
                        }
                        else {
-                               GPU_set_object_materials(scene, ob, 0, NULL);
+                               GPU_set_object_materials(v3d, scene, ob, 0, NULL);
                                glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                        
                                drawDispListsolid(lb, ob, 0);
@@ -2790,7 +2788,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        if(solid) {
                                
                                if(draw_glsl_material(scene, ob, v3d, dt)) {
-                                       GPU_set_object_materials(scene, ob, 1, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 1, NULL);
                                        drawDispListsolid(lb, ob, 1);
                                }
                                else if(dt == OB_SHADED) {
@@ -2799,7 +2797,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                        drawDispListshaded(lb, ob);
                                }
                                else {
-                                       GPU_set_object_materials(scene, ob, 0, NULL);
+                                       GPU_set_object_materials(v3d, scene, ob, 0, NULL);
                                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                
                                        drawDispListsolid(lb, ob, 0);
@@ -2978,7 +2976,7 @@ static void draw_new_particle_system(View3D *v3d, Base *base, ParticleSystem *ps
                        break;
                case PART_DRAW_BB:
                        if(v3d->camera==0 && part->bb_ob==0){
-// XXX                         error("Billboards need an active camera or a target object!");
+                               printf("Billboards need an active camera or a target object!\n");
 
                                draw_as=part->draw_as=PART_DRAW_DOT;
 
@@ -3966,18 +3964,35 @@ static void drawnurb(Scene *scene, View3D *v3d, Base *base, Nurb *nurb, int dt)
 /* draw a sphere for use as an empty drawtype */
 static void draw_empty_sphere (float size)
 {
-       float cent=0;
-       GLUquadricObj *qobj = gluNewQuadric(); 
-       gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
+       static GLuint displist=0;
+       
+       if (displist == 0) {
+               GLUquadricObj   *qobj;
                
-       glPushMatrix();
-       glTranslatef(cent, cent, cent);
-       glScalef(size, size, size);
-       gluSphere(qobj, 1.0, 8, 5);
+               displist= glGenLists(1);
+               glNewList(displist, GL_COMPILE_AND_EXECUTE);
                
-       glPopMatrix();
+               glPushMatrix();
+               
+               qobj    = gluNewQuadric(); 
+               gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
+               gluDisk(qobj, 0.0,  1, 16, 1);
+               
+               glRotatef(90, 0, 1, 0);
+               gluDisk(qobj, 0.0,  1, 16, 1);
+               
+               glRotatef(90, 1, 0, 0);
+               gluDisk(qobj, 0.0,  1, 16, 1);
+               
+               gluDeleteQuadric(qobj);  
+               
+               glPopMatrix();
+               glEndList();
+       }
        
-       gluDeleteQuadric(qobj); 
+       glScalef(size, size, size);
+               glCallList(displist);
+       glScalef(1/size, 1/size, 1/size);
 }
 
 /* draw a cone for use as an empty drawtype */
@@ -4544,7 +4559,7 @@ static void drawtexspace(Object *ob)
 }
 
 /* draws wire outline */
-static void drawSolidSelect(View3D *v3d, Base *base) 
+static void drawSolidSelect(Scene *scene, View3D *v3d, Base *base) 
 {
        Object *ob= base->object;
        
@@ -4564,7 +4579,7 @@ static void drawSolidSelect(View3D *v3d, Base *base)
        }
        else if(ob->type==OB_ARMATURE) {
                if(!(ob->flag & OB_POSEMODE))
-                       draw_armature(base, OB_WIRE, 0);
+                       draw_armature(scene, v3d, base, OB_WIRE, 0);
        }
 
        glLineWidth(1.0);
@@ -4595,7 +4610,7 @@ static void drawWireExtra(Scene *scene, View3D *v3d, Object *ob)
                }
        }
        
-       bglPolygonOffset(1.0);
+       bglPolygonOffset(v3d->dist, 1.0);
        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
        
        if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
@@ -4612,7 +4627,7 @@ static void drawWireExtra(Scene *scene, View3D *v3d, Object *ob)
        }
 
        glDepthMask(1);
-       bglPolygonOffset(0.0);
+       bglPolygonOffset(v3d->dist, 0.0);
 }
 
 /* should be called in view space */
@@ -4890,7 +4905,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        if((v3d->flag & V3D_SELECT_OUTLINE) && ob->type!=OB_MESH) {
                if(dt>OB_WIRE && dt<OB_TEXTURE && ob!=G.obedit && (flag && DRAW_SCENESET)==0) {
                        if (!(ob->dtx&OB_DRAWWIRE) && (ob->flag&SELECT) && !(flag&DRAW_PICKING)) {
-                               drawSolidSelect(v3d, base);
+                               drawSolidSelect(scene, v3d, base);
                        }
                }
        }
@@ -5035,7 +5050,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        break;
                case OB_ARMATURE:
                        if(dt>OB_WIRE) GPU_enable_material(0, NULL); // we use default material
-                       empty_object= draw_armature(base, dt, flag);
+                       empty_object= draw_armature(scene, v3d, base, dt, flag);
                        if(dt>OB_WIRE) GPU_disable_material();
                        break;
                default:
@@ -5378,7 +5393,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
 
                        em_solidoffs= bbs_mesh_solid_EM(scene, v3d, dm, scene->selectmode & SCE_SELECT_FACE);
                        
-                       bglPolygonOffset(1.0);
+                       bglPolygonOffset(v3d->dist, 1.0);
                        
                        // we draw edges always, for loop (select) tools
                        em_wireoffs= bbs_mesh_wire(dm, em_solidoffs);
@@ -5388,7 +5403,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
                                em_vertoffs= bbs_mesh_verts(dm, em_wireoffs);
                        else em_vertoffs= em_wireoffs;
                        
-                       bglPolygonOffset(0.0);
+                       bglPolygonOffset(v3d->dist, 0.0);
 
                        dm->release(dm);
 
@@ -5432,7 +5447,7 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, Object *ob, int
 
                if(dm) {
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
-                       GPU_set_object_materials(scene, ob, glsl, NULL);
+                       GPU_set_object_materials(v3d, scene, ob, glsl, NULL);
                }
                else {
                        glEnable(GL_COLOR_MATERIAL);