Here are some examples of creating one or more buffers using glGenBuffers. If you must use function calls such as glGenBuffers(n, buffers), you can directly use ctypes or use PyOpenGL GLint, which completes the data type of the ctypes type.
import ctypes
import numpy as np
from OpenGL.GL import *
import pygame
pygame.init()
screen = pygame.display.set_mode((800,600), pygame.OPENGL | pygame.DOUBLEBUF)
py_id = glGenBuffers(1)
c_id = ctypes.c_int()
glGenBuffers(1, c_id)
gl_id = GLint()
glGenBuffers(1, gl_id)
print py_id, c_id.value, gl_id.value
n = 10
py_list = glGenBuffers(n)
c_list = (ctypes.c_int * n)()
glGenBuffers(n, c_list)
gl_list = (GLint * n)()
glGenBuffers(n, gl_list)
print py_list, list(py_list)
print np.array(c_list), list(c_list)
print np.array(gl_list), list(gl_list)
, . , glGenBuffers , , buffers = glGenBuffers(n). , . , !
Update:
__call__, , . , , :
import ctypes
import numpy as np
from OpenGL.GL import *
import pygame
import timeit
pygame.init()
screen = pygame.display.set_mode((800,600), pygame.OPENGL | pygame.DOUBLEBUF)
def test(func, repeats):
start_time = timeit.default_timer()
for i in range(repeats):
func()
elapsed = timeit.default_timer() - start_time
print elapsed
def func1():
py_id = glGenBuffers(1)
def func2():
c_id = ctypes.c_int()
glGenBuffers(1, c_id)
def func3():
gl_id = GLint()
glGenBuffers(1, gl_id)
def func4():
n = 1
py_list = glGenBuffers(n)
def func5():
n = 1
c_list = (ctypes.c_int * n)()
glGenBuffers(n, c_list)
def func6():
n = 1
gl_list = (GLint * n)()
glGenBuffers(n, gl_list)
def func7():
n = 100
py_list = glGenBuffers(n)
def func8():
n = 100
c_list = (ctypes.c_int * n)()
glGenBuffers(n, c_list)
def func9():
n = 100
gl_list = (GLint * n)()
glGenBuffers(n, gl_list)
test(func1, 1000000)
test(func2, 1000000)
test(func3, 1000000)
test(func4, 1000000)
test(func5, 1000000)
test(func6, 1000000)
test(func7, 1000000)
test(func8, 1000000)
test(func9, 1000000)
, , , , , n = 1. , , , - . , , GLint() , ctypes , . , python , , OpenGL !