Diff of /branches/wings2/src/wings_session.erl [r136] .. [r137] Maximize Restore

  Switch to side-by-side view

--- a/branches/wings2/src/wings_session.erl
+++ b/branches/wings2/src/wings_session.erl
@@ -50,7 +50,9 @@
     gl:matrixMode(?GL_MODELVIEW),
     gl:loadIdentity(),
     Light = hemi(),
+    Select = select(),
     put(light_shader, Light),
+    put(select_shader, Select),
     gl:enable(?GL_DEPTH_TEST),
     gl:depthFunc(?GL_LESS),
     put(dc, array:new()),
@@ -76,7 +78,7 @@
 	Op ->
 	    NewState = wings_server:invoke(Op, State),
 	    %% Maybe not call repaint everytime..:-)
-	    repaint(Last,State),
+	    repaint(Last,NewState),
 	    loop(NewState, Last)
     end.
       
@@ -91,8 +93,12 @@
     WinProp = [wires,vertex_color,material],
     gl:useProgram(get(light_shader)),
     DCs = wings_draw:all(SelMode,Shading,WinProp,State,DCs0),
+    gl:useProgram(get(select_shader)),
+    gl:depthFunc(?GL_LEQUAL),
+    wings_draw:draw_selection(face, State, DCs),
+    gl:depthFunc(?GL_LESS),
     gl:useProgram(0),
-    mini_axis_icon(),
+    mini_axis_icon(),    
     wxGLCanvas:swapBuffers(DEnv#d_env.gl),
     put(dc,DCs).
 
@@ -166,6 +172,28 @@
     wings_gl:set_uloc(Prog, "GroundColor", wings_pref:get_value(hl_groundcol)),
     Prog.
 
+select() ->
+    Sh = wings_gl:compile(vertex, select_shader_src()),
+    Prog = wings_gl:link_prog([Sh]),
+    gl:useProgram(Prog),
+    DepthBits = element(1,gl:getIntegerv(?GL_DEPTH_BITS)),
+    Depth = 1 bsl DepthBits,
+    wings_gl:set_uloc(Prog, "DepthBias", Depth),
+    Prog.
+
+select_shader_src() ->
+    <<"
+      uniform float DepthBias;
+      void main() 
+      {
+        vec4 pos = ftransform();
+//        pos.xyz /= pos.w;      // Pre-calc 
+//        pos.w = 1.0;           // 
+//        pos.z += 10*DepthBias;  // Offset selection in Z dir
+        gl_Position = pos;
+        gl_FrontColor  = vec4(1.0,0.0,0.0,1.0);
+      }
+      ">>. 
 light_shader_src() ->
     <<"
      uniform vec3 LightPosition;
@@ -174,16 +202,16 @@
 
      void main()
      {
-		vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
-		vec3 tnorm	   = normalize(gl_NormalMatrix * gl_Normal);
-		vec3 lightVec   = normalize(LightPosition - ecPosition);
-		float costheta  = dot(tnorm, lightVec);
-		float a	   = 0.5 + 0.5 * costheta;
-		// ATI needs this for vcolors to work
-		vec4 color	   = gl_FrontMaterial.diffuse * gl_Color;
-		gl_FrontColor   = color * vec4(mix(GroundColor, SkyColor, a), 
+	vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
+	vec3 tnorm	= normalize(gl_NormalMatrix * gl_Normal);
+	vec3 lightVec   = normalize(LightPosition - ecPosition);
+	float costheta  = dot(tnorm, lightVec);
+	float a	   = 0.5 + 0.5 * costheta;
+	// ATI needs this for vcolors to work
+	vec4 color	   = gl_FrontMaterial.diffuse * gl_Color;
+	gl_FrontColor   = color * vec4(mix(GroundColor, SkyColor, a), 
                                                1.0);
-		gl_TexCoord[0]  = gl_MultiTexCoord0;
-		gl_Position	   = ftransform();
-	       }
+	gl_TexCoord[0]  = gl_MultiTexCoord0;
+	gl_Position	   = ftransform();
+     }
      ">>.