[pygame] PyOpenGL and pygame.display.flip

2014-11-25 Thread sylvain.boussekey

Hi everyone,

I'm running into difficulties when using an opengl window in pygame. 
For reasons I don't catch, sometimes, when I draw quads with pyopengl, I 
have to call pygame.display.flip to actually display anything, and 
sometimes, I don't, resulting in a blinking horrific mess when I draw 
multiple quads overlapping themselves.


I really don't know when it happen but it does in one project, not in 
one another. Can't tell the difference...


I'm using flags OPENGL | DOUBLEBUF | HWSURFACE for my pygame window

Here's what I execute at the beginning of my drawing state :

def clear():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

And here's my function to draw quads :

def drawtexturedquad(imgid, pos, proj=True, siz=(1, 1), r=1.0, g=1.0, 
b=1.0, alpha=1.0):

if proj:
glMatrixMode(GL_MODELVIEW)
else:
glMatrixMode(GL_PROJECTION)

glLoadIdentity()
glPushMatrix()
glEnable(GL_TEXTURE_2D)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

glTranslated(-1, -1, 0)
glTranslated(pos[0], pos[1], 0)
glScalef(siz[0], siz[1], 1)

glColor4f(r, g, b, alpha)

glBindTexture(GL_TEXTURE_2D, imgid)

glBegin(GL_QUADS)

glTexCoord2f(0.0, 1.0)
glVertex2f(-1.0, 1.0)

glTexCoord2f(1.0, 1.0)
glVertex2f(1.0, 1.0)

glTexCoord2f(1.0, 0.0)
glVertex2f(1.0, -1.0)

glTexCoord2f(0.0, 0.0)
glVertex2f(-1.0, -1.0)

glEnd()
glPopMatrix()
glFlush()


Re: [pygame] PyOpenGL and pygame.display.flip

2014-11-25 Thread sylvain.boussekey
Oops I hate when I search hours to find an answer and find it right 
when posting to a forum or mailing list !


I was just calling pygame.init() in another module than 
pygame.display.flip() and was doing a pygame.display.set_mode() 
elsewhere too without using DOUBLEBUFF flag.


I'm not sure to quite understand what've done here but it surely comes 
from the fact my pygame.display thing are not at the same place as my 
first import pygame.



Le 2014-11-25 11:10, sylvain.boussekey a écrit :

Hi everyone,

I'm running into difficulties when using an opengl window in pygame.
For reasons I don't catch, sometimes, when I draw quads with 
pyopengl,

I have to call pygame.display.flip to actually display anything, and
sometimes, I don't, resulting in a blinking horrific mess when I draw
multiple quads overlapping themselves.

I really don't know when it happen but it does in one project, not in
one another. Can't tell the difference...

I'm using flags OPENGL | DOUBLEBUF | HWSURFACE for my pygame window

Here's what I execute at the beginning of my drawing state :

def clear():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

And here's my function to draw quads :

def drawtexturedquad(imgid, pos, proj=True, siz=(1, 1), r=1.0, g=1.0,
b=1.0, alpha=1.0):
if proj:
glMatrixMode(GL_MODELVIEW)
else:
glMatrixMode(GL_PROJECTION)

glLoadIdentity()
glPushMatrix()
glEnable(GL_TEXTURE_2D)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

glTranslated(-1, -1, 0)
glTranslated(pos[0], pos[1], 0)
glScalef(siz[0], siz[1], 1)

glColor4f(r, g, b, alpha)

glBindTexture(GL_TEXTURE_2D, imgid)

glBegin(GL_QUADS)

glTexCoord2f(0.0, 1.0)
glVertex2f(-1.0, 1.0)

glTexCoord2f(1.0, 1.0)
glVertex2f(1.0, 1.0)

glTexCoord2f(1.0, 0.0)
glVertex2f(1.0, -1.0)

glTexCoord2f(0.0, 0.0)
glVertex2f(-1.0, -1.0)

glEnd()
glPopMatrix()
glFlush()