[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33566] trunk/blender/source/blender/ blenfont: Add the possibility to set a 4x4 matrix to be used on blf.

Diego Borghetti bdiego at gmail.com
Thu Dec 9 05:37:00 CET 2010


Revision: 33566
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33566
Author:   bdiego
Date:     2010-12-09 05:36:58 +0100 (Thu, 09 Dec 2010)

Log Message:
-----------
Add the possibility to set a 4x4 matrix to be used on blf.

This option allow the user to set a 4x4 matrix to be
multiplied before draw the text, for example:

	double *m;

	/* Get the matrix or build it! */

	BLF_matrix(m);
	BLF_enable(BLF_MATRIX);

	/* set color, size, etc and draw! */

	BLF_disable(BLF_MATRIX);

You don't need the last line (disable), but remember
that if you use the font to draw in any other place,
the matrix will be used!.

The GL code is:

	glPushMatrix();
	glMultMatrixd(m);
	glTranslatef();
	glScalef();
	glRotatef();

	glPopMatrix();

Let's Dalai test this!!! :D

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/BLF_api.h
    trunk/blender/source/blender/blenfont/intern/blf.c
    trunk/blender/source/blender/blenfont/intern/blf_font.c
    trunk/blender/source/blender/blenfont/intern/blf_internal_types.h

Modified: trunk/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_api.h	2010-12-09 03:22:03 UTC (rev 33565)
+++ trunk/blender/source/blender/blenfont/BLF_api.h	2010-12-09 04:36:58 UTC (rev 33566)
@@ -49,6 +49,20 @@
 void BLF_position(int fontid, float x, float y, float z);
 void BLF_size(int fontid, int size, int dpi);
 
+/* Set a 4x4 matrix to be multiplied before draw the text.
+ * Remember that you need call BLF_enable(BLF_MATRIX)
+ * to enable this.
+ *
+ * The order of the matrix is like GL:
+
+	| m[0]  m[4]  m[8]  m[12] |
+	| m[1]  m[5]  m[9]  m[13] |
+	| m[2]  m[6]  m[10] m[14] |
+	| m[3]  m[7]  m[11] m[15] |
+
+ */
+void BLF_matrix(int fontid, double *m);
+
 /* Draw the string using the default font, size and dpi. */
 void BLF_draw_default(float x, float y, float z, const char *str, size_t len);
 void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len);
@@ -180,6 +194,7 @@
 #define BLF_CLIPPING (1<<1)
 #define BLF_SHADOW (1<<2)
 #define BLF_KERNING_DEFAULT (1<<3)
+#define BLF_MATRIX (1<<4)
 
 // XXX, bad design
 extern int blf_mono_font;

Modified: trunk/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf.c	2010-12-09 03:22:03 UTC (rev 33565)
+++ trunk/blender/source/blender/blenfont/intern/blf.c	2010-12-09 04:36:58 UTC (rev 33566)
@@ -330,6 +330,18 @@
 		font->aspect= aspect;
 }
 
+void BLF_matrix(int fontid, double *m)
+{
+	FontBLF *font;
+	int i;
+
+	font= BLF_get(fontid);
+	if (font) {
+		for (i= 0; i < 16; i++)
+			font->m[i]= m[i];
+	}
+}
+
 void BLF_position(int fontid, float x, float y, float z)
 {
 	FontBLF *font;
@@ -435,6 +447,10 @@
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
 	glPushMatrix();
+
+	if (font->flags & BLF_MATRIX)
+		glMultMatrixd((GLdouble *)&font->m);
+
 	glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
 	glScalef(font->aspect, font->aspect, 1.0);
 

Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c	2010-12-09 03:22:03 UTC (rev 33565)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c	2010-12-09 04:36:58 UTC (rev 33566)
@@ -493,11 +493,16 @@
 
 static void blf_font_fill(FontBLF *font)
 {
+	int i;
+
 	font->aspect= 1.0f;
 	font->pos[0]= 0.0f;
 	font->pos[1]= 0.0f;
 	font->angle= 0.0f;
-	unit_m4(font->mat);
+
+	for (i= 0; i < 16; i++)
+		font->m[i]= 0;
+
 	font->clip_rec.xmin= 0.0f;
 	font->clip_rec.xmax= 0.0f;
 	font->clip_rec.ymin= 0.0f;

Modified: trunk/blender/source/blender/blenfont/intern/blf_internal_types.h
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_internal_types.h	2010-12-09 03:22:03 UTC (rev 33565)
+++ trunk/blender/source/blender/blenfont/intern/blf_internal_types.h	2010-12-09 04:36:58 UTC (rev 33566)
@@ -154,8 +154,10 @@
 	/* shadow color. */
 	float shadow_col[4];
 	
-	/* this is the matrix that we load before rotate/scale/translate. */
-	float mat[4][4];
+	/* Multiplied this matrix with the current one before
+	 * draw the text! see blf_draw__start.
+	 */
+	double m[16];
 
 	/* clipping rectangle. */
 	rctf clip_rec;





More information about the Bf-blender-cvs mailing list