OpenGL模板测试无法在Bootcamp Windows上运行

时间:2014-05-19 14:21:45

标签: python opengl stencil-buffer bootcamp

我有一个python代码,可以绘制一些OpenGL数据。这些数字是几个条形和一个圆形,后者实际上是一个可以看到条形的孔。为了获得这个光圈,我使用GL_STENCIL_TEST。它在我的同事的计算机上完美运行,但它不能在我的MacBook Pro计算机上运行,​​但使用Windows操作系统,使用Bootcamp。

我是否必须在代码中添加任何特殊行?

我使用的代码如下:

def drawAperture():
    global fill_color, numTheta, deltaTheta, x0_pix, y0_pix, apertRad_pix

    # Enable stencil
    glClearStencil(0x0)
    glEnable(GL_STENCIL_TEST)

    #define the region where the stencil is 1
    glClear(GL_STENCIL_BUFFER_BIT)
    glStencilFunc(GL_ALWAYS, 0x1, 0x1) #Always pass stencil functions test
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE)

    #Draw aperture     
    glColor3f( fill_color[0] , fill_color[1], fill_color[2])

    for i in range (0, numTheta):
        cx1 = x0_pix + apertRad_pix * math.sin(deltaTheta * i)
        cy1 = y0_pix + apertRad_pix * math.cos(deltaTheta * i)
        cx2 = x0_pix + apertRad_pix * math.sin(deltaTheta * (i+1))
        cy2 = y0_pix + apertRad_pix * math.cos(deltaTheta * (i+1))

        glBegin( GL_TRIANGLES )
        glVertex2f(x0_pix, y0_pix )
        glVertex2f(cx1 , cy1 )
        glVertex2f(cx2 , cy2 )
        glEnd()

def drawGrating(x, y, fill_color2, orientation, mylambda, duty_cycle):

    global apertRad_pix

    radio_aux = (2 * apertRad_pix) + mylambda #diameter 
    num_bars = int(1 + math.floor(radio_aux / mylambda))

    glStencilFunc (GL_EQUAL, 0x1, 0x1) 
    glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP)

    glLoadIdentity() #replace current matrix with the identity matrix
    glTranslatef(x, y, 0)
    glRotatef(orientation,0,0,1)    
    glTranslatef(-x, -y, 0)

    glColor3f( fill_color2[0] , fill_color2[1], fill_color2[2] )

    for i in range(num_bars):    

        x1 = mylambda * i + x
        x2 = (duty_cycle*mylambda) + (mylambda * i + x)

        glBegin(GL_QUADS)

        glVertex2f(x1, y - (apertRad_pix+50)) 
        glVertex2f(x1, y + (apertRad_pix+50)) 
        glVertex2f(x2, y + (apertRad_pix+50)) 
        glVertex2f(x2, y - (apertRad_pix+50))

        glEnd()

    glLoadIdentity()     

@myWindow.event
def on_draw():
    glEnable(GL_BLEND)
    pyglet.gl.glClearColor( 0.55 , 0.1, 0.1 , 0)
    myWindow.clear()

    drawAperture()

    mylambda = 100
    duty_cycle = 0.2
    drawGrating(x_right, y_right, [0.7, 0.6, 0.0], orientation, mylambda, duty_cycle)

dt2 = 1/60.0
pyglet.clock.schedule_interval(update_frames,dt2) 
timeStart = time.clock()   
pyglet.app.run()#run the script

0 个答案:

没有答案