[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] antialiasing problems



My monitor has 2 thin black lines all the time. Does yours have it when you are not running the program? On a White screen?

On 1/8/06, michael gross < mich@xxxxxxxxx> wrote:
> Your e-mail has no attachment in my mail browser.  Perhaps the mailing
> list
> stripped it?
>
ok the code is down there. just put it in a folder with an other image and
run it. that should work. Im am wondering how I can get ride of this thin
black line which crosses the image.

best michael

import os, random
from string import split
from math import sin, cos
from OpenGL.GL import *
from OpenGL.GLU import *
import pygame, pygame.image, pygame.key
from pygame.locals import *


textures = []

yrot = 0.0
xpos = 0.0
zpos = 0.0

x1 = 0
a = 0

def resize((width, height)):
    if height==0:
        height=1.0
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45, float(width)/height, 0.1, 100.0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

def load_textures():
    global textures

    texturefile = "test.bmp"
    textureSurface = pygame.image.load(texturefile)
    textureSurface = pygame.transform.scale(textureSurface,(512,512))
    textureData = pygame.image.tostring(textureSurface, "RGBA", 1)

    #textures = glGenTextures(3)

    glBindTexture(GL_TEXTURE_2D, 0) #textures[0])
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
#GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
#GL_LINEAR)#
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, textureSurface.get_width(),
textureSurface.get_height(), 0,
                  GL_RGBA, GL_UNSIGNED_BYTE, textureData )

def init():

    glEnable(GL_TEXTURE_2D)

    glShadeModel(GL_SMOOTH)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glClearDepth(1.0)

    glEnable (GL_BLEND)
    glDisable (GL_DEPTH_TEST);

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    #this enables the antialiasing for polygons
    glEnable(GL_POLYGON_SMOOTH)

    glPolygonMode(GL_FRONT, GL_FILL)
    glDepthFunc(GL_LEQUAL)

    load_textures()


def draw():
    global xpos, zpos, yrot
    global textures, filter, tris, x1

    xtrans = -xpos
    ztrans = -zpos



    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )

    glLoadIdentity()
    glTranslatef(a*0.1, 0.0, -10)

    glRotatef(a*20,0,1.0,1.0)
    glTranslatef(0.1,0.0,0.0)

    #glBindTexture( GL_TEXTURE_2D, 0)  #textures[filter] )

    glBindTexture(GL_TEXTURE_2D, 0);
    glColor4f(1,1,1,1);

    glBegin(GL_QUADS)
    # Front Face (note that the texture's corners have to match the quad's
corners)
    glTexCoord2f(0.0, 0.0);
    glVertex3f(-1.0, -1.0,  1.0)    # Bottom Left Of The Texture and Quad

    glTexCoord2f(1.0, 0.0);
    glVertex3f( a*1, -1.0,  1.0)    # Bottom Right Of The Texture and Quad

    glTexCoord2f(1.0, 1.0);
    glVertex3f( a*1,  1.0,  1.0)    # Top Right Of The Texture and Quad

    glTexCoord2f(0.0, 1.0);
    glVertex3f(-1.0,  1.0,  1.0)

    glEnd()

def main():

    global surface, x1, a




    video_flags = OPENGL|DOUBLEBUF

    pygame.init()
    surface = pygame.display.set_mode((640,480), video_flags)
    pygame.key.set_repeat(100,0)

    resize((640,480))
    init()


    frames = 0
    done = 0
    ticks = pygame.time.get_ticks()
    while not done:
        while 1:
            event = pygame.event.poll()
            if event.type == NOEVENT:
                break
            if event.type == QUIT:
                done = 1

        x1 = x1 - 0.00005
        a = a + 0.001

        draw()
        pygame.display.flip()
        frames += 1


    print "fps:  %d" % ((frames*1000)/(pygame.time.get_ticks()-ticks))


if __name__ == '__main__': main()