(Python OpenGL) "4" Uniform variable Pyopengl

Source: Internet
Author: User

1 __author__="WSX"2 ImportNumPy as NP3  fromOpengl.glutImport*4  fromOpengl.glImport*5 ImportcTYPES6 ImportMath7 Globalgscalelocation8Scale = 0.09 #Vertex shader SectionTenVertex_shader ="""    One #version A  - Layout (location = 0) in vec3 Position; -  the uniform float Gscale; - void Main () - { - gl_position = VEC4 (Gscale * position.x, Gscale * position.y, POSITION.Z, 1.0); +     } - """ + #Fragment Shader section, String type AFragment_shader ="""  at #version - Out vec4 fragcolor; - void Main () - { - Fragcolor = VEC4 (1.0, 0.0, 0.0, 1.0); -     } in """ - defCreate_shader (Shaderprogram, Shader_type, Source):#Create and add shaders (equivalent to Addshader) Shader_type to type toShaderobj = Glcreateshader (Shader_type)#Create a Shader object + Glshadersource (shaderobj, Source) -Glcompileshader (Shaderobj)#to compile theGlattachshader (Shaderprogram, Shaderobj)#associating a shader object to a program *  $ Panax Notoginseng defCompile_shader ():#Compiling shaders -     Globalgscalelocation theShader_program = Glcreateprogram ()#Create an empty shader program + Create_shader (Shader_program, Gl_vertex_shader, Vertex_shader) A Create_shader (Shader_program, Gl_fragment_shader, Fragment_shader) the Gllinkprogram (Shader_program) + Gluseprogram (Shader_program) -Gscalelocation = Glgetuniformlocation (Shader_program,"Gscale") $  $ defDraw (): -     Global Scale - glclear (gl_color_buffer_bit) theScale + = 0.001 - gluniform1f (gscalelocation, Math.sin (scale))Wuyi Glenablevertexattribarray (0) the Glbindbuffer (Gl_array_buffer, VBO) -Glvertexattribpointer (0, 3, gl_float, Gl_false, 0, None)#None of this here can be written as 0. WuGldrawarrays (gl_triangles, 0, 3) -Gldisablevertexattribarray (0)#parsing data such as a matrix containing position, color, and a variety of information About glutswapbuffers () $  -  - defCreatebuffer ():#creating a vertex buffer -     GlobalVBO#set to global variable AVertex = Np.array ([[ -1.0,-1.0,0.0], +[1.0,-1.0,0.0], the[0.0,1.0,0.0]],dtype="float32")#creating a vertex array -VBO = glgenbuffers (1)#Create Cache $Glbindbuffer (Gl_array_buffer, VBO)#binding theGlbufferdata (Gl_array_buffer, Vertex.nbytes, Vertex, Gl_static_draw)#input Data the  the  the definitializeglutcallbacks (): -Glutdisplayfunc (Draw)#callback function in Glutidlefunc (Draw) the  the defMain (): About Glutinit ([]) theGlutinitdisplaymode (glut_double | GLUT_RGBA)#display mode dual cache theGlutinitwindowposition (100, 100)#Window Position theGlutinitwindowsize (500, 500)#Window Size +Glutcreatewindow ("Sanjiao")#Create Window -Glutinitcontextversion (4,3)#for compatibility theGlutinitcontextprofile (Glut_core_profile)#for compatibilityBayi initializeglutcallbacks () theGlclearcolor (0.0, 0.0, 0.0, 0.0) the Createbuffer () - Compile_shader () - Glutmainloop () the  theMain ()

Effect: (Dynamic effect, added later)

(Python OpenGL) "4" Uniform variable Pyopengl

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.