
    &hA                     *   S r SSKrSSKrSSKr SSKJr  SSKJr   SSKJrJrJrJrJrJr  SrSrSrS	rS
rSS jrS rS rS r " S S5      rS rS rS rS r S r!\"S:X  a  \!" 5         gg! \	 a    \
" S5        \ef = f! \	 a    \
" S5        \ef = f)a  pygame.examples.glcube

Draw a cube on the screen.



Amazing.

Every frame we orbit the camera around a small amount
creating the illusion of a spinning object.

First we setup some points of a multicolored cube. Then we then go through
a semi-unoptimized loop to draw the cube points onto the screen.

OpenGL does all the hard work for us. :]


Keyboard Controls
-----------------

* ESCAPE key to quit
* f key to toggle fullscreen.

    Nz=pyopengl missing. The GLCUBE example requires: pyopengl numpy)arraydoteyezerosfloat32uint32z:numpy missing. The GLCUBE example requires: pyopengl numpyT))      ?      r
   )r	   r	   r
   )r
   r	   r
   )r
   r
   r
   )r	   r
   r	   )r	   r	   r	   )r
   r
   r	   )r
   r	   r	   ))   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   r   r   r   )r   r   r   )r   r   r   ))r   r         )r   r         )r   r         )r   r   r   r   )r   r   r   r   )r   r   r   r   ))r   r   )r   r   )r   r   )r   r   r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   c                     [        SSSU/SSSU/SSSU// SQ/U R                  S9R                  n[        X5      U S'   U $ )aS  
Translate (move) a matrix in the x, y and z axes.

:param matrix: Matrix to translate.
:param x: direction and magnitude to translate in x axis. Defaults to 0.
:param y: direction and magnitude to translate in y axis. Defaults to 0.
:param z: direction and magnitude to translate in z axis. Defaults to 0.
:return: The translated matrix.
      ?        )r   r   r   r   dtype.)r   r   Tr   )matrixxyztranslation_matrixs        N/var/www/auris/envauris/lib/python3.13/site-packages/pygame/examples/glcube.py	translater    e   sb     #sA#sA#sA 		
 ll a  f1F3KM    c                     [        S[        S9nSU-  X-
  -  US'   X-   X-
  -  US'   SU-  X2-
  -  US'   X2-   X2-
  -  US'   XT-   * XT-
  -  US'   S	U-  U-  XT-
  -  US
'   SUS'   U$ )a  
Build a perspective matrix from the clipping planes, or camera 'frustrum'
volume.

:param left: left position of the near clipping plane.
:param right: right position of the near clipping plane.
:param bottom: bottom position of the near clipping plane.
:param top: top position of the near clipping plane.
:param znear: z depth of the near clipping plane.
:param zfar: z depth of the far clipping plane.

:return: A perspective matrix.
)r   r   r          @)r   r   )r   r   )r   r   )r   r   )r   r   g       r   r   g      r   )r   r   )leftrightbottomtopznearzfarperspective_matrixs          r   frustumr,   |   s     vW5#e|u|<t %>t#e|s|<t #>t!%$,?t#e|d2dlCt#tr!   c                     [         R                  " U S-  [         R                  -  5      U-  nXA-  n[        U* XT* XBU5      $ )a4  
Build a perspective matrix from field of view, aspect ratio and depth
planes.

:param fovy: the field of view angle in the y axis.
:param aspect: aspect ratio of our view port.
:param znear: z depth of the near clipping plane.
:param zfar: z depth of the far clipping plane.

:return: A perspective matrix.
g     v@)mathtanpir,   )fovyaspectr)   r*   hws         r   perspectiver5      s@     	'(50A	
AA2q"a--r!   c                    [         R                  U-  S-  n[         R                  " U5      [         R                  " U5      pe[         R                  " X"-  X3-  -   XD-  -   5      nX'-  X7-  XG-  pCnSU-
  U-  SU-
  U-  SU-
  U-  pn[        X-  U-   X-  XF-  -
  X-  X6-  -   S/X-  XF-  -   X-  U-   X-  X&-  -
  S/X-  X6-  -
  X-  X&-  -   X-  U-   S// SQ/U R                  S9R                  n[        X5      U S'   U $ )z
Rotate a matrix around an axis.

:param matrix: The matrix to rotate.
:param angle: The angle to rotate by.
:param x: x of axis to rotate around.
:param y: y of axis to rotate around.
:param z: z of axis to rotate around.

:return: The rotated matrix
   r   r   r   r   r   r   r   .)	r.   r0   cossinsqrtr   r   r   r   )r   angler   r   r   csncxcyczrotation_matrixs               r   rotaterD      s    GGeOc!E88E?DHHUOq		!%!%-!%'(AeQUAE!Aa%1q1ukAEQ;BBVaZ!%!%;Vae^RVaZ!%;Vae^RVae^RVaZ;		
 ll a  f.F3KMr!   c                       \ rS rSrSrS rSrg)Rotation   z7
