[Bf-blender-cvs] [4214b3c] blender2.8: OpenGL: simplify 3D cursor drawing

Mike Erwin noreply at git.blender.org
Mon Aug 8 10:56:32 CEST 2016


Commit: 4214b3c44a8de2df4a5db7be1db6f49e312df54a
Author: Mike Erwin
Date:   Mon Aug 8 03:17:24 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB4214b3c44a8de2df4a5db7be1db6f49e312df54a

OpenGL: simplify 3D cursor drawing

Use simple alternating colored lines instead of stippled overdraw.

Reimplement circ function to not use deprecated GLU (T49042). It also
leaves matrix stack untouched.

Remove unused circf function.

===================================================================

M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_intern.h

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 02e6009..a166ef0 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -120,38 +120,16 @@ extern void bl_debug_draw_edge_add(const float v0[3], const float v1[3]);
 extern void bl_debug_color_set(const unsigned int col);
 #endif
 
-void circf(float x, float y, float rad)
-{
-	GLUquadricObj *qobj = gluNewQuadric(); 
-	
-	gluQuadricDrawStyle(qobj, GLU_FILL); 
-	
-	glPushMatrix(); 
-	
-	glTranslatef(x, y, 0.0);
-	
-	gluDisk(qobj, 0.0,  rad, 32, 1);
-	
-	glPopMatrix(); 
-	
-	gluDeleteQuadric(qobj);
-}
-
 void circ(float x, float y, float rad)
 {
-	GLUquadricObj *qobj = gluNewQuadric(); 
-	
-	gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
-	
-	glPushMatrix(); 
-	
-	glTranslatef(x, y, 0.0);
-	
-	gluDisk(qobj, 0.0,  rad, 32, 1);
-	
-	glPopMatrix(); 
-	
-	gluDeleteQuadric(qobj);
+	glBegin(GL_LINE_LOOP);
+	const int segments = 32;
+	for (int i = 0; i < segments; ++i) {
+		float angle = 2 * M_PI * ((float)i / (float)segments);
+		glVertex2f(x + rad * cosf(angle),
+		           y + rad * sinf(angle));
+	}
+	glEnd();
 }
 
 
@@ -563,7 +541,6 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit, bool wr
 	glDepthMask(GL_TRUE);
 }
 
-
 static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d)
 {
 	int co[2];
@@ -575,19 +552,39 @@ static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d)
 		const float f20 = U.widget_unit;
 		
 		glLineWidth(1);
-		setlinestyle(0); 
-		cpack(0xFF);
-		circ((float)co[0], (float)co[1], f10);
-		setlinestyle(4);
-		cpack(0xFFFFFF);
-		circ((float)co[0], (float)co[1], f10);
-		setlinestyle(0);
+		glShadeModel(GL_FLAT);
+
+		glBegin(GL_LINE_LOOP);
+
+		const int segments = 16;
+		for (int i = 0; i < segments; ++i) {
+			float angle = 2 * M_PI * ((float)i / (float)segments);
+			float x = co[0] + f10 * cosf(angle);
+			float y = co[1] + f10 * sinf(angle);
+
+			if (i % 2 == 0)
+				glColor3ub(255,0,0);
+			else
+				glColor3ub(255,255,255);
+
+			glVertex2f(x,y);
+		}
+		glEnd();
 
 		UI_ThemeColor(TH_VIEW_OVERLAY);
-		sdrawline(co[0] - f20, co[1], co[0] - f5, co[1]);
-		sdrawline(co[0] + f5, co[1], co[0] + f20, co[1]);
-		sdrawline(co[0], co[1] - f20, co[0], co[1] - f5);
-		sdrawline(co[0], co[1] + f5, co[0], co[1] + f20);
+
+		glBegin(GL_LINES);
+		glVertex2f(co[0] - f20, co[1]);
+		glVertex2f(co[0] - f5, co[1]);
+		glVertex2f(co[0] + f5, co[1]);
+		glVertex2f(co[0] + f20, co[1]);
+		glVertex2f(co[0], co[1] - f20);
+		glVertex2f(co[0], co[1] - f5);
+		glVertex2f(co[0], co[1] + f5);
+		glVertex2f(co[0], co[1] + f20);
+		glEnd();
+
+		glShadeModel(GL_SMOOTH);
 	}
 }
 
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index c5026fb..e6f1262 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -192,7 +192,6 @@ void ED_view3d_draw_depth(Scene *scene, struct ARegion *ar, View3D *v3d, bool al
 void ED_view3d_draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d);
 void ED_view3d_after_add(ListBase *lb, Base *base, const short dflag);
 
-void circf(float x, float y, float rad);
 void circ(float x, float y, float rad);
 void view3d_update_depths_rect(struct ARegion *ar, struct ViewDepths *d, struct rcti *rect);
 float view3d_depth_near(struct ViewDepths *d);




More information about the Bf-blender-cvs mailing list