Generate entities based on vertex cache
Original (English link) http://ogldev.atspace.co.uk/www/tutorial03/tutorial03.html
1 __author__="WSX"2 3 ImportNumPy as NP4 fromOpengl.glutImport*5 fromOpengl.glImport*6 ImportcTYPES7 defDraw ():8 glclear (gl_color_buffer_bit)9 Glenablevertexattribarray (0)Ten Glbindbuffer (Gl_array_buffer, VBO) OneGlvertexattribpointer (0, 3, gl_float, Gl_false, 0, None)#None of this here can be written as 0. AGldrawarrays (gl_triangles, 0, 3) -Gldisablevertexattribarray (0)#parsing data such as a matrix containing position, color, and a variety of information - glutswapbuffers () the - - defCreatebuffer ():#creating a vertex buffer - GlobalVBO#set to global variable +Vertex = Np.array ([ -1.0,-1.0,0.0, -1.0,-1.0,0.0, +0.0,1.0,0.0],dtype="float32")#creating a vertex array AVBO = glgenbuffers (1)#Create Cache atGlbindbuffer (Gl_array_buffer, VBO)#binding -Glbufferdata (Gl_array_buffer, Vertex.nbytes, Vertex, Gl_static_draw)#input Data - - - defMain (): - Glutinit ([]) inGlutinitdisplaymode (glut_double | GLUT_RGBA)#display mode dual cache -Glutinitwindowposition (100, 100)#Window Position toGlutinitwindowsize (500, 500)#Window Size +Glutcreatewindow ("Sanjiao")#Create Window -Glutinitcontextversion (4,3)#for compatibility theGlutinitcontextprofile (Glut_core_profile)#for compatibility *Glutdisplayfunc (Draw)#callback function $Glclearcolor (0.0, 0.0, 0.0, 0.0)Panax Notoginseng Createbuffer () - Glutmainloop () the +Main ()
Results:
"Python OpenGL" "2" first triangle (PYOPENGL)