Beispiel #1
0
    def draw(self):
        __GL.glEnable(__GL.GL_DEPTH_TEST)
        for sid in self.stack: #should return order as 0+ (0 being the FG, [-1] the BG)
            d=(len(stack)-sid)*.01
            primitives=self.stack[sid].primitives #faster access (I think)
            for pid in primitives:
                p=primitives[pid]
                __GL.glBegin(p.primitive)
                __GL.glColor4iv(p.color)
                __GL.glVertex3fv(p.v1+[d])
                __GL.glVertex3fv(p.v2+[d])
                __GL.glVertex3fv(p.v3+[d])
                if p.v4!=None: __GL.glVertex3fv(p.v4+[d])
                __GL.glEnd()
        __GL.glDisable(__GL.GL_DEPTH_TEST)

        FontSize=0
        for oid in self.overlay:

            primitives=self.overlay[oid].primitives
            for pid in primitives:
                p=primitives[pid]
                __GL.glBegin(p.primitive)
                __GL.glColor4iv(p.color)
                __GL.glVertex2fv(p.v1)
                __GL.glVertex2fv(p.v2)
                __GL.glVertex2fv(p.v3)
                if p.v4!=None: __GL.glVertex2fv(p.v4)
                __GL.glEnd()

            strings=self.font[oid].strings
            for sid in strings:
                tet,size=strings[sid].text,strings[sid].size
                if size!= FontSize:
                    F=__pyg.font.Font('fonts/tahoma.ttf',size) #don't use .fon files
                    FontSize=size

                w,h=F.size(text)
                image=__pyg.transform.flip(F.render(text,True,strings[sid].color), False, True).get_buffer().raw #get raw pixel data

                x,y,X,Y = strings[sid].x,strings[sid].y,strings[sid].X,strings[sid].Y

                px=x*pw if type(x)==int else x
                py=y*ph if type(y)==int else y
                #center to the area: (if specified)
                if x2!=None: px+=((X if type(X)==float else float(X)*pw)-px)/2; px-=(w*pw)/2
                if y2!=None: py+=((Y if type(Y)==float else float(Y)*ph)-py)/2; py-=(h*ph)/2
                py+=(h*ph)

                __GL.glRasterPos2f(px,py)
                __GL.glDrawPixels(w,h,__GL.GL_BGRA,__GL.GL_UNSIGNED_BYTE,image)

                del(image) #remove the old buffer
Beispiel #2
0
def __DrawGUI(w, h, RotMatrix):  # called directly by the display function after drawing the scene
    global pw, ph
    # the GUI is drawn over the scene by clearing the depth buffer
    pw, ph = 1.0 / w, 1.0 / h

    global W_HitDefs
    W_HitDefs = {}  # clear the hitdefs to avoid improper activation

    __GL.glMatrixMode(__GL.GL_PROJECTION)
    __GL.glLoadIdentity()
    # glOrtho(-2*P, 2*P, -2, 2, -100, 100)
    __GLU.gluOrtho2D(0.0, 1.0, 1.0, 0.0)

    __GL.glMatrixMode(__GL.GL_MODELVIEW)

    __GL.glClear(__GL.GL_DEPTH_BUFFER_BIT)
    __GL.glPolygonMode(__GL.GL_FRONT_AND_BACK, __GL.GL_FILL)

    __GL.glLoadIdentity()

    __GL.glEnable(__GL.GL_BLEND)
    __GL.glDisable(__GL.GL_DEPTH_TEST)
    __GL.glDisable(__GL.GL_LIGHTING)

    __GL.glBegin(__GL.GL_QUADS)
    __GL.glColor4f(0.4, 0.4, 0.4, 0.8)  # options toggle
    __GL.glVertex2f(pw * 0, ph * 0)
    __GL.glVertex2f(pw * w, ph * 0)
    __GL.glVertex2f(pw * w, ph * 20)
    __GL.glVertex2f(pw * 0, ph * 20)
    __GL.glEnd()
    __GL.glColor4f(0.0, 0.0, 0.0, 0.2)
    __GL.glBegin(__GL.GL_TRIANGLES)
    __GL.glVertex2f(pw * ((w / 2) - 10), ph * 6)
    __GL.glVertex2f(pw * ((w / 2) + 10), ph * 6)
    __GL.glVertex2f(pw * (w / 2), ph * 15)
    __GL.glEnd()

    M = __ExPanel(pw * 0, ph * 21, pw * 210, ph * h, 1, "MODEL")
    if M:
        __BrowseBar(pw * 10, ph * 40, 180)

    A = __ExPanel(pw * (w - 210), ph * 21, pw * w, ph * h, 3, "ANIM")
    D = __ExPanel(
        pw * (211 if M else 1),
        ph * 21,
        pw * (w - (211 if A else 1)),
        ph * 150,
        2,
        "DSPL",
        (0 if M else pw * 105) + (0 if A else pw * -105),
    )
    if D:
        VIEWER.TOGGLE_LIGHTING = __TButton(pw * (221 if M else 11), ph * 31, "EnLight", True, "Lighting")
        VIEWER.TOGGLE_WIREFRAME = __TButton(pw * (221 if M else 11), ph * 56, "EnWire", False, "Wireframe")
        VIEWER.TOGGLE_BONES = __TButton(pw * (221 if M else 11), ph * 81, "EnBone", True, "Bones")

        global ORTHO
        if VIEWER.TOGGLE_ORTHO != ORTHO:
            W_States["EnOrtho"] = VIEWER.TOGGLE_ORTHO
            ORTHO = VIEWER.TOGGLE_ORTHO  # HACK
        ORTHO = __TButton(pw * (321 if M else 111), ph * 31, "EnOrtho", True, "Ortho")
        VIEWER.TOGGLE_ORTHO = ORTHO

        VIEWER.TOGGLE_3D = __TButton(pw * (321 if M else 111), ph * 56, "En3D", False, "3D Analglyph")
        VIEWER.TOGGLE_NORMALS = __TButton(pw * (321 if M else 111), ph * 81, "EnNrm", False, "Normals")

    C = __ExPanel(
        pw * (211 if M else 1),
        ph * (h - 150),
        pw * (w - (211 if A else 1)),
        ph * h,
        0,
        "CTRL",
        (0 if M else pw * 105) + (0 if A else pw * -105),
    )

    __GL.glDisable(__GL.GL_BLEND)
    __GL.glEnable(__GL.GL_DEPTH_TEST)

    # axis
    __GL.glLineWidth(1.0)
    __GL.glPushMatrix()
    __GL.glTranslatef(pw * (228 if M else 17), ph * (h - (167 if C else 17)), 0)
    __GL.glScalef(pw * 600, ph * 600, 1)
    __GL.glMultMatrixf(RotMatrix)

    __GL.glColor3f(1.0, 0.0, 0.0)
    __GL.glBegin(__GL.GL_LINES)
    __GL.glVertex3f(0.0, 0.0, 0.0)
    __GL.glVertex3f(0.02, 0.0, 0.0)
    __GL.glEnd()  # X
    __GL.glTranslatef(0.0145, 0.0, 0.0)
    __GL.glRotatef(90, 0.0, 1.0, 0.0)
    # __GLUT.glutSolidCone(0.003, 0.011, 8, 1)
    __GL.glRotatef(-90, 0.0, 1.0, 0.0)
    __GL.glTranslatef(-0.0145, 0.0, 0.0)
    __GL.glColor3f(0.0, 1.0, 0.0)
    __GL.glBegin(__GL.GL_LINES)
    __GL.glVertex3f(0.0, 0.0, 0.0)
    __GL.glVertex3f(0.0, -0.02, 0.0)
    __GL.glEnd()  # Y
    __GL.glTranslatef(0.0, -0.0145, 0.0)
    __GL.glRotatef(90, 1.0, 0.0, 0.0)
    # __GLUT.glutSolidCone(0.003, 0.011, 8, 1)
    __GL.glRotatef(-90, 1.0, 0.0, 0.0)
    __GL.glTranslatef(0.0, 0.0145, 0.0)
    __GL.glColor3f(0.0, 0.0, 1.0)
    __GL.glBegin(__GL.GL_LINES)
    __GL.glVertex3f(0.0, 0.0, 0.0)
    __GL.glVertex3f(0.0, 0.0, 0.02)
    __GL.glEnd()  # Z
    __GL.glTranslatef(0.0, 0.0, 0.0145)
    # __GLUT.glutSolidCone(0.003, 0.011, 8, 1)
    __GL.glTranslatef(0.0, 0.0, -0.0145)
    __GL.glColor3f(0.5, 0.5, 0.5)
    # __GLUT.glutSolidSphere(0.003, 8, 4)
    __GL.glPopMatrix()
