def scene(self, vs): vs.put(background((.5, 1, 1))) vs.put(GLRen.createTransMatrix("MATRIX0_ARB"), vs.orthoCS(0, "A", 0, 200, 200, 200, 100)) vs.put( GLRen.createTransMatrix("MATRIX1_ARB"), vs.rotateCS(vs.orthoCS(0, "B", 0, self.x, self.y, 150, 150), "R", self.a)) vs.put( getDListNocoords(""" PushAttrib ENABLE_BIT CURRENT_BIT COLOR_BUFFER_BIT TEXTURE_BIT BindProgram VERTEX_PROGRAM_ARB %s Enable VERTEX_PROGRAM_ARB BindProgram FRAGMENT_PROGRAM_ARB %s Enable FRAGMENT_PROGRAM_ARB Enable BLEND Disable DEPTH_TEST AlphaFunc GREATER 0 BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA BindTexture TEXTURE_2D %s TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 20 ActiveTextureARB TEXTURE1 BindTexture TEXTURE_2D %s TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 20 ActiveTextureARB TEXTURE0 """ % ( vp[0].getProgId(), fp[0].getProgId(), noise.getTexId(), lnoise.getTexId(), ))) vs.put(GLRen.createQuad(40, 40, 1), vs.orthoCS(0, "C", 0, 100, 500, 20, 20)) vs.put(getDListNocoords("PopAttrib"))
def getpaper(vecs, cols, x0, y0, x1, y1, t0, t1, tex0comb, isectcomb, tex1comb): pap = Paper() pap.setNPasses(1) ppass = pap.getPass(0) ppass.setSetupcode(""" PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT """) ppass.setTeardowncode(""" PopAttrib ActiveTexture TEXTURE0 """) # texid = vob.paper.textures.ptextures["RGB2"][1].getTexId(); texid0 = vob.paper.textures.getNamed("RGB2", t0).getTexId() texid1 = vob.paper.textures.getNamed("RGB2", t1).getTexId() constcode = """ ActiveTexture TEXTURE0 Enable TEXTURE_2D BindTexture TEXTURE_2D %(texid0)s TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT TexParameter TEXTURE_2D TEXTURE_WRAP_T REPEAT TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR ActiveTexture TEXTURE1 Enable TEXTURE_2D BindTexture TEXTURE_2D %(texid1)s TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT TexParameter TEXTURE_2D TEXTURE_WRAP_T REPEAT TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR Enable BLEND BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA BlendEquation FUNC_ADD Disable ALPHA_TEST Enable REGISTER_COMBINERS_NV """ % locals() r0, r1 = vecs c0, c1, c2, c3 = cols constcode += """ Color %(c0)s SecondaryColorEXT %(c1)s Fog FOG_COLOR %(c2)s CombinerParameterNV CONSTANT_COLOR0_NV %(r0)s CombinerParameterNV CONSTANT_COLOR1_NV %(r1)s """ % locals() return GLRen.createBasisPaperQuad( pap, 0, 0, x0, y0, 0, 0, x1, y1, GL.createDisplayList(constcode + parsedTexcodes[tex0comb]), GL.createDisplayList(constcode + parsedTexcodes[tex1comb]), GL.createDisplayList(constcode + parsedTexcodes[isectcomb]))
def genBgFileFromSeed(w, vs, seed, jpeg=0, scale=1): """ Generates a background texture into filename constructed from the seed. Seed is some 64bit integer value. ThePaperMill must loaded and be set to be global. Returns the filename with absolute path of the generated file. """ scalePostfix = '' if scale != 1: scalePostfix = '-%sx' % (scale) size = vs.getSize() # for Java to accept Python Long if seed > 0x7FFFFFFFFFFFFFFFL: lseed = seed - 0x10000000000000000L else: lseed = seed pap = ThePaperMill().getPaper(lseed, passmask=passmask, vecs=[[.5, 0], [0, .5]]) pq = GLRen.createPaperQuad(pap, -0.5, -0.5, 0.5, 0.5, 0) cs = vs.coords.affine(0, 1, 0, 0, 768 * scale, 0, 0, 768 * scale) vs.matcher.add(cs, "tex") vs.put(SolidBackdropVob(java.awt.Color(0, 0, 0))) vs.map.put(pq, cs, 0) w.renderStill(vs, 0) if (jpeg): print 'Saving background texture into %s%s-paper.gen.jpg.' % ( str(seed), scalePostfix) saveanim.saveframe('bgfile.tmp', w, 0, 0, 384 * scale, 384 * scale) os.system("convert -quality 95 %s %s" \ % ('bgfile.tmp', basedir+str(seed)+'%s-paper.gen.jpg' % (scalePostfix))) os.system("rm bgfile.tmp") return os.path.abspath(basedir + str(seed) + '%s-paper.gen.jpg' % (scalePostfix)) else: print 'Saving background texture into %s%s-paper.gen.png.' % ( str(seed), scalePostfix) saveanim.saveframe( basedir + str(seed) + '%s-paper.gen.png' % (scalePostfix), w, 0, 0, 384 * scale, 384 * scale) return os.path.abspath(basedir + str(seed) + '%s-paper.gen.png' % (scalePostfix))
def compile(self, *args): if self.list: self.list = None return list = GL.createDisplayList() vs = w.createVobScene() self.putGraph(vs, 0, 800) list.startCompile(w.window) #w.renderStill(vs, 0) vs.coords.renderInterp(w.getRenderingSurface(), vs.map, None, None, 0, 0, 1) list.endCompile(w.window) self.list = GLRen.createCallListCoorded(list)
def scene(self, vs): vs.put(background((.2, 1, 1))) vs.put( getDListNocoords(""" PushAttrib ENABLE_BIT CURRENT_BIT COLOR_BUFFER_BIT TEXTURE_BIT BindProgram VERTEX_PROGRAM_ARB %s Enable VERTEX_PROGRAM_ARB """ % (vp[0].getProgId(), ))) a = [] def param(i, v1=0, v2=0, v3=0, v4=0): vs.put( GLRen.createProgramLocalParameterARB("VERTEX_PROGRAM_ARB", i), vs.orthoCS(0, str(len(a)), 0, v1, v2, v3, v4)) a.append(0) param(0, 300, 300) q = GLRen.createQuad(500, 2, 1) param(3, -1, 3, self.ang) param(4, 30, self.l1, self.l2) vs.put(q, 0) param(3, 1, self.ang, 3) param(4, 30, self.l2, self.l1) vs.put(q, 0) param(3, 1, 3, self.ang + 2 * math.pi) param(4, 30, self.l1, self.l2) vs.put(q, 0) param(3, -1, self.ang + 2 * math.pi, 3) param(4, 30, self.l2, self.l1) vs.put(q, 0) vs.put(getDListNocoords("PopAttrib"))
def param(i, v1=0, v2=0, v3=0, v4=0): vs.put( GLRen.createProgramLocalParameterARB("VERTEX_PROGRAM_ARB", i), vs.orthoCS(0, str(len(a)), 0, v1, v2, v3, v4)) a.append(0)
def scene(self, vs): colors = vob.paper.colors.Colors(self.colorseed, minlum=0) textures = vob.paper.textures.Textures(self.texseed) texrand = java.util.Random(491728 * self.texseed2) # The RNG starts badly for i in range(0, 6): texrand.nextDouble() tex0 = textures.getPaperTexture("DSDT_HILO", texrand) tex1 = textures.getPaperTexture("RGB2", texrand) tcrand = java.util.Random(491728 * self.coordseed) # The RNG starts badly for i in range(0, 6): tcrand.nextDouble() repunit = vob.paper.texcoords.TexGenXYRepeatUnit(rnd=tcrand, ) syses = [ repunit, ] syses.extend([repunit.getRelated(tcrand) for i in range(0, 4)]) vs.put(background((.5, 1, 1))) vs.put( getDListNocoords(""" PushAttrib ENABLE_BIT CURRENT_BIT COLOR_BUFFER_BIT TEXTURE_BIT BindProgram VERTEX_PROGRAM_ARB %s Enable VERTEX_PROGRAM_ARB BindProgram FRAGMENT_PROGRAM_ARB %s Enable FRAGMENT_PROGRAM_ARB Enable BLEND Disable DEPTH_TEST AlphaFunc GREATER 0 BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA BindTexture TEXTURE_2D %s TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 20 ActiveTextureARB TEXTURE1 BindTexture TEXTURE_2D %s TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 20 ActiveTextureARB TEXTURE0 """ % ( vp[0].getProgId(), fp[0].getProgId(), tex0.getTexId(), tex1.getTexId(), ))) fpid = fp[0].getProgId() for c in range(0, 8): col = colors.colorarrs[c] vs.put( GLRen.createProgramLocalParameterARB("FRAGMENT_PROGRAM_ARB", c), vs.orthoCS(0, "aa%s" % c, 0, col[0], col[1], col[2], 0)) vind = 0 for c in range(0, len(syses)): v = syses[c]._getSTVectors(tcrand) vs.put( GLRen.createProgramLocalParameterARB("VERTEX_PROGRAM_ARB", vind), vs.orthoCS(0, "bb%s" % c, 0, v[0][0], v[0][1], v[0][2], v[0][3])) vs.put( GLRen.createProgramLocalParameterARB("VERTEX_PROGRAM_ARB", vind), vs.orthoCS(0, "bc%s" % c, 0, v[1][0], v[1][1], v[1][2], v[1][3])) vind += 1 print v vs.put(GLRen.createQuad(2, 2, 1), vs.orthoCS(0, "C", 0, 50, 50, 700, 700)) vs.put(getDListNocoords("PopAttrib"))
def __init__(self, x0, y0, x1, y1, border, ripple, typeInt=0, contentColor=java.awt.Color.white, frameColor=java.awt.Color.black, type="square"): self.dbg = 0 if typeInt == 1: type = 'square' elif typeInt == 2: type = 'ellipse' if self.dbg: print "Texture id:", self.tex.getTexId() def code(color): return """ PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT Enable ALPHA_TEST AlphaFunc GREATER 0.0 Disable BLEND Color %(color)s ActiveTexture TEXTURE1 BindTexture TEXTURE_2D %(boxtex)s Enable TEXTURE_2D TexImage2D TEXTURE_2D 0 ALPHA 4 4 0 ALPHA 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 TexParameter TEXTURE_2D TEXTURE_BASE_LEVEL 0 TexParameter TEXTURE_2D TEXTURE_MAX_LEVEL 0 TexParameter TEXTURE_2D TEXTURE_WRAP_S CLAMP TexParameter TEXTURE_2D TEXTURE_WRAP_T CLAMP TexParameter TEXTURE_2D TEXTURE_MIN_FILTER NEAREST TexParameter TEXTURE_2D TEXTURE_MAG_FILTER NEAREST #TexGen S TEXTURE_GEN_MODE EYE_LINEAR #Enable TEXTURE_GEN_S #TexGen T TEXTURE_GEN_MODE EYE_LINEAR #Enable TEXTURE_GEN_T ActiveTexture TEXTURE0 BindTexture TEXTURE_2D %(tex)s Enable TEXTURE_2D %(comb)s REGISTER_COMBINERS_NV CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1 CombinerInputNV COMBINER0_NV ALPHA VARIABLE_A_NV TEXTURE1 UNSIGNED_IDENTITY_NV ALPHA CombinerInputNV COMBINER0_NV ALPHA VARIABLE_B_NV TEXTURE0 SIGNED_NEGATE_NV ALPHA CombinerInputNV COMBINER0_NV ALPHA VARIABLE_C_NV TEXTURE1 UNSIGNED_IDENTITY_NV ALPHA CombinerInputNV COMBINER0_NV ALPHA VARIABLE_D_NV SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV BLUE CombinerOutputNV COMBINER0_NV ALPHA DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE FALSE FALSE FinalCombinerInputNV VARIABLE_A_NV ZERO UNSIGNED_IDENTITY_NV RGB FinalCombinerInputNV VARIABLE_B_NV ZERO UNSIGNED_IDENTITY_NV RGB FinalCombinerInputNV VARIABLE_C_NV ZERO UNSIGNED_IDENTITY_NV RGB FinalCombinerInputNV VARIABLE_D_NV PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB FinalCombinerInputNV VARIABLE_G_NV SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA """ % { "boxtex": self.boxtex.getTexId(), "tex": self.tex.getTexId(), "comb": self.combiners, "color": vob.util.ColorUtil.colorGLString(color) } def code2(color): return parseCombiner(""" PushAttrib ENABLE_BIT TEXTURE_BIT COLOR_BUFFER_BIT CombinerParameterNV CONSTANT_COLOR0_NV %(color)s 1 Enable REGISTER_COMBINERS_NV SPARE0 = TEX0 . COL0 SPARE0.alpha = TEX0.alpha * COL0.alpha + COL1.blue SPARE0.alpha = SPARE0.blue + SPARE0.alpha alpha = SPARE0.alpha color = CONST0 BindTexture TEXTURE_2D %(tex)s TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR Enable TEXTURE_2D Enable ALPHA_TEST AlphaFunc GEQUAL 1.0 Color 0 0 0 1 """) % { "tex": self.tex2.getTexId(), "color": vob.util.ColorUtil.colorGLString(color) } def code3(color): return parseCombiner(""" PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT COLOR_BUFFER_BIT BindTexture TEXTURE_2D %(tex)s TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR Enable TEXTURE_2D TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD Enable ALPHA_TEST AlphaFunc GEQUAL 1.0 """) % { "tex": self.tex3.getTexId(), "color": vob.util.ColorUtil.colorGLString(color) } if type == "square": self._content = GLRen.createIrregularQuad(x0, y0, x1, y1, border, ripple, 0, code(contentColor), self.dicefactor) self._frame = GLRen.createIrregularQuad(x0, y0, x1, y1, border, ripple, 1, code(frameColor), self.dicefactor) elif type == "ellipse": texscale = ripple ripple_scale = border / ripple ratio = float(ripple_scale) / self.ripple_scale if ratio < 3. / 4 or ratio > 4. / 3: if self.dbg: print "WARNING: anisotropy ratio", round( ratio, 2), "is far from one" # Irregu flags Y_COLOR = 1 Y_SECCOLOR = 2 DOTVEC_COLOR = 4 INTERP_DOTVEC = 8 SLICE_1D = 16 SLICE_2D = 32 SHIFTS = 64 INSIDE = 128 SHIFTS8 = 256 if GL.hasExtension("GL_NV_register_combiners"): self._content = GLRen.createIrregularEdge( 8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale, 0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 3, 0, SLICE_1D + Y_SECCOLOR + INSIDE, code2(contentColor), 1.0) self._frame = GLRen.createIrregularEdge( 8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale, 0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 3, 0, SLICE_1D + Y_SECCOLOR + DOTVEC_COLOR + INTERP_DOTVEC, code2(frameColor), 1.0) else: self._content = GLRen.createIrregularEdge( 8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale, 0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 0, 0, SLICE_1D + Y_COLOR + INSIDE, code3(contentColor), 1.0) self._frame = GLRen.createIrregularEdge( 8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale, 0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 0, 0, SLICE_1D + Y_COLOR + SHIFTS, code3(frameColor) + """ BlendFunc ZERO ZERO Enable BLEND """, 1.0)
win = _realwin else: win = org.nongnu.libvob.GraphicsAPI.getInstance( ).createStableOffscreen(500, 500) from org.nongnu.libvob.gl import GL, GLCache, GLRen _buf = GL.createByteVector(500 * 500 * 3) _drawbufvs = _realwin.createVobScene() _drawbufvs.map.put(SolidBackdropVob(Color(0, 0, 0.2))) _drawbufvs.map.put( GLCache.getCallList(""" Disable TEXTURE_2D Color 1 1 1 1 """)) cs = _drawbufvs.translateCS(0, "tr", 0, 501) _drawbufvs.map.put( GLRen.createDrawPixels(500, 500, "RGB", "UNSIGNED_BYTE", _buf), cs) else: win = _realwin # print "GW: ",win def failUnless(b, msg=None): if not b: raise str(("FU ", msg)) def getvs(): return win.createVobScene()
def getOptimizedPaper(self, seed, passmask=[1, 1, 1, 1, 1, 1, 1], numcolors=8, minlum=80, blend=0): pap = self.getPaper(seed, passmask, numcolors, minlum, blend) if not GL.hasExtension("GL_SGIS_generate_mipmap"): print "Warning: not returning optimized paper because" print "GL_SGIS_generate_mipmap extension is required but not available" return pap if GL.workaroundStupidBuggyAtiDrivers: print "Warning: not returning optimized paper because" print "copyTexImage2D has problems on ATI drivers" return pap # Now, we render a region. v = pap.repeat._getSTVectors() vs = optimizingWindow.createVobScene() vs.map.put(vob.vobs.SolidBackdropVob(java.awt.Color.red)) cs1 = vs.coords.ortho(0, 0, 0, 0, optimizedPaperSize + 1, optimizedPaperSize + 1) cs2 = vs.coords.affine(0, 0, 0, 0, v[0][0], v[0][1], v[1][0], v[1][1]) vs.map.put(GLRen.createPaperQuad(pap, 0, 0, 1, 1, 1), cs1, cs2) optimizingWindow.renderStill(vs, 1) tex = GL.createTexture() texid = tex.getTexId() GL.call(""" BindTexture TEXTURE_2D %(texid)s TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 2 TexParameter TEXTURE_2D GENERATE_MIPMAP_SGIS TRUE TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR BindTexture TEXTURE_2D 0 """ % locals()) tex.copyTexImage2D(optimizingWindow.getRenderingSurface(), "FRONT", "TEXTURE_2D", 0, "RGB5", 0, 0, optimizedPaperSize, optimizedPaperSize, 0) # Apparently, NV drivers 44.96 (maybe others) have some trouble # with the 1x1 mipmap getting clobbered. # Usually, that wouldn't be a problem, but papers will be viewed # 1) at largely different scales # 2) blurred for text background # so this matters. # We shall forbid the use of that mipmap tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAX_LEVEL", optimizedPaperMaxLevel) if dbg: vob.putil.texture.printTex(tex.getTexId()) npap = PaperHanger() npap.setNPasses(1) npap.cachedTexture = tex npap.addDepend(tex) # Need this for clones to survive ppass = npap.getPass(0) ppass.setSetupcode(""" PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT COLOR_BUFFER_BIT CURRENT_BIT Disable BLEND ActiveTexture TEXTURE1 Disable TEXTURE_2D ActiveTexture TEXTURE0 Enable DEPTH_TEST DepthFunc LESS BindTexture TEXTURE_2D %(texid)s TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE Color 0 1 0 Enable TEXTURE_2D SecondaryColorEXT 0 0 0 """ % locals()) ppass.setNTexGens(1) # t = pap.repeat.vecs t = v if dbg: print "T ", t ppass.putNormalTexGen(0, [ t[0][0], t[0][1], 0, 0, -t[1][0], -t[1][1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]) ppass.setTeardowncode(""" PopAttrib ActiveTexture TEXTURE0 """) if dbg: print "Ret: ", npap.toString(), npap.getPass(0).getNTexGens() return npap
def drawFillets(self, vs, pc): vs.put(getDListNocoords(""" PushAttrib POLYGON_BIT ENABLE_BIT Enable DEPTH_TEST DepthFunc LEQUAL LineWidth %s PolygonOffset -100 -100 ShadeModel SMOOTH """ % self.linewidth)) if self.lines: vs.put(getDListNocoords("PolygonMode FRONT_AND_BACK LINE")) border = 2 spans = GLRen.createFilletSpan2(border, self.dice, 1 + 4 * self.depthColor + 16 * self.ellipses + 64 * self.stretched + 128 * self.sectors) conns = GLRen.createSortedConnections(spans, spans, 2) spans = GLRen.createFilletSpan2(border, self.dice, 2 + 4 * self.depthColor + 16 * self.ellipses + 64 * self.stretched + 128 * self.sectors) conns_l = GLRen.createSortedConnections(spans, spans, 2) spans = GLRen.createFilletSpan2(1000, self.dice, 2 + 4 * self.depthColor + 16 * self.ellipses + 32 + 64 * self.stretched + 128 * self.sectors) conns_c = GLRen.createSortedConnections(spans, spans, 2) f3d = GLRen.createFillet3D(border, self.dice, 1); conns3d = GLRen.createIterConnections(f3d, f3d, 2); conns3dblend = GLRen.createFillet3DBlend(self.dice, self.dicelen, self.tblsize, self.mode); if self.fillets: thick = vs.coords.rational1D22(0, .5 * self.thick, 0, 0, 1, 1, 0); angle = vs.coords.rational1D22(0, self.angle, 0, 0, 1, 0, 0); thick = vs.coords.rational1D22(0, 2*self.thick, self.thick, .1, 2, 1, 1); angle = vs.coords.power1D2(0, self.angle, 1/3., 1, -1); else: thick = vs.coords.power1D2(0, .15 * self.thick, 0, 0, 0) angle = vs.coords.power1D2(0, 0, 1/3., 0, -1) vs.matcher.add(thick, "Thi") vs.matcher.add(angle, "Ang") if self.fillet3d: vs.put(getDListNocoords(""" Color 1 1 1 BindProgram VERTEX_PROGRAM_ARB %s Enable VERTEX_PROGRAM_ARB MatrixMode PROJECTION PushMatrix MatrixMode MODELVIEW PushMatrix """ % vp[not self.depthColor].getProgId())) if self.texture: vs.put(getDListNocoords(""" BindTexture TEXTURE_2D %s #TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR #TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR #TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 20 TexEnv TEXTURE_ENV TEXTURE_ENV_MODE MODULATE Enable TEXTURE_2D """ % tex.getTexId())) if self.blend3d and self.fillets: vs.put(getDListNocoords("Color .2 .2 1")) pc(conns3dblend, [thick, angle]) if self.drawInside or not self.fillets: vs.put(getDListNocoords("Color .2 .2 1")) pc(conns3d, [thick, angle]) vs.put(getDListNocoords(""" MatrixMode PROJECTION PopMatrix MatrixMode MODELVIEW PopMatrix """)) else: if hasattr(self, 'drawInsideColor'): vs.put(getDListNocoords("Color "+ColorUtil.colorGLString(self.drawInsideColor))) else: vs.put(getDListNocoords("Color 1 1 1")) if self.drawInside: pc(conns, [thick, angle]) vs.put(getDListNocoords(""" Color 0 0 0 """)) if self.drawEdge: pc(conns_l, [thick, angle]) if self.curvature : pc(conns_c, [thick, angle]) vs.put(getDListNocoords(""" BindProgram VERTEX_PROGRAM_ARB 0 BindTexture TEXTURE_2D 0 PopAttrib """)) if self.fillet3d and self.drawEdge: size = vs.getSize() initBuffers(size.width, size.height) # Now, draw the edges if directDepthCopy: vs.put(getDListNocoords(""" BindTexture TEXTURE_RECTANGLE_NV %s """ % depthTexture.getTexId())) vs.put(GLRen.createCopyTexSubImage2D("TEXTURE_RECTANGLE_NV", 0, 0, 0, width, height), 0) else: vs.put(getDListNocoords(""" PushAttrib ENABLE_BIT Disable ALPHA_TEST Disable DEPTH_TEST Disable TEXTURE_RECTANGLE_NV Disable TEXTURE_2D """)) # Copy the color buffer to a texture vs.put(getDListNocoords(""" BindTexture TEXTURE_RECTANGLE_NV %s """ % tmpTexture.getTexId())) vs.put(GLRen.createCopyTexSubImage2D("TEXTURE_RECTANGLE_NV", 0, 0, 0, width, height), 0) # Copy stencil&depth to color csdest = vs.translateCS(0,"copydest",0,height) vs.put(GLRen.createCopyPixels(width, height, "DEPTH_STENCIL_TO_BGRA_NV"), 0, csdest, ) # Read the depth to a texture vs.put(getDListNocoords(""" BindTexture TEXTURE_RECTANGLE_NV %s """ % depthTexture.getTexId())) vs.put(GLRen.createCopyTexSubImage2D("TEXTURE_RECTANGLE_NV", 0, 0, 0, width, height), 0) # Copy the color back from the backup texture vs.put(getDListNocoords(""" BindTexture TEXTURE_RECTANGLE_NV %s Enable TEXTURE_RECTANGLE_NV """ % tmpTexture.getTexId())) vs.put(getDList(""" Color 1 1 1 Begin QUAD_STRIP TexCoord 0 0 Vertex 0 %(h)s TexCoord 0 %(h)s Vertex 0 0 TexCoord %(w)s 0 Vertex %(w)s %(h)s TexCoord %(w)s %(h)s Vertex %(w)s 0 End """ % { "w" : width, "h" : height }), 0) vs.put(getDListNocoords(""" PopAttrib """)) vs.put(getDListNocoords(""" PushAttrib ENABLE_BIT Color 1 1 1 BindProgram FRAGMENT_PROGRAM_NV %s Enable FRAGMENT_PROGRAM_NV Enable BLEND BindTexture TEXTURE_RECTANGLE_NV %s """ % (edgefp.getProgId(), depthTexture.getTexId()))) vs.put(quad(), vs.orthoCS(0, "nprEdgeQuad", -100, 0, 0, width, height)) vs.put(getDListNocoords(""" BindTexture TEXTURE_RECTANGLE_NV 0 PopAttrib """))
def scene(self, vs): if self.index == self.oldindex: self.cols[self.index] = (self.Y, self.H, self.S) else: self.Y, self.H, self.S = self.cols[self.index] self.oldindex = self.index #log([apply(getcol, col) for col in self.cols]) status = " ".join(["(%.4G, %.4G, %.4G)" % col for col in self.cols]) str(self.cols) vs.put( background( (0, 0, 0) ) ) vssize = vs.getSize() cs = vs.orthoCS(0, "root", 0, 0, 0, vssize.width / 4.0, vssize.height / 3.0) csA0 = vs.orthoCS(cs, "csA0", 0, 0, 0, 2, 3) csB0 = vs.orthoCS(cs, "csB0", 0, 4 - 2, 0, 2, 3) size = 2.0**self.size csA1 = vs.orthoCS(cs, "csA1", 0, (2 - size) / 2.0, (3 - size) / 2.0, size, size) csB1 = vs.orthoCS(cs, "csB1", 0, 4 - (2 - size) / 2.0 - size, (3 - size) / 2.0, size, size) colA0, colA1, colB0, colB1 = tuple( [linear_to_monitor(apply(getcol, col)) for col in self.cols] ) if self.type < 4: vs.map.put(coloredQuad(colA0), csA0) vs.map.put(coloredQuad(colB0), csB0) if (self.type & 1) == 0: vs.map.put(coloredQuad(colA1), csA1) if (self.type & 2) == 0: vs.map.put(coloredQuad(colB1), csB1) nx = int(2 / size + .5) ny = int(3 / size + .5) for y in range(0, ny): for x in range(1 - self.parity, nx): if (x+y & 1) == 0 and (self.type & 1): csA = vs.orthoCS(cs, "csA%s-%s" % (x,y), 0, 2 - (x + 1) * size, y * size, size, size) vs.map.put(coloredQuad(colA1), csA) if (x+y & 1) == self.parity and (self.type & 2): csB = vs.orthoCS(cs, "csB%s-%s" % (x,y), 0, 2 + x * size, y * size, size, size) vs.map.put(coloredQuad(colB1), csB) else: nx = int(2 / size + .5) ny = int(3 / size + .5) for y in range(0, ny): for x in range(-nx, nx): def lerp(c0,c1,t): return [(1-t) * c0[i] + t * c1[i] for i in range(0,3)] t = 0.5 + (x+.5) / (2.0 * nx) / self.w if t < 0: t = 0 if t > 1: t = 1 cs2 = vs.orthoCS(cs, "cs-%s-%s" % (x,y), 0, x * size + 2, y * size, size, size) if (x+y & 1) == 0: col = lerp(colA0, colB0, t) else: col = lerp(colA1, colB1, t) vs.map.put(getDListNocoords("Color %s %s %s" % tuple(col))) vs.map.put(quad(), cs2) if self.frame: vs.map.put(getDListNocoords(""" PushAttrib ENABLE_BIT Disable ALPHA_TEST %sable BLEND """ % ("Dis", "En")[self.blend])) c = "%s %s %s" % linear_to_monitor(getcol(0, 0, 0)) vs.map.put(getDList(""" Begin QUAD_STRIP Color %(c)s 1 Vertex 0 0 Color %(c)s 0 Vertex .25 .25 Color %(c)s 1 Vertex 4 0 Color %(c)s 0 Vertex 3.75 .25 Color %(c)s 1 Vertex 4 3 Color %(c)s 0 Vertex 3.75 2.75 Color %(c)s 1 Vertex 0 3 Color %(c)s 0 Vertex .25 2.75 Color %(c)s 1 Vertex 0 0 Color %(c)s 0 Vertex .25 .25 End PopAttrib """ % locals()), cs) if self.line: vs.map.put(getDList(""" Color 0 0 0 LineWidth 8 Begin LINES Vertex 2 0 Vertex 2 3 End """), cs) putText(vs, cs, status, color = (0,0,0), x = 2, y = 2.98, h = .08, key = "txt") x, y = from_polar(self.S, self.H) s = .375 d = .5 + int(s/size) x0 = (d + (self.index & 1)) * size y0 = d * size if self.index & 2: x0 = 4 - x0 - (self.parity | (self.type == 4)) * size cs1 = vs.affineCS(cs, "cs1", 0, x0, y0, s, 0, 0, -s) cs2 = vs.affineCS(cs, "cs2", 0, x0, y0, x * s, -y * s, -y * s, -x * s) self.col_orig = (x0 / 4.0 * vssize.width, y0 / 3.0 * vssize.height) self.col_scale = s / 4.0 * vssize.width vs.map.put(arrow, cs2) if self.bars: bars = clamp(getcol(self.Y, self.H, self.S)) #h = math.fmod(self.H, 1) #if h < 0: h += 1 #bars += self.Y, h, self.S cols = ((1,0,0), (0,1,0), (0,0,1), (1,1,1), (1,1,0), (.5,.5,.5), ) for i in range(0,len(bars)): cs_bar = vs.affineCS(cs, "bar" + str(i), 0, 0.1 + 0.1 * i, 3, .05, 0, 0, -.2 * bars[i]) vs.map.put(coloredQuad(cols[i]), cs_bar) if 1: if not self.__dict__.has_key("gamut"): self.gamut = {} if self.gamut.has_key(self.Y): g = self.gamut[self.Y] else: code = [""" Begin LINE_LOOP Color 1 1 1 """] for vert in getRGBslice(self.Y): Y, H, S = setcol(vert) x, y = from_polar(S, H) code.append("Vertex %s %s" % (x, y)) code.append("End") g = getDList("\n".join(code)) vs.map.put(g, cs1) else: vs.map.put(getDListNocoords("Color 1 1 1")) cols = getRGBslice(self.Y, dupes = 1) poly = map(lambda col: apply(from_polar, setcol(col)[2:0:-1]), cols) cs = [] for i in range(0, len(poly)): cs.append(vs.affineCS(cs1, "cs_gamut" + str(i), 0, poly[i][0], poly[i][1], 1, 0, 0, 1)) line = GLRen.createLineConnector(0,0,0,0) for i in range(0, len(poly)): vs.map.put(line, cs[i-1], cs[i])