Exemplo n.º 1
0
def test_gl():
    glClearColor(1, 0, 0, 0)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    print("Error before compilation?", glGetError())
    shader = shaders.compileProgram(
        shaders.compileShader(
            """#version 130
    attribute vec3 position;
    void main() {
        gl_Position = vec4(position, 0);
    }""", GL_VERTEX_SHADER),
        shaders.compileShader(
            """#version 130
    void main() {
        gl_FragColor = vec4(0,1,0,.5);
    }""", GL_FRAGMENT_SHADER),
    )
    vbo = VBO(array([
        (0, 1, 0),
        (1, -1, 0),
        (-1, -1, 0),
    ], dtype="f"))
    position_location = glGetAttribLocation(shader, "position")
    stride = 3 * 4
    with vbo:
        with shader:
            glEnableVertexAttribArray(position_location)
            stride = 3 * 4
            glVertexAttribPointer(position_location, 3, GL_FLOAT, False,
                                  stride, vbo)
            glDrawArrays(GL_TRIANGLES, 0, 3)
Exemplo n.º 2
0
def test_gl( ):
    glClearColor( 1,0,0, 0 )
    glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT )
    
    print('pre-compile error', glGetError())
    shader = shaders.compileProgram(
        shaders.compileShader( '''#version 130
    attribute vec3 position;
    void main() {
        gl_Position = vec4( position, 0 );
    }''', GL_VERTEX_SHADER),
        shaders.compileShader( '''#version 130
    void main() {
        gl_FragColor = vec4( 1,0,0,0 );
    }''', GL_FRAGMENT_SHADER),
    )
    vbo = VBO( array([
        (0,1,0),
        (1,-1,0),
        (-1,-1,0),
    ],dtype='f'))
    position_location = glGetAttribLocation(
        self.shader, 'position'
    )
    stride = 3*4
    with vbo:
        with shader:
            glEnableVertexAttribArray( position_location )
            stride = 3*4
            glVertexAttribPointer(
                position_location,
                3, GL_FLOAT,False, stride, self.vbo
            )
            glDrawArrays( GL_TRIANGLES, 0, 3 )
Exemplo n.º 3
0
def test_gl():
    glClearColor(1, 0, 0, 0)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    print 'pre-compile error', glGetError()
    shader = shaders.compileProgram(
        shaders.compileShader(
            '''#version 130
    attribute vec3 position;
    void main() {
        gl_Position = vec4( position, 0 );
    }''', GL_VERTEX_SHADER),
        shaders.compileShader(
            '''#version 130
    void main() {
        gl_FragColor = vec4( 1,0,0,0 );
    }''', GL_FRAGMENT_SHADER),
    )
    vbo = VBO(array([
        (0, 1, 0),
        (1, -1, 0),
        (-1, -1, 0),
    ], dtype='f'))
    position_location = glGetAttribLocation(self.shader, 'position')
    stride = 3 * 4
    with vbo:
        with shader:
            glEnableVertexAttribArray(position_location)
            stride = 3 * 4
            glVertexAttribPointer(position_location, 3, GL_FLOAT, False,
                                  stride, self.vbo)
            glDrawArrays(GL_TRIANGLES, 0, 3)
Exemplo n.º 4
0
def displayfunc_gles2(display, surface, ctx):
    from OpenGL import GLES2 as GL
    from OpenGL.GLES2 import shaders
    eglMakeCurrent( display, surface, surface, ctx )
    GL.glClearColor( 1,0,0, 0 )
    GL.glClear( GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT )
    
    global shader,vbo,position_location,stride
    if shader is None:
        shader = shaders.compileProgram(
            shaders.compileShader( '''#version 130
    attribute vec3 position;
    void main() {
        gl_Position = vec4( position, 0 );
    }''', type=GL_VERTEX_SHADER),
            shaders.compileShader( '''#version 130
    void main() {
        gl_FragColor = vec4( 1,0,0,0 );
    }''', type=GL_FRAGMENT_SHADER),
        )
        vbo = VBO( array([
            (0,1,0),
            (1,-1,0),
            (-1,-1,0),
        ],dtype='f'))
        position_location = GL.glGetAttribLocation(
            self.shader, 'position'
        )
        stride = 3*4
    with vbo:
        with shader:
            GL.glEnableVertexAttribArray( position_location )
            stride = 3*4
            GL.glVertexAttribPointer(
                position_location,
                3, GL_FLOAT,False, stride, self.vbo
            )
            GL.glDrawArrays( GL.GL_TRIANGLES, 0, 3 )
    eglSwapBuffers( display, surface )
Exemplo n.º 5
0
def displayfunc_gles2(display, surface, ctx):
    from OpenGL import GLES2 as GL
    from OpenGL.GLES2 import shaders
    eglMakeCurrent( display, surface, surface, ctx )
    GL.glClearColor( 1,0,0, 0 )
    GL.glClear( GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT )
    
    global shader,vbo,position_location,stride
    if shader is None:
        shader = shaders.compileProgram(
            shaders.compileShader( '''#version 130
    attribute vec3 position;
    void main() {
        gl_Position = vec4( position, 0 );
    }''', type=GL_VERTEX_SHADER),
            shaders.compileShader( '''#version 130
    void main() {
        gl_FragColor = vec4( 1,0,0,0 );
    }''', type=GL_FRAGMENT_SHADER),
        )
        vbo = VBO( array([
            (0,1,0),
            (1,-1,0),
            (-1,-1,0),
        ],dtype='f'))
        position_location = GL.glGetAttribLocation(
            self.shader, 'position'
        )
        stride = 3*4
    with vbo:
        with shader:
            GL.glEnableVertexAttribArray( position_location )
            stride = 3*4
            GL.glVertexAttribPointer(
                position_location,
                3, GL_FLOAT,False, stride, self.vbo
            )
            GL.glDrawArrays( GL.GL_TRIANGLES, 0, 3 )
    eglSwapBuffers( display, surface )