Ejemplo n.º 1
0
def process(hoxlist, getgeom, drawpiece,withstyle=True):
    glPushMatrix()
    try:
        for h in hoxlist:
            if not h: continue  # all nothings are NOOPs
            if type(h) is tuple:
                op = h[0]
                if op == DRAW or (op == STYLE and withstyle):
                    drawpiece(h[1])
                elif op == MOVE:
                    try:    #debug
                        op,name,axis,mult = h
                    except ValueError:  #debug
                        print h #debug
                        raise   #debug
                    t = getgeom(name)
                    if not t: continue  # skip the rest if zero movement
                    v = [0.0,0.0,0.0]
                    v[axis] = t * mult
                    glTranslatef(*v)
                elif op == ROT:
                    try:    #debug
                        op,name,axis,mult = h
                    except ValueError:  #debug
                        print h #debug
                        raise   #debug
                    a = getgeom(name)
                    if not a: continue  # skip the rest if zero rotation
                    v = [0.0,0.0,0.0]
                    v[axis] = 1.0
                    glRotatef(a * mult,*v)
            else:   # recurse into sub-list
                process(h,getgeom,drawpiece,withstyle)
    finally:
        glPopMatrix()   # GOT to do this no matter what!
Ejemplo n.º 2
0
def process(hoxlist, getgeom, drawpiece, withstyle=True):
    glPushMatrix()
    try:
        for h in hoxlist:
            if not h: continue  # all nothings are NOOPs
            if type(h) is tuple:
                op = h[0]
                if op == DRAW or (op == STYLE and withstyle):
                    drawpiece(h[1])
                elif op == MOVE:
                    try:  #debug
                        op, name, axis, mult = h
                    except ValueError:  #debug
                        print h  #debug
                        raise  #debug
                    t = getgeom(name)
                    if not t: continue  # skip the rest if zero movement
                    v = [0.0, 0.0, 0.0]
                    v[axis] = t * mult
                    glTranslatef(*v)
                elif op == ROT:
                    try:  #debug
                        op, name, axis, mult = h
                    except ValueError:  #debug
                        print h  #debug
                        raise  #debug
                    a = getgeom(name)
                    if not a: continue  # skip the rest if zero rotation
                    v = [0.0, 0.0, 0.0]
                    v[axis] = 1.0
                    glRotatef(a * mult, *v)
            else:  # recurse into sub-list
                process(h, getgeom, drawpiece, withstyle)
    finally:
        glPopMatrix()  # GOT to do this no matter what!
Ejemplo n.º 3
0
 def setdown_geom(self):
     """Default setdown_geom pops modelview matrix"""
     glPopMatrix()
Ejemplo n.º 4
0
import gl

def vec(*args):
    return (GLfloat * len(args))(*args)

def sphere(radius, slices, stacks):
    q = gluNewQuadric();
    gluQuadricNormals(q, GLU_SMOOTH);
    gluSphere(q, radius, slices, stacks);
    gluDeleteQuadric(q);



w = 400
h = 400

osmesa.init_ctx(w, h)
osmesa.render()

gl.glPushMatrix()
gl.glTranslatef(-10.0, 10.0, 0)
osmesa.sphere(20)
gl.glPopMatrix()

gl.glPushMatrix()
gl.glTranslatef(-10.0, 10.0, 0)
osmesa.sphere(22)
gl.glPopMatrix()

osmesa.free_ctx()
Ejemplo n.º 5
0
 def setdown_geom(self):
     """Default setdown_geom pops modelview matrix"""
     glPopMatrix()