Example #1
0
static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
{
	Mesh *me = ob->data;
	DerivedMesh *ddm;
	MPoly *mp, *mface  = me->mpoly;
	MTexPoly *mtpoly   = me->mtpoly;
	MLoopUV *mloopuv   = me->mloopuv;
	MLoopUV *luv;
	MLoopCol *mloopcol = me->mloopcol;  /* why does mcol exist? */
	MLoopCol *lcol;

	bProperty *prop = BKE_bproperty_object_get(ob, "Text");
	GPUVertexAttribs gattribs;
	int a, totpoly = me->totpoly;

	/* fake values to pass to GPU_render_text() */
	MCol  tmp_mcol[4]  = {{0}};
	MCol *tmp_mcol_pt  = mloopcol ? tmp_mcol : NULL;
	MTFace tmp_tf      = {{{0}}};

	/* don't draw without tfaces */
	if (!mtpoly || !mloopuv)
		return;

	/* don't draw when editing */
	if (ob->mode & OB_MODE_EDIT)
		return;
	else if (ob == OBACT)
		if (BKE_paint_select_elem_test(ob))
			return;

	ddm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);

	for (a = 0, mp = mface; a < totpoly; a++, mtpoly++, mp++) {
		short matnr = mp->mat_nr;
		int mf_smooth = mp->flag & ME_SMOOTH;
		Material *mat = (me->mat) ? me->mat[matnr] : NULL;
		int mode = mat ? mat->game.flag : GEMAT_INVISIBLE;


		if (!(mode & GEMAT_INVISIBLE) && (mode & GEMAT_TEXT) && mp->totloop >= 3) {
			/* get the polygon as a tri/quad */
			int mp_vi[4];
			float v1[3], v2[3], v3[3], v4[3];
			char string[MAX_PROPSTRING];
			int characters, i, glattrib = -1, badtex = 0;


			/* TEXFACE */
			ME_MTEXFACE_CPY(&tmp_tf, mtpoly);

			if (glsl) {
				GPU_enable_material(matnr + 1, &gattribs);

				for (i = 0; i < gattribs.totlayer; i++) {
					if (gattribs.layer[i].type == CD_MTFACE) {
						glattrib = gattribs.layer[i].glindex;
						break;
					}
				}
			}
			else {
				badtex = set_draw_settings_cached(0, &tmp_tf, mat, Gtexdraw);
				if (badtex) {
					continue;
				}
			}

			mp_vi[0] = me->mloop[mp->loopstart + 0].v;
			mp_vi[1] = me->mloop[mp->loopstart + 1].v;
			mp_vi[2] = me->mloop[mp->loopstart + 2].v;
			mp_vi[3] = (mp->totloop >= 4) ? me->mloop[mp->loopstart + 3].v : 0;

			/* UV */
			luv = &mloopuv[mp->loopstart];
			copy_v2_v2(tmp_tf.uv[0], luv->uv); luv++;
			copy_v2_v2(tmp_tf.uv[1], luv->uv); luv++;
			copy_v2_v2(tmp_tf.uv[2], luv->uv); luv++;
			if (mp->totloop >= 4) {
				copy_v2_v2(tmp_tf.uv[3], luv->uv);
			}

			/* COLOR */
			if (mloopcol) {
				unsigned int totloop_clamp = min_ii(4, mp->totloop);
				unsigned int j;
				lcol = &mloopcol[mp->loopstart];

				for (j = 0; j < totloop_clamp; j++, lcol++) {
					MESH_MLOOPCOL_TO_MCOL(lcol, &tmp_mcol[j]);
				}
			}

			/* LOCATION */
			ddm->getVertCo(ddm, mp_vi[0], v1);
			ddm->getVertCo(ddm, mp_vi[1], v2);
			ddm->getVertCo(ddm, mp_vi[2], v3);
			if (mp->totloop >= 4) {
				ddm->getVertCo(ddm, mp_vi[3], v4);
			}



			/* The BM_FONT handling is in the gpu module, shared with the
			 * game engine, was duplicated previously */

			BKE_bproperty_set_valstr(prop, string);
			characters = strlen(string);
			
			if (!BKE_image_has_ibuf(mtpoly->tpage, NULL))
				characters = 0;

			if (!mf_smooth) {
				float nor[3];

				normal_tri_v3(nor, v1, v2, v3);

				glNormal3fv(nor);
			}

			GPU_render_text(&tmp_tf, mode, string, characters,
			                (unsigned int *)tmp_mcol_pt, v1, v2, v3, (mp->totloop >= 4 ? v4 : NULL), glattrib);
		}
	}

	ddm->release(ddm);
}
Example #2
0
static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlaneTrack *plane_track,
                                 MovieTrackingPlaneMarker *plane_marker, bool is_active_track,
                                 bool draw_outline, int width, int height)
{
	bool tiny = (sc->flag & SC_SHOW_TINY_MARKER) != 0;
	bool is_selected_track = (plane_track->flag & SELECT) != 0;
	const bool has_image = plane_track->image != NULL &&
	                       BKE_image_has_ibuf(plane_track->image, NULL);
	const bool draw_plane_quad = !has_image || plane_track->image_opacity == 0.0f;
	float px[2];

	if (draw_outline) {
		UI_ThemeColor(TH_MARKER_OUTLINE);
	}
	else {
		float color[3], selected_color[3];
		plane_track_colors(is_active_track, color, selected_color);
		if (is_selected_track) {
			glColor3fv(selected_color);
		}
		else {
			glColor3fv(color);
		}
	}

	px[0] = 1.0f / width / sc->zoom;
	px[1] = 1.0f / height / sc->zoom;

	/* Draw image */
	if (draw_outline == false) {
		draw_plane_marker_image(scene, plane_track, plane_marker);
	}

	if (draw_plane_quad) {

		const bool stipple = !draw_outline && tiny;
		const bool thick = draw_outline && !tiny;

		if (stipple) {
			GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
			GPU_basic_shader_line_stipple(3, 0xAAAA);
		}
		else {
			GPU_basic_shader_bind_enable(GPU_SHADER_LINE);
		}

		GPU_basic_shader_line_width(thick ? 3.0f : 1.0f);

		/* Draw rectangle itself. */
		glBegin(GL_LINE_LOOP);
		glVertex2fv(plane_marker->corners[0]);
		glVertex2fv(plane_marker->corners[1]);
		glVertex2fv(plane_marker->corners[2]);
		glVertex2fv(plane_marker->corners[3]);
		glEnd();

		/* Draw axis. */
		if (!draw_outline) {
			float end_point[2];
			glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);

			glBegin(GL_LINES);

			getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[1], end_point);
			glColor3f(1.0, 0.0, 0.0f);
			glVertex2fv(plane_marker->corners[0]);
			glVertex2fv(end_point);

			getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[3], end_point);
			glColor3f(0.0, 1.0, 0.0f);
			glVertex2fv(plane_marker->corners[0]);
			glVertex2fv(end_point);

			glEnd();

			glPopAttrib();
		}

		if (stipple) {
			GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
		}
		else {
			GPU_basic_shader_bind_disable(GPU_SHADER_LINE);
		}
	}

	/* Draw sliders. */
	if (is_selected_track) {
		int i;
		for (i = 0; i < 4; i++) {
			draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1],
			                         3.0f * px[0], 3.0f * px[1], draw_outline, px);
		}
	}
}