File: check_egl_es2.py

package info (click to toggle)
pyopengl 3.1.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,024 kB
  • sloc: python: 108,056; sh: 13; makefile: 8
file content (56 lines) | stat: -rwxr-xr-x 1,420 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env python
from __future__ import print_function
import xlibegltest as egltest
from numpy import array
from OpenGL.arrays.vbo import VBO
from OpenGL.arrays import ArrayDatatype
from OpenGL.GLES2 import *
from OpenGL.GLES2 import shaders


@egltest.egltest(api='es2')
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)
    print('OK')


if __name__ == "__main__":
    test_gl()