Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from OpenGL.GL import *
- from OpenGL.GLU import *
- from OpenGL.GLUT import *
- import numpy as np
- from gl_implement import gl_primitives as prm
- width, height = 640,480
- def compile_shader(sourse, type) :
- id = glCreateShader(GL_VERTEX_SHADER)
- glShaderSource(id, sourse)
- glCompileShader(id)
- result = glGetShaderiv(id, GL_COMPILE_STATUS)
- if result == GL_FALSE :
- print('that\'s a sheet')
- glDeleteShader(id)
- return
- return id;
- def create_vertex_shader(vertexShader) :
- program = glCreateProgram()
- vs = compile_shader(GL_VERTEX_SHADER, vertexShader)
- glAttachShader(program)
- glLinkProgram(program)
- glValidateProgram(program)
- glDeleteShader(vs)
- return program
- def draw() :
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- glLoadIdentity()
- position = np.array([[-1/2, 1/2, 0],[1/2, 1/2, 0],[1/2, -1/2, 0],[-1/2, -1/2, 0]], dtype='float32')
- # # import ctypes
- # # arr = (ctypes.c_int * 3 * 4)(*(tuple(j) for j in position))
- # # # print(arr)
- # # # print('size numpy arr : \n', sys.getsizeof(pyarr)/8, 'size c arr : ', sys.getsizeof(arr)/8)
- # #
- # # # buffer = Gluint(position[0])
- # from OpenGL.arrays import vbo
- # coords = vbo.VBO(position)
- # print(coords)
- buffer = 0
- glGenBuffers(1, buffer)
- glBindBuffer(GL_ARRAY_BUFFER, buffer)
- glBufferData(GL_ARRAY_BUFFER, position.nbytes, position ,GL_STATIC_DRAW)
- glEnableVertexAttribArray(0)
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 16 ,0)
- glBindBuffer(GL_ARRAY_BUFFER, 0)
- vertexShader = """
- #version 400
- layout(location = 0) in vec4 position;
- void main() {
- gl_Position = position
- }
- """
- shader = create_vertex_shader(vertexShader)
- glUseProgram(shader);
- # prm.draw_quad(30, [0.1, 0.8, 0.2, 1], [[-1/2, 1/2, 0],[1/2, 1/2, 0],
- # [1/2, -1/2, 0],[-1/2, -1/2, 0]], 'fill')
- glutSwapBuffers()
- def Init_GL_Window(num_window, width, height) :
- glutInit()
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
- glutInitWindowSize(width, height)
- glutInitWindowPosition(300, 300)
- window = glutCreateWindow("My First app on OpenGL")
- glutDisplayFunc(draw)
- glClearColor(.6, .2, .4 , 1.0) # background color
- glutMainLoop()
- def main() :
- Init_GL_Window(0, width, height);
- if __name__ == '__main__' : main() # указываем что этот фаил является главным
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement