from aiv.window import Window from aiv.opengl import * # import numpy for advanced array support import numpy window = Window() # set the color to use when clearing the color buffer glClearColor(1, 0, 0, 1) # build and bind a vertex array vao = glGenVertexArrays(1) glBindVertexArray(vao) # generate a buffer (will be mapped to the currently bound vertexarray) vbo = glGenBuffers(1) # bind it glBindBuffer(GL_ARRAY_BUFFER, vbo) # build an array of vertices for a triangle (2d) vertices = numpy.array([0, 1, -1, -1, 1, -1], dtype=numpy.float32) # upload data to the GPU buffer (the vbo) glBufferData(GL_ARRAY_BUFFER, vertices.nbytes, vertices, GL_STATIC_DRAW) # map the current buffer (vbo) to the vertex array (index 0) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, None) # a simple vertex shader vertex_shader = """
from aiv.window import Window # import OpenGL functions from aiv.opengl import * # ask the OS for a drawable context window = Window() glClearColor(1, 0, 0, 1) # the game loop while window.is_opened: # clear the color buffer glClear(GL_COLOR_BUFFER_BIT) # draw the color buffer window.update()
from aiv.window import Window from aiv.opengl import * import numpy from aiv.math.matrix4 import Matrix4 from aiv.input import KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN window = Window() vertex_shader = """ #version 330 core layout(location = 0) in vec3 vertex; uniform mat4 world; uniform mat4 camera; out vec4 color; void main() { gl_Position = camera * world * vec4(vertex, 1); color = vec4(vertex, 1); } """ fragment_shader = """ #version 330 core in vec4 color; out vec4 final_color; void main() {
from aiv.window import Window from aiv.opengl import * window = Window(1024, 576) glClearColor(0, 0, 1, 1) while window.is_opened: glClear(GL_COLOR_BUFFER_BIT) window.update()