Reputation: 504
I have x.png
image which contains 4 pixels(let it be square) with collors: red, green, blue and 4-th is transparent.
I need to find combination of arguments glEnable() and/or glBlendFunc() which will give following effect:
1) Texture applies without "smoothing", just sharp pixel edges.
2) Transtarent pixel is transparent.
def set_3d(self):
...
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glTranslatef(x, y, z) # for getting scale image
...
# + here is adding background rect(blue) and rect with 4 pixels
def add_alpha_rect(self, batch):
... # getting textures, etc.
batch.add(
4, GL_QUADS,
texture_group,
('v3f', (x, y, z,
x_, y, z,
x_, y_, z
x, y_, z)),
('t3f', (0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0)))
How I can achive that result?
Is it possible?
Upvotes: 0
Views: 101
Reputation: 211126
You have to set the texture magnification function. This filter is used when the texture is magnified.
The magnification function can be set by glTexParameteri
. Possible values are GL_LINEAR
and GL_NEAREST
. The initial value is GL_LINEAR
.
Apply the magnification parameter GL_NEAREST
to the bound texture object, to solve your issue:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
Note while the parameter GL_LINEAR
would cause that the weighted average of the 4 texture elements that are closest to the specified texture coordinates are returned, GL_NEAREST
causes that the value of the texture element that is nearest is returned, when the texture is looked up.
Upvotes: 3