Re: [pygame] [OpenGL] Text, Transparency and Lists
Richard Jones wrote: Using the GL_ONE version, I get the ghostly version in the screenshot. Using GL_ONE_MINUS_SRC_ALPHA, I get a solid sprite all right, but with a black rectangle around it. I just noticed your texture loading has: tex_data = pygame.image.tostring(tex, "RGBX", 1 ) Why RGBX? You need the alpha channel... Poof! Changing "RGBX" to "RGBA" immediately makes it work. Thanks! This probably happened because that line is a distant descendant of some line that I copied from a tutorial long ago, without understanding that "X" wasn't Alpha. Kris
Re: [pygame] [OpenGL] Text, Transparency and Lists
On Sunday 17 September 2006 12:34, Kris Schnee wrote: > Richard Jones wrote: > > Looks like you've enabled blending without specifying a blend function. > > You'll want something like: > > > >glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) > > > > This indicates to use the texture's alpha channel for the texture imagea > > and the opposite (one minus) for the ground image. > > Thanks, but that doesn't seem to work. When I load the sprite image, I say: > ## Set up translucency. > ##glBlendFunc(GL_SRC_ALPHA,GL_ONE) > glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) > > Using the GL_ONE version, I get the ghostly version in the screenshot. > Using GL_ONE_MINUS_SRC_ALPHA, I get a solid sprite all right, but with a > black rectangle around it. I just noticed your texture loading has: tex_data = pygame.image.tostring(tex, "RGBX", 1 ) Why RGBX? You need the alpha channel... Richard
Re: [pygame] [OpenGL] Text, Transparency and Lists
Richard Jones wrote: Looks like you've enabled blending without specifying a blend function. You'll want something like: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) This indicates to use the texture's alpha channel for the texture imagea and the opposite (one minus) for the ground image. Thanks, but that doesn't seem to work. When I load the sprite image, I say: ## Set up translucency. ##glBlendFunc(GL_SRC_ALPHA,GL_ONE) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) Using the GL_ONE version, I get the ghostly version in the screenshot. Using GL_ONE_MINUS_SRC_ALPHA, I get a solid sprite all right, but with a black rectangle around it. The actual sprite-drawing says: glColor4f(1.0,1.0,1.0,1.0) glBindTexture(GL_TEXTURE_2D,self.texture) glEnable(GL_BLEND) glBegin(GL_QUADS) ... glEnd() glDisable(GL_BLEND) I'm also experimenting now with gluLookAt instead of my previous Camera class, which relied on glTranslatef and glRotatef, because gluLookAt offers a way to explicitly track the motion of a particular character. But that messes up the sprites' billboarding... Gah. Kris
Re: [pygame] [OpenGL] Text, Transparency and Lists
On Sunday 17 September 2006 11:31, Kris Schnee wrote: > I've put the latest code at: > http://kschnee.xepher.net/code/scurvy.py Looks like you've enabled blending without specifying a blend function. You'll want something like: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) This indicates to use the texture's alpha channel for the texture imagea and the opposite (one minus) for the ground image. Richard
[pygame] [OpenGL] Text, Transparency and Lists
Alex Holkner wrote (re: drawing text in pyOpenGL): Certainly not by getting the OS to draw font bitmaps. The standard technique is to render the characters you need to a texture (using pygame.font or SDL_ttf, for example), and rendering screen-aligned quads of the textures. pyglyph (http://www.partiallydisassembled.net/pyglyph/) is a module that does exactly this. I downloaded PyGlyph, but it's not clear what to do with it to make it work. I tried putting the pyglyph subdirectory into C:\Python24\Lib\site-packages, which allowed me to "import pyglyph", but attempting to run "hello.py" gave me this: Traceback (most recent call last): File "C:\Code\pyglyph_example\hello.py", line 56, in ? HelloExample().run() File "C:\Documents and Settings\Owner\Desktop\pyglyph-0.1\example\example_base.py", line 60, in run self.init() File "C:\Code\pyglyph_example\hello.py", line 30, in init fonts = pyglyph.font.LocalFontFactory(font_dir) File "..\pyglyph\font.py", line 117, in __init__ File "..\pyglyph\font.py", line 130, in add File "..\pyglyph\font.py", line 132, in add File "..\pyglyph\ttf.py", line 93, in __init__ AttributeError: 'module' object has no attribute 'MAP_SHARED' RE TRANSPARENCY: By the way, my efforts at combining OpenGL and Pygame (plus looking at NeHe tutorials) have gotten me to this point: http://kschnee.xepher.net/pics/060916scurvy2.jpg And now to: http://kschnee.xepher.net/pics/060916scurvy3.jpg But there's still a problem with sprite transparency. No matter what format I use -- GIF, BMP, or PNG -- I can't seem to make OpenGL draw the sprite WITHOUT black/white areas around it and WITH full solidity in the areas of the character's actual body. (The properly drawn version in the sceenshot was Photoshopped in.) I've put the latest code at: http://kschnee.xepher.net/code/scurvy.py and http://kschnee.xepher.net/code/OpenGL_Tools.py if you want to see/use them. Free license; a simpler version of this would work as a Python translation of NeHe 43, which I of course stumbled across after coming up with the same thing. OpenGL somehow locks the display surface so that thou shalt not draw anything without it. Is there some way to use normal Pygame drawing methods to apply my existing code for windows, etc., or at least to switch to OpenGL's Ortho mode and then just put an image on the screen without going through the process of loading it as an OpenGL texture and worrying about having it loaded repeatedly, assigned to a textre number etc.? RE LISTS: I'm having trouble using display lists by the normal method! I have a simple gradient background, so I figured I'd make that a list first: def BuildList_Background(self): self.draw_lists["background"] = glGenLists(1) glNewList(self.draw_lists["background"],GL_COMPILE) ## Drawing stuff omitted. glEndList() def DrawBackground(self): glCallList(self.draw_lists["background"]) When I call the first function up front and then the second every frame, nothing seems to get drawn! What's going on? Kris