Beispiel #1
0
/* Vertex Paint and Weight Paint */
void draw_mesh_paint_weight_faces(DerivedMesh *dm, const bool use_light,
                                  void *facemask_cb, void *user_data)
{
	if (use_light) {
		const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f};

		/* but set default spec */
		glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);

		/* diffuse */
		glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
		glEnable(GL_LIGHTING);
		glEnable(GL_COLOR_MATERIAL);
	}

	dm->drawMappedFaces(dm, (DMSetDrawOptions)facemask_cb, GPU_enable_material, NULL, user_data,
	                    DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);

	if (use_light) {
		glDisable(GL_COLOR_MATERIAL);
		glDisable(GL_LIGHTING);

		GPU_disable_material();
	}
}
Beispiel #2
0
static void draw_mesh_paint_light_end(void)
{
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_LIGHTING);

	GPU_disable_material();
}
Beispiel #3
0
static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs)
{
	/* texture draw mode without GLSL */
	TexMatCallback *data = (TexMatCallback *)userData;
	GPUVertexAttribs *gattribs = attribs;
	Image *ima;
	ImageUser *iuser;
	bNode *node;
	int texture_set = 0;

	/* draw image texture if we find one */
	if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) {
		/* get openl texture */
		int mipmap = 1;
		int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, false) : 0;
		float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};

		if (bindcode) {
			NodeTexBase *texbase = node->storage;

			/* disable existing material */
			GPU_disable_material();
			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, zero);
			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero);
			glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);

			/* bind texture */
			glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
			glEnable(GL_COLOR_MATERIAL);
			glEnable(GL_TEXTURE_2D);

			glBindTexture(GL_TEXTURE_2D, ima->bindcode);
			glColor3f(1.0f, 1.0f, 1.0f);

			glMatrixMode(GL_TEXTURE);
			glLoadMatrixf(texbase->tex_mapping.mat);
			glMatrixMode(GL_MODELVIEW);

			/* use active UV texture layer */
			memset(gattribs, 0, sizeof(*gattribs));

			gattribs->layer[0].type = CD_MTFACE;
			gattribs->layer[0].name[0] = '\0';
			gattribs->layer[0].gltexco = 1;
			gattribs->totlayer = 1;

			texture_set = 1;
		}
	}

	if (!texture_set) {
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		glMatrixMode(GL_MODELVIEW);

		/* disable texture */
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_COLOR_MATERIAL);

		/* draw single color */
		GPU_enable_material(mat_nr, attribs);
	}
}
Beispiel #4
0
void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d,
                     Object *ob, DerivedMesh *dm, const int draw_flags)
{
	DMSetDrawOptions facemask = NULL;
	Mesh *me = ob->data;
	const bool do_light = (v3d->drawtype >= OB_SOLID);

	/* hide faces in face select mode */
	if (me->editflag & (ME_EDIT_PAINT_VERT_SEL | ME_EDIT_PAINT_FACE_SEL))
		facemask = wpaint__setSolidDrawOptions_facemask;

	if (ob->mode & OB_MODE_WEIGHT_PAINT) {

		if (do_light) {
			const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f};

			/* enforce default material settings */
			GPU_enable_material(0, NULL);
		
			/* but set default spec */
			glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);

			/* diffuse */
			glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
			glEnable(GL_LIGHTING);
			glEnable(GL_COLOR_MATERIAL);
		}

		dm->drawMappedFaces(dm, facemask, GPU_enable_material, NULL, me,
		                    DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);

		if (do_light) {
			glDisable(GL_COLOR_MATERIAL);
			glDisable(GL_LIGHTING);

			GPU_disable_material();
		}
	}
	else if (ob->mode & OB_MODE_VERTEX_PAINT) {
		if (me->mloopcol) {
			dm->drawMappedFaces(dm, facemask, GPU_enable_material, NULL, me,
			                    DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
		}
		else {
			glColor3f(1.0f, 1.0f, 1.0f);
			dm->drawMappedFaces(dm, facemask, GPU_enable_material, NULL, me,
			                    DM_DRAW_ALWAYS_SMOOTH);
		}
	}

	/* draw face selection on top */
	if (draw_flags & DRAW_FACE_SELECT) {
		draw_mesh_face_select(rv3d, me, dm);
	}
	else if ((do_light == false) || (ob->dtx & OB_DRAWWIRE)) {
		const int use_depth = (v3d->flag & V3D_ZBUF_SELECT) || !(ob->mode & OB_MODE_WEIGHT_PAINT);

		/* weight paint in solid mode, special case. focus on making the weights clear
		 * rather than the shading, this is also forced in wire view */

		if (use_depth) {
			bglPolygonOffset(rv3d->dist, 1.0);
			glDepthMask(0);  /* disable write in zbuffer, selected edge wires show better */
		}
		else {
			glDisable(GL_DEPTH_TEST);
		}

		glEnable(GL_BLEND);
		glColor4ub(255, 255, 255, 96);
		glEnable(GL_LINE_STIPPLE);
		glLineStipple(1, 0xAAAA);

		dm->drawEdges(dm, 1, 1);

		if (use_depth) {
			bglPolygonOffset(rv3d->dist, 0.0);
			glDepthMask(1);
		}
		else {
			glEnable(GL_DEPTH_TEST);
		}

		glDisable(GL_LINE_STIPPLE);
		glDisable(GL_BLEND);
	}
}