Xlib Events And Fullscreen Gles In Python - Youtube Vid


chris_c

Member
Joined
Jun 25, 2010
Messages
393
Age
55
http://www.youtube.com/watch?v=CbaQE4MI-44

Nearly ready for a first release! I have xlib events and full screen working to my satisfaction, all I need to do now is to package up some of the code in the sample into utility routines, oh and I should provide a way to shutdown the gles context too I suppose :eek:) !

Events I trap are mouse motion and mouse button press/release and key press/release. I'll be turning this into :-

utilPollEvents() must be run once a "frame"
utilGetMousePos() returning a tuple
utilGetMouseButton() a bool

There will also be a Boolean array of key states so you can do

if (utilKeys[24]):
print "q pressed!"

All the GLES stuff is literally directly calling the GLES library like this for example
gles.glPopMatrix()
gles.eglSwapBuffers(egldisplay,eglwindow)

There will be a utilInitialiseGLES() function that will open up a full screen context and return some info you'll need later for example the display and window handles...

There are almost certainly bugs in the function parameter decelerations so I'll be needing feedback :D

I do NOT plan to include higher level features like texture loading or 3d OBJ loading etc as I feel this is out of the scope of this module

I might at a later date put some of my old python OBJ loading and other support routines into a separate module if there is need, what I'd like to add to the OBJ loader would be a TRI soup to
TRI strips routine, but I need to hunt down an algorithm for that one!!!


At this stage I would also welcome any general ideas or suggestion that people might have, baring in mind that I want to keep this module as light and close to the "bare metal" as possible
(the only reason Xlib event handling is included is because I needed to create a window for the context and I wasn't too sure how people would go about getting events given only a window handle!)

Anyone with good python skills who knows GLES interested in doing some samples to go with the module?
 
in order to stimulate some feedback here is the sample code I'm using to test the module which is almost ready!

in bold are none gles module specific utility routines provided by the module...


#!/usr/bin/env python
import sys
import imgdat # example code programatically builds texture RGBA data

sys.path.append("./pygles") # not needed if "installed"
from GLES1_1 import *

egldisplay,eglwindow = utilInitialiseGLES()

# initialise gles states
gles.glClearColor(0.2, 0.2, 0.6, 0)
gles.glShadeModel(GL_SMOOTH)
gles.glEnable(GL_DEPTH_TEST)
gles.glDepthFunc(GL_LEQUAL)
gles.glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST)
gles.glEnableClientState(GL_VERTEX_ARRAY)
gles.glEnableClientState(GL_COLOR_ARRAY) #not with lighting
gles.glEnableClientState(GL_TEXTURE_COORD_ARRAY)
gles.glEnableClientState(GL_NORMAL_ARRAY)
gles.glEnable( GL_TEXTURE_2D )

# bind texture data to a gles texture reference
tex=c_uint()
gles.glGenTextures(1,byref(tex))
gles.glBindTexture( GL_TEXTURE_2D, tex)
gles.glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 16,16, 0, GL_RGBA,
GL_UNSIGNED_BYTE, imgdat.timg );​
gles.glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
gles.glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

# set up the projection matrix
gles.glViewport(0,0,800,480)
gles.glMatrixMode(GL_PROJECTION)
gles.glLoadIdentity()
utilPerspective(90,1.6666667,0.1,1000) # like gluPerspective
gles.glMatrixMode(GL_MODELVIEW)
gles.glLoadIdentity()


# NB using stride you can have all the vert, tex and norm data
# together which is more like it is normally structured
# but I was testing one thing then another...
# initialise without values and then fill or they are immutable

