How to disable blur effect on textures with OpenGL? - opengl

I am using Texture-Mapped fonts in my OpenGL program.
I have drawn very basic fonts in a bitmap (each letter is 5x7 pixels, white on black background).
When displayed on a quad that makes more than a few pixels large, OpenGL is making some work to make the image smooth.
Is there an easy way to temporarily get rid of that blur effect ?

Try glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ).

Related

Opengl 4.0 Texture issue

Hi I am trying to render texture on a rectangle. I am using GL_CLAMP_TO_BORDER because I dont want texture to repeat itself.
glTextureParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTextureParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
I am expecting output to be something like this : Notice non-texels are grey which is its face color.
But I am getting this output :
Area mentioned in no 2 I guess can be resolved if I enable the blending but I am not getting any solution for Area 1.
I know I havn't shared any code because I really can't ,is there any additional gl calls I need to make to resolve the issue ?
GL_CLAMP_TO_BORDER clamps to the border color defined in the texture/sampler object. That is, texture coordinates outside the [0, 1] range will fetch that border color.
If you didn't set that border color, it will likely be black.
The clamping mode you probably want is GL_CLAMP_TO_EDGE. That means that the color you get for out-of-range fetches is the color of the nearest edge texels of the texture.

Pango text gets blurring when GL viewport is changed

I am working with a piece of code which was rendering a texture containing text written using Pango, in a particular GL viewport. I have now had to change the viewport, and put the texture at a different z-distance, however, the text has become blurry. I have tried changing the font size, style, etc., but no success.
I am new to Pango, and this is a rather generic question, but any pointers to what could be the reason will be helpful.
Could it be mipmapping is kicking in because of the larger z-distance? Could you try to apply
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
to the texture you are rendering the text in?

OpenGL: GL_REPEAT and GL_CLAMP_TO_EDGE

Im working on my game project with OGL 3.2 and I was using GL_REPEAT in the texture parameters to set up my terrain very fast by defining ST coordinates more than (1;1). But now, when I've added a skybox, an edges between skybox textures looks very scratchy and I don't want them to be. I can remove them by using GL_CLAMP_TO_EDGE parameter, but terrain texture renders wrong without GL_REPEAT parameter. So I must choose between GL_REPEAT and GL_CLAMP_TO_EDGE. If I switch it to GL_CLAMP_TO_EDGE I can't use GL_REPEAT advantage and have to divide my terrain to smaller chunks and give texture to each one by one, which is (in my opinion) very inefficient, especially when I want huge sized map.
Is there any way to use both advantages of GL_REPEAT and GL_CLAMP_TO_EDGE or maybe there is some more awesome way to solve this which I don't know?
You can use both at once. The texture wrapping mode is stored on a per-texture basis, so use GL_REPEAT for your ground texture and GL_CLAMP_TO_EDGE for your sky texture.
Set it for each texture immediately after (or immediately before, just as long as the texture is bound) uploading the texture image.

OpenGL multitexture tessellation

I have to tessellate some surface in OpenGL with rectangular textures. Let it be a single triangle for simplicity. The textures touch each other by sides, and do not overlap. That is done by setting GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_CLAMP_TO_BORDER and adjusting texture coords properly. Everything goes fine while GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER is set to GL_NEAREST, but when I want to apply GL_LINEAR filering and/or anisotropic filtering following arifact apperas: textures border pixel's alpha gradually fall to transparent, so that line of background color is visible between neighbouring textures.
How can I avoid this artifact without merging multiple textures to one while linear filtering is preserved?
You probably want GL_CLAMP_TO_EDGE instead of GL_CLAMP_TO_BORDER. Clamp to border mixes the edge pixel with the border color, which is initialized to (0,0,0,0). This is where your transparency is coming from.
Either clamp the texture to the actual edge, or set a border color that is nontransparent.

OpenGL texture color issue

I'm loading raw texture (with alpha channel) and displaying it in openGL everything is fine and texture displayed, but color is little bit darker than original. I already tried to turn of lighting, blending and dithering, but this doesn't helps.
I'm using mac osx.
Sample image
http://postimage.org/image/2wi1x5jic/
Here's openGL texture loading source code:
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 , width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &bytes[0]);
EDIT:
Thats very weird, I used example from http://forums.tigsource.com/index.php?topic=9560.0
and received same glitch ... So the problem not im my code, maybe driver options? Hm ...
SOLUTION:
Thanks #datenwolf, images were saved with sRrgb color profile. Problem is solved once I removed it and converted to RGB.
Maybe you have GL_MODULATE set as texturing environment and the vertex colours are not white. Try setting the texture environment to GL_REPLACE.
glBindTexture(GL_TEXTURE_2D, your_texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
EDIT
Another problem may be a color profile embedded into the image. A image viewer may use this colour profile to implement color management, adjusting the colours for your monitor's colour profile. OpenGL as-it-is doesn't do color management; there is a extension, that framebuffers and textures are sRGB, this is kind of the smallest common denominator of colour management. But then you'd still have to transfer your input images to sRGB colour space.
I've a lengthy article in preparation the explains in depth how to do colour management with OpenGL. But it's far from complete.