opengl - PyOpenGL Transformation Blur -
i know how create opengl not "blur" upscaled texture, seems bluring set default transformations. texure pot png file. code used define texture , set on screen this:
class texture(): # simple texture class # designed 32 bit png images (with alpha channel) def __init__(self,filename): self.texid=0 self.loadtexture(filename) def loadtexture(self,filename): try: texturesurface = pygame.image.load(filename).convert_alpha() texturedata = pygame.image.tostring(texturesurface, "rgba", true) self.w, self.h = texturesurface.get_size() self.texid=glgentextures(1) glbindtexture(gl_texture_2d, self.texid) gltexparameteri(gl_texture_2d,gl_texture_mag_filter,gl_linear) gltexparameteri(gl_texture_2d,gl_texture_min_filter,gl_linear) glteximage2d( gl_texture_2d, 0, gl_rgba, texturesurface.get_width(), texturesurface.get_height(), 0, gl_rgba, gl_unsigned_byte, texturedata ) except exception e: print(e) print ("can't open texture: %s"%(filename)) def __del__(self): gldeletetextures(self.texid) def get_width(self): homecoming self.w def get_height(self): homecoming self.h def blit(texture, x, y): """ function blits given texture on screen """ #we set texture onto screen glbindtexture(gl_texture_2d, texture.texid) #now must position image glbegin(gl_quads) #we calculate each of points relative center of screen top = -y/(height//2) + 1.0 left = x/(width//2) - 1.0 right = left + texture.w/(width//2) downwards = top - texture.h/(height//2) #we position each point of image gltexcoord2f(0.0, 1.0) glvertex2f(left, top) gltexcoord2f(1.0,1.0) glvertex2f(right, top) gltexcoord2f(1.0,0.0) glvertex2f(right, down) gltexcoord2f(0.0,0.0) glvertex2f(left, down) glend()
i configured opengl follows:
def configureopengl(w, h): #glshademodel(gl_smooth) #glclearcolor(0.0, 0.0, 0.0, 1.0) #glclear(gl_color_buffer_bit | gl_depth_buffer_bit) glviewport(0, 0, w, h) glmatrixmode(gl_projection) #glloadidentity() #gluortho2d(-8.0, 8.0, -6.0, 6.0) glmatrixmode(gl_modelview) glloadidentity() glshademodel(gl_smooth) glclearcolor(0.0, 0.0, 0.0, 0.0) glcleardepth(1.0) gldisable(gl_depth_test) gldisable(gl_lighting) gldepthfunc(gl_lequal) glhint(gl_perspective_correction_hint, gl_nicest) glenable(gl_blend) surface = pygame.display.set_mode((width, height), opengl|doublebuf)#|fullscreen) configureopengl(width, height)
before putting in screen phone call method:
def openglrender(self): """ used prepare screen render """ glclear(gl_color_buffer_bit|gl_depth_buffer_bit) glloadidentity() gldisable(gl_lighting) glenable(gl_texture_2d) glblendfunc(gl_src_alpha, gl_one_minus_src_alpha) glclearcolor(1.0, 1.0, 1.0, 1.0)
i'm using pyopengl 3.0.2
use gl_nearest
in gltexparameteri()
calls:
gltexparameteri(gl_texture_2d,gl_texture_mag_filter,gl_nearest) gltexparameteri(gl_texture_2d,gl_texture_min_filter,gl_nearest)
opengl python-3.x resize pygame pyopengl
No comments:
Post a Comment