[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19639] branches/blender2.5/blender/source /blender: 2.5

Ton Roosendaal ton at blender.org
Fri Apr 10 16:27:29 CEST 2009


Revision: 19639
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19639
Author:   ton
Date:     2009-04-10 16:27:29 +0200 (Fri, 10 Apr 2009)

Log Message:
-----------
2.5

Nicer implementation of blurred font draw, moved to blenfont
module. Set it with BLF_blur(value). Current kernels implemented
are 3 and 5 only. Blenfont module can extend this once.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
    branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_style.c

Modified: branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/BLF_api.h	2009-04-10 14:09:44 UTC (rev 19638)
+++ branches/blender2.5/blender/source/blender/blenfont/BLF_api.h	2009-04-10 14:27:29 UTC (rev 19639)
@@ -68,7 +68,9 @@
  */
 void BLF_rotation(float angle);
 void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
+void BLF_blur(int size);
 
+
 void BLF_enable(int option);
 void BLF_disable(int option);
 

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf.c	2009-04-10 14:09:44 UTC (rev 19638)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf.c	2009-04-10 14:27:29 UTC (rev 19639)
@@ -280,6 +280,15 @@
 		(*font->size_set)(font, size, dpi);
 }
 
+void BLF_blur(int size)
+{
+	FontBLF *font;
+	
+	font= global_font[global_font_cur];
+	if (font)
+		font->blur= size;
+}
+
 void BLF_draw(char *str)
 {
 	FontBLF *font;

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c	2009-04-10 14:09:44 UTC (rev 19638)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c	2009-04-10 14:27:29 UTC (rev 19639)
@@ -433,6 +433,69 @@
 	MEM_freeN(g);
 }
 
+static void blf_glyph_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2)
+{
+	
+	glBegin(GL_QUADS);
+	glTexCoord2f(uv[0][0], uv[0][1]);
+	glVertex2f(dx, y1);
+	
+	glTexCoord2f(uv[0][0], uv[1][1]);
+	glVertex2f(dx, y2);
+	
+	glTexCoord2f(uv[1][0], uv[1][1]);
+	glVertex2f(dx1, y2);
+	
+	glTexCoord2f(uv[1][0], uv[0][1]);
+	glVertex2f(dx1, y1);
+	glEnd();
+	
+}
+
+static void blf_glyph_texture5_draw(float uv[2][2], float x1, float y1, float x2, float y2)
+{
+	float soft[25]= {
+		1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f, 
+		1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, 
+		2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f, 
+		1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, 
+		1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f};
+	
+	float color[4], *fp= soft;
+	int dx, dy;
+	
+	glGetFloatv(GL_CURRENT_COLOR, color);
+	
+	for(dx=-2; dx<3; dx++) {
+		for(dy=-2; dy<3; dy++, fp++) {
+			glColor4f(color[0], color[1], color[2], fp[0]*color[3]);
+			blf_glyph_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy);
+		}
+	}
+	
+	glColor4fv(color);
+}
+
+static void blf_glyph_texture3_draw(float uv[2][2], float x1, float y1, float x2, float y2)
+{
+	float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f};
+	float color[4], *fp= soft;
+	int dx, dy;
+	
+	glGetFloatv(GL_CURRENT_COLOR, color);
+	
+	for(dx=-1; dx<2; dx++) {
+		for(dy=-1; dy<2; dy++, fp++) {
+			glColor4f(color[0], color[1], color[2], fp[0]*color[3]);
+			blf_glyph_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy);
+		}
+	}
+	
+	glColor4fv(color);
+}
+
+
+
 int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y)
 {
 	GlyphTextureBLF *gt;
@@ -461,20 +524,13 @@
 	if (cur_tex != gt->tex)
 		glBindTexture(GL_TEXTURE_2D, gt->tex);
 
-	glBegin(GL_QUADS);
-	glTexCoord2f(gt->uv[0][0], gt->uv[0][1]);
-	glVertex2f(dx, y1);
-
-	glTexCoord2f(gt->uv[0][0], gt->uv[1][1]);
-	glVertex2f(dx, y2);
-
-	glTexCoord2f(gt->uv[1][0], gt->uv[1][1]);
-	glVertex2f(dx1, y2);
-
-	glTexCoord2f(gt->uv[1][0], gt->uv[0][1]);
-	glVertex2f(dx1, y1);
-	glEnd();
-
+	if (font->blur==3)
+		blf_glyph_texture3_draw(gt->uv, dx, y1, dx1, y2);
+	else if (font->blur==5)
+		blf_glyph_texture5_draw(gt->uv, dx, y1, dx1, y2);
+	else
+		blf_glyph_texture_draw(gt->uv, dx, y1, dx1, y2);
+	
 	return(1);
 }
 

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h	2009-04-10 14:09:44 UTC (rev 19638)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h	2009-04-10 14:27:29 UTC (rev 19639)
@@ -157,7 +157,10 @@
 
 	/* angle in degrees. */
 	float angle;