Beispiel #3
0
def __DrawGUI(w,h,RotMatrix): #called directly by the display function after drawing the scene
    global pw,ph,lw,lh,layer
    #the GUI is drawn over the scene by clearing the depth buffer

    #using floats will cause a more accurate edge-blur between panels when the screen is resized
    pw,ph=1./w,1./h
    #using ints won't look as pretty, but you won't need the extra multiplication (TODO: add in options)

    global HitDefs
    HitDefs = {} #clear the hitdefs to avoid improper activation

    __GL.glMatrixMode(__GL.GL_PROJECTION)
    __GL.glLoadIdentity()
    __GL.glOrtho(0.0, 1.0, 1.0, 0.0, -100, 100)
    #__GLU.gluOrtho2D(0.0, 1.0, 1.0, 0.0)

    __GL.glMatrixMode(__GL.GL_MODELVIEW)

    __GL.glClear( __GL.GL_DEPTH_BUFFER_BIT )
    #__GL.glPolygonMode(__GL.GL_FRONT_AND_BACK,__GL.GL_FILL)

    __GL.glLoadIdentity()

    __GL.glBlendFunc(__GL.GL_SRC_ALPHA, __GL.GL_ONE_MINUS_SRC_ALPHA)
    __GL.glEnable(__GL.GL_BLEND)
    __GL.glEnable(__GL.GL_DEPTH_TEST)
    __GL.glDisable(__GL.GL_TEXTURE_2D)
    __GL.glDisable(__GL.GL_LIGHTING)

    #positioning precalculations
    pw211 = pw*211
    pw210 = pw*210
    pw105 = pw*105
    
    ph150 = ph*150
    ph21 = ph*21


    M,A,D,C=False,False,False,False
    if not __OprionsUpdatePanel(w,h):
        M = __ExPanel(0.,ph21,pw210,1.,1,'MODEL')
        if M: __ModelPanel()

        A = __ExPanel(1.-pw210,ph21,1.,1.,3,'ANIM')
        if A: __AnimPanel()

        D = __ExPanel(pw211 if M else 0.,ph21,1.-(pw211 if A else 0.),ph150,2,'DSPL',(0. if M else pw105)+(0. if A else -pw105))
        if D: __DisplayPanel(210 if M else 0,-210 if A else 0)

        C = __ExPanel(pw211 if M else 0.,1.-ph150,1.-(pw211 if A else 0.),1.,0,'CTRL',(0 if M else pw105)+(0 if A else -pw105))
        if C: __ControlPanel(210 if M else 0,-210 if A else 0)


        __GL.glDisable(__GL.GL_BLEND)
        #__GL.glEnable(__GL.GL_DEPTH_TEST)

        #axis
        __GL.glLineWidth(1.0)
        __GL.glPushMatrix()
        __GL.glTranslatef(pw*(228 if M else 17),ph*(h-(167 if C else 17)),0)
        __GL.glScalef(pw*600,ph*600,1)
        __GL.glMultMatrixf(RotMatrix)

        __GL.glColor3f(1.0,0.0,0.0)
        __GL.glBegin(__GL.GL_LINES); __GL.glVertex3f(0.0,0.0,0.0); __GL.glVertex3f(0.02,0.0,0.0); __GL.glEnd() #X
        __GL.glTranslatef(0.0145,0.0,0.0); __GL.glRotatef(90, 0.0, 1.0, 0.0)
        #__GLUT.glutSolidCone(0.003, 0.011, 8, 1)
        __GL.glRotatef(-90, 0.0, 1.0, 0.0); __GL.glTranslatef(-0.0145,0.0,0.0)
        __GL.glColor3f(0.0,1.0,0.0)
        __GL.glBegin(__GL.GL_LINES); __GL.glVertex3f(0.0,0.0,0.0); __GL.glVertex3f(0.0,-0.02,0.0); __GL.glEnd() #Y
        __GL.glTranslatef(0.0,-0.0145,0.0); __GL.glRotatef(90, 1.0, 0.0, 0.0)
        #__GLUT.glutSolidCone(0.003, 0.011, 8, 1)
        __GL.glRotatef(-90, 1.0, 0.0, 0.0); __GL.glTranslatef(0.0,0.0145,0.0)
        __GL.glColor3f(0.0,0.0,1.0)
        __GL.glBegin(__GL.GL_LINES); __GL.glVertex3f(0.0,0.0,0.0); __GL.glVertex3f(0.0,0.0,0.02); __GL.glEnd() #Z
        __GL.glTranslatef(0.0,0.0,0.0145)
        #__GLUT.glutSolidCone(0.003, 0.011, 8, 1)
        __GL.glTranslatef(0.0,0.0,-0.0145)
        __GL.glColor3f(0.5,0.5,0.5) ; #__GLUT.glutSolidSphere(0.003, 8, 4)
        __GL.glPopMatrix()

    for lid in layer: layer[lid].draw()

    global doFrameCheck
    if doFrameCheck: __FrameCheck(); doFrameCheck=False
    __GL.glBlendFunc(__GL.GL_SRC_ALPHA, __GL.GL_ONE_MINUS_SRC_ALPHA) #reset to mormal for anything else