Data class that stores rotation angles in three axes.
c                 .    SU l         SU l        SU l        g )N   (      )thetaphipsi)selfs    r   __init__Rotation.__init__   s    
r!   )rM   rN   rL   N)__name__
__module____qualname____firstlineno____doc__rP   __static_attributes__ r!   r   rF   rF      s    r!   rF   c                  F   [        [        [        [        5      5      n [        R
                  " [        R                  5        [         H>  nU H5  nX   u  p4[        R                  " U5        [        R                  " U5        M7     M@     [        R                  " 5         [        R                  " SSS5        [        R
                  " [        R                  5        [         H(  nU H  nX   u  p4[        R                  " U5        M!     M*     [        R                  " 5         g)zC
Draw the cube using the old open GL methods pre 3.2 core context.
r   N)listzipCUBE_POINTSCUBE_COLORSGLglBeginGL_QUADSCUBE_QUAD_VERTS
glColor3fvglVertex3fvglEnd	glColor3fGL_LINES
CUBE_EDGES)	allpointsfacevertposcolorlines         r   drawcube_oldrn      s     Sk23IJJr{{D"JCMM% NN3   
 HHJLLc3JJr{{D"JCNN3  
 HHJr!   c                  R   [         R                  " [         R                  5        [         R                  " [         R                  5        [         R
                  " 5         [        R                  " SSSS5        [         R                  " SSS5        [         R                  " SSS	S	5        g
)z/
Initialise open GL, prior to core context 3.2
     F@gUUUUUU?g?      Y@r   g      rK   r   r   N)
r^   glEnableGL_DEPTH_TESTglMatrixModeGL_PROJECTIONglLoadIdentityGLUgluPerspectiveglTranslatef	glRotatefrX   r!   r   init_gl_stuff_oldr{      sl     KK  ! OOB$$%t[#u5OOCd#LLQ1r!   c           	         SnSn[         R                  " 5       n[         R                  " [         R                  5      n[         R                  " [         R                  5      n[         R
                  " XA5        [         R                  " U5        [         R                  " U5      n[        U[        5      (       a  UR                  5       nUR                  S5       H  n[        U5        M     [         R                  " X45        [         R
                  " XR5        [         R                  " U5        [         R                  " U5      n[        U[        5      (       a  UR                  5       nUR                  S5       H  n[        U5        M     [         R                  " X55        [         R                  " U5        [         R                  " U5        [         R                   " X45        [         R                   " X55        [         R"                  " U5        [%        SS[&        S4S[&        S4/5      n/ S	Q/ S
Q/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/US'   / SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/US'   [)        / SQ[*        S9n	[)        / SQ[*        S9n
0 0 S.n[         R,                  " [         R.                  " S5      5        [         R0                  " S5      US   S'   [         R2                  " [         R4                  US   S   5        [         R6                  " [         R4                  UR8                  U[         R:                  5        UR<                  S    n[>        R@                  " S 5      n[         RB                  " US5      n[         RD                  " U5        [         RF                  " US[         RH                  S!X5        [>        R@                  " URJ                  S   RL                  5      n[         RB                  " US5      n[         RD                  " U5        [         RF                  " US[         RH                  S!X5        [         R0                  " S5      US   S"'   [         R2                  " [         RN                  US   S"   5        [         R6                  " [         RN                  U	R8                  U	[         RP                  5        [         R0                  " S5      US   S#'   [         R2                  " [         RN                  US   S#   5        [         R6                  " [         RN                  U
R8                  U
[         RP                  5        [         RR                  " US$5      US%   S$'   [         RT                  " US%   S$   SS![W        S5      5        [         RR                  " US&5      US%   S&'   [Y        [W        S5      S'S(9n[         RT                  " US%   S&   SS!U5        [         RR                  " US)5      US%   S)'   [         RT                  " US%   S)   SS![W        S5      5        [         RR                  " US*5      US%   S*'   [         RZ                  " US%   S*   SSSS5        [         RR                  " US+5      US%   S+'   [         RZ                  " US%   S+   S S S S 5        [         R\                  " S S S S 5        [         R^                  " SS5        [         R`                  " [         Rb                  5        [         Rd                  " [         Rf                  [         Rh                  5        [         Rj                  " [         Rl                  5        [         Rn                  " [         Rp                  [         Rr                  5        [         Rt                  " S,5        [w        S-U S    [y        U S   5      -  S.S/5      n[         RT                  " US%   S)   SS!U5        XU
4$ )0z
Initialise open GL in the 'modern' open GL style for open GL versions
greater than 3.1.

:param display_size: Size of the window/viewport.
a  

    #version 150
    uniform mat4   model;
    uniform mat4   view;
    uniform mat4   projection;

    uniform vec4   colour_mul;
    uniform vec4   colour_add;

    in vec4 vertex_colour;         // vertex colour in
    in vec3 vertex_position;

    out vec4   vertex_color_out;            // vertex colour out
    void main()
    {
        vertex_color_out = (colour_mul * vertex_colour) + colour_add;
        gl_Position = projection * view * model * vec4(vertex_position, 1.0);
    }

    z
    #version 150
    in vec4 vertex_color_out;  // vertex colour from vertex shader
    out vec4 fragColor;
    void main()
    {
        fragColor = vertex_color_out;
    }
    
   vertex_positionr   vertex_colourr   r   )r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   r   )r   r   r   r   r8   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )$r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )buffer	constantsr   r   verticesr   Ffilledoutlinemodelr   viewi)r   
projection
colour_mul
colour_addr   rp   r#   rq   )=r^   glCreateProgramglCreateShaderGL_VERTEX_SHADERGL_FRAGMENT_SHADERglShaderSourceglCompileShaderglGetShaderInfoLog
isinstancebytesdecodesplitprintglAttachShaderglValidateProgramglLinkProgramglDetachShaderglUseProgramr   r   r   r   glBindVertexArrayglGenVertexArraysglGenBuffersglBindBufferGL_ARRAY_BUFFERglBufferDatanbytesGL_DYNAMIC_DRAWstridesctypesc_void_pglGetAttribLocationglEnableVertexAttribArrayglVertexAttribPointerGL_FLOATr   itemsizeGL_ELEMENT_ARRAY_BUFFERGL_STATIC_DRAWglGetUniformLocationglUniformMatrix4fvr   r    glUniform4fglClearColorglPolygonOffsetrr   GL_LINE_SMOOTHglBlendFuncGL_SRC_ALPHAGL_ONE_MINUS_SRC_ALPHAglDepthFuncGL_LESSglHintGL_LINE_SMOOTH_HINT	GL_NICESTglLineWidthr5   float)display_sizevertex_codefragment_codeprogramvertexfragmentlogrm   r   filled_cube_indicesoutline_cube_indicesshader_datastrideoffsetlocr   r   s                    r   init_gl_modernr      s   K,M   "Gr223F  !6!67Hf*v 


'C#ujjl		$d   g&h.x  


)C#ujjl		$d   g(!Wg&g(OOG 	+ow-JKH
 		#H 		!H_  %	
L O(T !P
  b1K--a01(*(:K*%OOB&&H(=j(IJOOB&&2CUCUVa F__QF

 
 *;
<C  %S!R[[%H__X^^,=>GGHF

 
 /
:C  %S!R[[%H&(ooa&8K(#OOB..H0Eh0OPOO
""""
	 (*q'9K)$OOB..H0Ei0PQOO
""##
	 )+(?(?(QKW%+k27;Qs1vN')'>'>w'OKV$SVr"D+k26:AudK-/-D-D.K\* +k2<@!UCPQFS .0-D-D.K\* NN;{+L91aAF .0-D-D.K\* NN;{+L91aAF OOAq!Qq!KK!!"NN2??B$=$=>NN2::IIb$$bll3NN3T<?U<?5K#KSRWXJ+k2<@!UJW-AAAr!   c                 ^   [         R                  " [         R                  [         R                  -  5        [         R                  " [         R
                  5        [         R                  " [         R                  5        [         R                  " [         R                  5        [         R                  " U S   S   SSSS5        [         R                  " U S   S   SSSS5        [         R                  " [         R                  U S   S   5        [         R                  " [         R                  [        U5      [         R                  S	5        [         R                  " [         R                  5        [         R                  " [         R
                  5        [         R                  " U S   S   SSSS5        [         R                  " U S   S   SSSS
5        [         R                  " [         R                  U S   S   5        [         R                  " [         R                   [        U5      [         R                  S	5        U=R"                  S
-  sl        [%        S[&        S9n[)        XCR"                  SSS5        [)        XCR*                  SSS5        [         R,                  " U S   S   SSU5        g	)aS  
Draw a cube in the 'modern' Open GL style, for post 3.1 versions of
open GL.

:param shader_data: compile vertex & pixel shader data for drawing a cube.
:param filled_cube_indices: the indices to draw the 'filled' cube.
:param outline_cube_indices: the indices to draw the 'outline' cube.
:param rotation: the current rotations to apply.
r   r   r   r   r   r   r   r   Nr   r   r   r   r   F)r^   glClearGL_COLOR_BUFFER_BITGL_DEPTH_BUFFER_BIT	glDisableGL_BLENDrr   rs   GL_POLYGON_OFFSET_FILLr   r   r   glDrawElementsGL_TRIANGLESlenGL_UNSIGNED_INTrf   rM   r   r   rD   rN   r   )r   r   r   rotationr   s        r   draw_cube_modernr     s    JJr%%(>(>>? LLKK  !KK))*NN;{+L91aAFNN;{+L91aCHOOB..H0Eh0OP
0123E3Et
 LL**+KKNN;{+L91aCHNN;{+L91aCHOOB..H0Ei0PQbkk3';#<b>P>PRVW LLCL!E
5,,1a(
5,,1a(+k27;QuMr!   c                     [         R                  " 5         Sn [        (       a  Sn [         R                  R	                  [         R
                  U S   5        [         R                  R	                  [         R                  U S   5        [         R                  R	                  [         R                  [         R                  5        SnSn[         R                  R                  U[         R                  [         R                  -  [         R                  -  5        [        (       a  [        U5      u  p4n[        5       nO
[        5         SnU(       Gat  [         R                   R#                  5       nU GH  n	U	R$                  [         R&                  :X  d<  U	R$                  [         R(                  :X  a"  U	R*                  [         R,                  :X  a  SnMb  U	R$                  [         R(                  :X  d  M  U	R*                  [         R.                  :X  d  M  U(       d\  [1        S5        [         R                  R                  S[         R                  [         R                  -  [         R2                  -  5        OJ[1        S	5        [         R                  R                  S[         R                  [         R                  -  5        U(       + nU S   S
:  d  U S   S:X  a$  U S   S:  a  [        U5      u  p4n[        5       nGM  [        5         GM     [        (       a  [5        WWWW5        OX[6        R8                  " [6        R:                  [6        R<                  -  5        [6        R>                  " SSSS5        [A        5         [         R                  RC                  5         [         RD                  RG                  S5        U(       a  GMt  [         RH                  " 5         g)zrun the demo)r   r   r$   r   r   F)i  i  TzChanging to FULLSCREENzChanging to windowed moder   r   r   
   N)%pginitUSE_MODERN_GLdisplaygl_set_attributeGL_CONTEXT_MAJOR_VERSIONGL_CONTEXT_MINOR_VERSIONGL_CONTEXT_PROFILE_MASKGL_CONTEXT_PROFILE_COREset_modeOPENGL	DOUBLEBUF	RESIZABLEr   rF   r{   eventgettypeQUITKEYDOWNkeyK_ESCAPEK_fr   
FULLSCREENr   r^   r   r   r   rz   rn   fliptimewaitquit)

gl_version
fullscreenr   gpu	f_indices	o_indicesr   goingeventsr   s
             r   mainr     sp    GGIJ}
 	

##B$?$?AO


##B$?$?AO


##&&(B(B	
 JLJJbii",,&>&MN}$2<$@!	:E
EzzRWW$

bjj(UYY"++-Erzz)eii266.A!23JJ''"BII$<r}}$L 56JJ''
BII4LM!+^
a=A%*Q-1*<ARSAS0>|0L-CI'zH%') , =S)YA JJr--0F0FFGLLAq!$N



RG %J GGIr!   __main__)r   r   r   )#rV   r.   r   pygamer   	OpenGL.GLr^   
OpenGL.GLUrw   ImportErrorr   
SystemExitnumpyr   r   r   r   r   r   r   r\   r]   ra   rg   r    r,   r5   rD   rF   rn   r{   r   r   r   rR   rX   r!   r   <module>r     s   0   
== 		
 .2."< 0eBP(NVCL zF Y  	
IJ
  	
FG
s   A- B -A>B