-
+	
+	/* blur: 3 or 5 large kernel */
+	int blur;
+	
 	/* this is the matrix that we load before rotate/scale/translate. */
 	float mat[4][4];
 

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_style.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_style.c	2009-04-10 14:09:44 UTC (rev 19638)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_style.c	2009-04-10 14:27:29 UTC (rev 19639)
@@ -134,57 +134,22 @@
 
 /* *************** draw ************************ */
 
-
-static void ui_font_shadow5_draw(uiFontStyle *fs, int x, int y, char *str)
+static void ui_font_shadow_draw(uiFontStyle *fs, int x, int y, char *str)
 {
-	float soft[25]= {
-		1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f, 
-		1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, 
-		2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f, 
-		1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, 
-		1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f};
+	float color[4];
 	
-	float color[4], *fp= soft;
-	int dx, dy;
-	
 	glGetFloatv(GL_CURRENT_COLOR, color);
 	
-	x+= fs->shadx;
-	y+= fs->shady;
+	glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
 	
-	for(dx=-2; dx<3; dx++) {
-		for(dy=-2; dy<3; dy++, fp++) {
-			glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fp[0]*fs->shadowalpha);
-			BLF_position(x+dx, y+dy, 0.0f);
-			BLF_draw(str);
-		}
-	}
+	BLF_blur(fs->shadow);
+	BLF_position(x+fs->shadx, y+fs->shady, 0.0f);
+	BLF_draw(str);
+	BLF_blur(0);
 	
 	glColor4fv(color);
 }
 
-static void ui_font_shadow3_draw(uiFontStyle *fs, int x, int y, char *str)
-{
-	float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f};
-	float color[4], *fp= soft;
-	int dx, dy;
-	
-	glGetFloatv(GL_CURRENT_COLOR, color);
-	
-	x+= fs->shadx;
-	y+= fs->shady;
-	
-	for(dx=-1; dx<2; dx++) {
-		for(dy=-1; dy<2; dy++, fp++) {
-			glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fp[0]*fs->shadowalpha);
-			BLF_position(x+dx, y+dy, 0.0f);
-			BLF_draw(str);
-		}
-	}
-	
-	glColor4fv(color);
-}
-
 void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str)
 {
 	float height;
@@ -204,10 +169,8 @@
 	BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+4, rect->ymax+4);
 	BLF_enable(BLF_CLIPPING);
 	
-	if(fs->shadow==3) 
-		ui_font_shadow3_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str);
-	else if(fs->shadow==5) 
-		ui_font_shadow5_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str);
+	if(fs->shadow) 
+		ui_font_shadow_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str);
 	
 	BLF_position(rect->xmin+xofs, rect->ymin+yofs, 0.0f);
 	BLF_draw(str);





More information about the Bf-blender-cvs mailing list