我想知道如何使openGL不会模糊"一个放大的纹理,因为看起来bluring被设置为转换的默认值。 texure是一个POT png文件。用于定义纹理并将其放在屏幕上的代码如下:
class Texture():
# simple texture class
# designed for 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 as E:
print(E)
print ("can't open the texture: %s"%(fileName))
def __del__(self):
glDeleteTextures(self.texID)
def get_width(self):
return self.w
def get_height(self):
return self.h
def blit(texture, x, y):
"""
Function that blits a given texture on the screen
"""
#We put the texture onto the screen
glBindTexture(GL_TEXTURE_2D, texture.texID)
#Now we must position the image
glBegin(GL_QUADS)
#We calculate each of the points relative to the center of the screen
top = -y/(HEIGHT//2) + 1.0
left = x/(WIDTH//2) - 1.0
right = left + texture.w/(WIDTH//2)
down = top - texture.h/(HEIGHT//2)
#We position each point of the 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()
我按如下方式配置了openGL:
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)
在将任何内容放入屏幕之前,我也称之为:
def OpenGLRender(self):
"""
Used to prepare the screen to 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)
我正在使用PyOpenGL 3.0.2
答案 0 :(得分:1)
在GL_NEAREST
来电中使用glTexParameteri()
:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)