Discussion:
how to blit a Surface to screen with OPENGLBLIT arg?
flya flya
2005-08-28 02:53:06 UTC
Permalink
I want use pyopengle to render some 3d effects, but I also need to
blit some normal Surface to screen before redering 3d object.
my code like these:

pygame.init()
screen = pygame.display.set_mode((640,480),DOUBLEBUF|OPENGLBLIT|OPENGL)

background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 0))

while 1:
#clear screen and move camera
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
screen.blit(background, (0, 0))

#orbit camera around by 1 degree
glRotatef(1, 0, 1, 0)

drawcube()
pygame.display.flip()
pygame.time.wait(10)
but it seems "screen.blit(background, (0, 0))" do nothing when set
OPENGLBLIT,why?
Rene Dudfield
2005-08-28 03:06:30 UTC
Permalink
OPENGLBLIT does not work
Post by flya flya
I want use pyopengle to render some 3d effects, but I also need to
blit some normal Surface to screen before redering 3d object.
pygame.init()
screen = pygame.display.set_mode((640,480),DOUBLEBUF|OPENGLBLIT|OPENGL)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 0))
#clear screen and move camera
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
screen.blit(background, (0, 0))
#orbit camera around by 1 degree
glRotatef(1, 0, 1, 0)
drawcube()
pygame.display.flip()
pygame.time.wait(10)
but it seems "screen.blit(background, (0, 0))" do nothing when set
OPENGLBLIT,why?
Kris Schnee
2005-08-28 03:32:30 UTC
Permalink
Post by flya flya
I want use pyopengle to render some 3d effects, but I also need to
blit some normal Surface to screen before redering 3d object.
Welcome to OpenGHell! As far as I know, you can't just draw 2D objects
to the screen in OpenGL, even if you're also using Pygame. You have to
switch to a 2D OpenGL drawing mode, then create a quadrilateral painted
with a texture rather than _just blitting the image_. This is one way to
do it:

def CreateSpecialDrawingLists():
"""Create some drawing lists for quick screen-clearing and
mode-switching."""
global L_CLEARSCREEN,L_SWITCH_TO_2D,L_SWITCH_TO_3D
L_CLEARSCREEN = glGenLists(3)
L_SWITCH_TO_2D = L_CLEARSCREEN + 1
L_SWITCH_TO_3D = L_CLEARSCREEN + 2

glNewList(L_CLEARSCREEN,GL_COMPILE)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glEndList()

glNewList(L_SWITCH_TO_2D,GL_COMPILE)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0,SCREEN_SIZE_X,0,SCREEN_SIZE_Y,-1,1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glEndList()

glNewList(L_SWITCH_TO_3D,GL_COMPILE)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()

gluPerspective(45.0,float(SCREEN_SIZE_X)/float(SCREEN_SIZE_Y),0.1,100.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glEndList()

def OpenGLSwitchMode(two_d=True):
"""Switch between 2D and 3D drawing modes.
Currently it assumes the actual screen size/resolution never change,
so it will go squirrely if the screen is resized."""
global L_SWITCH_TO_2D, L_SWITCH_TO_3D
if two_d:
glCallList(L_SWITCH_TO_2D)
else:
glCallList(L_SWITCH_TO_3D)

(Then you switch to 2D mode and back during every run of the drawing loop.)



Kris
Who'd like to be corrected.
Simon Wittber
2005-08-28 03:57:44 UTC
Permalink
Post by Kris Schnee
Welcome to OpenGHell! As far as I know, you can't just draw 2D objects
to the screen in OpenGL, even if you're also using Pygame. You have to
switch to a 2D OpenGL drawing mode, then create a quadrilateral painted
with a texture rather than _just blitting the image_. This is one way to
It doesnt have to be OpenGHell. I try to make things easy, using my
SiGL abstraction. Look for some of the OpenGL projects on pygame.org.
rdypg and pygext and LGT are all designed to make 2D OpenGL a little
easier.

Sw.
Jasper
2005-08-28 09:33:30 UTC
Permalink
Post by flya flya
I want use pyopengle to render some 3d effects, but I also need to
blit some normal Surface to screen before redering 3d object.
The short answer is to use your surfaces to create textures in OpenGL,
and then map them to quads and draw them in 3D. The long answer is that
you pick up the OpenGL Redbook, walk through those NeHe tutorials that
have been translated into python, and perhaps take a look at how some
other projects use it.

-Jasper

Loading...