Exemplo n.º 1
0
 def display(self, writer=None):
     debug("shape Display")
     if self.shape != None:
         if (writer != None):
             writer.Transfer(self.shape)
         else:
             debug("Line style is %s" % (self.style, ))
             ais_context = Singleton.sd.display.GetContext()
             if (self.style == 'hidden'):
                 ais_shp = AIS_Shape(self.shape)
                 ais_shp.SetWidth(0.1)
                 ais_shp.SetTransparency(0.10)
                 ais_shp.SetColor(rgb_color(0, 0, 0))
                 aspect = ais_shp.Attributes().WireAspect()
                 aspect.SetColor(rgb_color(0, 0, 0))
                 aspect.SetTypeOfLine(1)
                 ais_context.Display(ais_shp, True)
             elif (self.style == 'main_projection'):
                 ais_shp = AIS_Shape(self.shape)
                 ais_shp.SetWidth(5)
                 #ais_shp.SetTransparency(0)
                 #ais_shp.SetColor(rgb_color(0,0,0))
                 aspect = ais_shp.Attributes().WireAspect()
                 aspect.SetColor(rgb_color(0, 0, 0))
                 aspect.SetTypeOfLine(0)
                 ais_context.Display(ais_shp, True)
             else:
                 ais_context = Singleton.sd.display.GetContext()
                 ais_shp = AIS_Shape(self.shape)
                 ais_shp.SetWidth(2.0)
                 ais_shp.SetTypeOfHLR(2)
                 if (is_var_set(self.shape_color)):
                     ais_shp.SetColor(self.shape_color)
                 else:
                     ais_shp.SetColor(Quantity_Color(Quantity_NOC_PERU))
                 if (self.display_mode == DISP_MODE_WIREFRAME):
                     ais_context.SetDisplayMode(ais_shp, AIS_WireFrame,
                                                True)
                 else:
                     ais_context.SetDisplayMode(ais_shp, AIS_Shaded, True)
                 ais_context.Display(ais_shp, True)
     else:
         warning("Empty shape")
void main()
{
    gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}
"""

# construct the shader, load, compile and attach the GLSL programs
vs_shader = Graphic3d_ShaderObject.CreateFromSource(
    Graphic3d_TOS_VERTEX, TCollection_AsciiString(vs))
fs_shader = Graphic3d_ShaderObject.CreateFromSource(
    Graphic3d_TOS_FRAGMENT, TCollection_AsciiString(fs))
aProgram = Graphic3d_ShaderProgram()
aProgram.AttachShader(fs_shader)
aProgram.AttachShader(vs_shader)

# attach the shader to the AIS_Shape representation that renders the sphere
aspect = anIO.Attributes().ShadingAspect().Aspect()

if aProgram.IsDone():
    aspect.SetShaderProgram(aProgram)
else:
    raise AssertionError("no valid shader program found")

# when a shader fails to compile, raise an AssertionError
assert not aspect.ShaderProgram() is None, "no shader program is null"

# redisplay the sphere, when the shader was attached to its AIS_Shape aspect
display.Context.Redisplay(anIO, True)
display.FitAll()
start_display()