triVerts = (c_float * 9)( 0, 1, 0, -1, -1, 0, 1, -1, 0)
quadVerts = (c_float * 12)(
-1, 1, 0,
1, 1, 0,
-1,-1, 0,
1,-1, 0​
)
triColors = (c_float *12)(
1.0, 0.0, 0.0, 1.0, # Red
0.0, 1.0, 0.0, 1.0, # Green
0.0, 0.0, 1.0, 1.0 # Blue
)
quadColors = (c_float *16)(
1.0, 0.0, 0.0, 1.0, # Red
0.0, 1.0, 0.0, 1.0, # Green
0.0, 0.0, 1.0, 1.0, # Blue
1.0, 1.0, 1.0, 1.0 # White
)
triTverts = (c_float * 6)(.5,1, 0,0, 1,0)
quadTverts = (c_float * 8)(-1,1, 1,1, -1,-1, 1,-1)
triNorms = (c_float * 9)( 0, 0, 1, 0, 0, 1, 0, 0, 1)
quadNorms = (c_float * 12)(
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1​
) # real world shapes would have more interesting normals


LightAmbient = (c_float * 4)( 0.1, 0.1, 0.1, 1.0 )
LightDiffuse = (c_float * 4)( 1.0, 1.0, 1.0, 1.0 )
LightPosition = (c_float * 4)( 0.0, 0.0, 0.0, 1.0 )

gles.glLightfv( GL_LIGHT0, GL_AMBIENT, LightAmbient )
gles.glLightfv( GL_LIGHT0, GL_DIFFUSE, LightDiffuse )
gles.glLightfv( GL_LIGHT0, GL_POSITION, LightPosition )
gles.glEnable( GL_LIGHTING ) # comment this line to see vertex colouring
gles.glEnable( GL_LIGHT0 )

a=0
x=0
y=0
fin=False
while(fin==False): # while not pressed q

a=a+1.2
gles.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
gles.glLoadIdentity()
gles.glTranslatef(0,0,-6)
gles.glPushMatrix()

gles.glTranslatef(-1.5,0,0)
gles.glRotatef(x,0,1,0)
gles.glRotatef(y,1,0,0)
gles.glVertexPointer(3,GL_FLOAT,0,triVerts)
gles.glColorPointer(4, GL_FLOAT, 0, triColors)
gles.glTexCoordPointer(2, GL_FLOAT, 0, triTverts)
gles.glNormalPointer(GL_FLOAT,0,triNorms)
gles.glDrawArrays(GL_TRIANGLE_STRIP,0,3)

gles.glPopMatrix()
gles.glPushMatrix()

gles.glTranslatef(1.5,0,0)
gles.glRotatef(a,0,0,1)
gles.glRotatef(a,1,0,1)
gles.glVertexPointer(3,GL_FLOAT,0,quadVerts)
gles.glColorPointer(4, GL_FLOAT, 0, quadColors)
gles.glNormalPointer(GL_FLOAT,0,quadNorms)
gles.glTexCoordPointer(2, GL_FLOAT, 0, quadTverts)
gles.glDrawArrays(GL_TRIANGLE_STRIP,0,4)

gles.glPopMatrix()
gles.eglSwapBuffers(egldisplay, eglwindow)

utilPollEvents()
if utilsIsKeyDown(24): # 24=q
fin=True​

x+=(utilsGetMouseX()-400.0)/20
y+=(utilsGetMouseY()-240.0)/20

if utilsIsMouseDown():
gles.glClearColor(0.8, 0.2, 0.6, 0)​
else:
gles.glClearColor(0.2, 0.2, 0.6, 0)​

utilsShutdownGLES()
 
I think the code's beyond my understanding but I'm really impressed at your work rate. Loved watching the video and your fast progress on this. I think it'll be of use and interest to many. Certainly if I do ever write a game in Python, I'll most definitely be utilising this wrapper.

Now I look forward to hearing more expert discussions.

Thanks a lot.
 
yeah, the work rate is amazing :) You living on sick-time right now, or between terms or something? :)

I only get a few hours of hacking in every few days.. amazing :)

jeff
 
chris_c said:
couldn't sleep....

One more developer losing sleep because of the Pandora, welcome to the team!
 
Last edited by a moderator:
Back
Top