Beispiel #4
0
def __DrawGUI(w,h,RotMatrix): #called directly by the display function after drawing the scene

    global pw,ph
    #the GUI is drawn over the scene by clearing the depth buffer
    pw,ph=1./w,1./h

    global W_HitDefs
    W_HitDefs = {} #clear the hitdefs to avoid improper activation

    __GL.glMatrixMode(__GL.GL_PROJECTION)
    __GL.glLoadIdentity()
    #glOrtho(-2*P, 2*P, -2, 2, -100, 100)
    __GLU.gluOrtho2D(0.0, 1.0, 1.0, 0.0) #TODO update the viewport with the pixel range instead of 1.0 (less GUI calculations will be needed)

    __GL.glMatrixMode(__GL.GL_MODELVIEW)

    __GL.glClear( __GL.GL_DEPTH_BUFFER_BIT )
    __GL.glPolygonMode(__GL.GL_FRONT_AND_BACK,__GL.GL_FILL)

    __GL.glLoadIdentity()

    __GL.glEnable(__GL.GL_BLEND)
    __GL.glDisable(__GL.GL_DEPTH_TEST)
    __GL.glDisable(__GL.GL_TEXTURE_2D)
    __GL.glDisable(__GL.GL_LIGHTING)

    __GL.glBegin(__GL.GL_QUADS)
    __GL.glColor4f(0.4,0.4,0.4,0.8) #options toggle
    __GL.glVertex2f(pw*0,ph*0)
    __GL.glVertex2f(pw*w,ph*0)
    __GL.glVertex2f(pw*w,ph*20)
    __GL.glVertex2f(pw*0,ph*20)
    __GL.glEnd()
    __GL.glColor4f(0.0,0.0,0.0,0.2)
    __GL.glBegin(__GL.GL_TRIANGLES)
    __GL.glVertex2f(pw*((w/2)-10),ph*6)
    __GL.glVertex2f(pw*((w/2)+10),ph*6)
    __GL.glVertex2f(pw*(w/2),ph*15)
    __GL.glEnd()

    M = __ExPanel(pw*0,ph*21,pw*210,ph*h,1,'MODEL')
    if M: __ModelPanel()

    A = __ExPanel(pw*(w-210),ph*21,pw*w,ph*h,3,'ANIM')
    if A: __AnimPanel()

    D = __ExPanel(pw*(211 if M else 1),ph*21,pw*(w-(211 if A else 1)),ph*150,2,'DSPL',(0 if M else pw*105)+(0 if A else pw*-105))
    if D: __DisplayPanel(210 if M else 0,-210 if A else 0)

    C = __ExPanel(pw*(211 if M else 1),ph*(h-150),pw*(w-(211 if A else 1)),ph*h,0,'CTRL',(0 if M else pw*105)+(0 if A else pw*-105))
    if C: __ControlPanel(210 if M else 0,-210 if A else 0)


    #__font(40,40,14,"testing",(128,0,0,100))


    __GL.glDisable(__GL.GL_BLEND)
    __GL.glEnable(__GL.GL_DEPTH_TEST)

    #axis
    __GL.glLineWidth(1.0)
    __GL.glPushMatrix()
    __GL.glTranslatef(pw*(228 if M else 17),ph*(h-(167 if C else 17)),0)
    __GL.glScalef(pw*600,ph*600,1)

    __GL.glMultMatrixf(RotMatrix)

    __GL.glColor3f(1.0,0.0,0.0)
    __GL.glBegin(__GL.GL_LINES); __GL.glVertex3f(0.0,0.0,0.0); __GL.glVertex3f(0.02,0.0,0.0); __GL.glEnd() #X
    __GL.glTranslatef(0.0145,0.0,0.0); __GL.glRotatef(90, 0.0, 1.0, 0.0)
    #__GLUT.glutSolidCone(0.003, 0.011, 8, 1)
    __GL.glRotatef(-90, 0.0, 1.0, 0.0); __GL.glTranslatef(-0.0145,0.0,0.0)

    __GL.glColor3f(0.0,1.0,0.0)
    __GL.glBegin(__GL.GL_LINES); __GL.glVertex3f(0.0,0.0,0.0); __GL.glVertex3f(0.0,-0.02,0.0); __GL.glEnd() #Y
    __GL.glTranslatef(0.0,-0.0145,0.0); __GL.glRotatef(90, 1.0, 0.0, 0.0)
    #__GLUT.glutSolidCone(0.003, 0.011, 8, 1)
    __GL.glRotatef(-90, 1.0, 0.0, 0.0); __GL.glTranslatef(0.0,0.0145,0.0)

    __GL.glColor3f(0.0,0.0,1.0)
    __GL.glBegin(__GL.GL_LINES); __GL.glVertex3f(0.0,0.0,0.0); __GL.glVertex3f(0.0,0.0,0.02); __GL.glEnd() #Z
    __GL.glTranslatef(0.0,0.0,0.0145)
    #__GLUT.glutSolidCone(0.003, 0.011, 8, 1)
    __GL.glTranslatef(0.0,0.0,-0.0145)

    __GL.glColor3f(0.5,0.5,0.5) ; #__GLUT.glutSolidSphere(0.003, 8, 4)
    __GL.glPopMatrix()