PNG image is blurry when loading onto texture

I created a png image in Photoshop with the transparencies I uploaded and the OpenGL program. I attached it to the texture, and in the program the image looks blurry, and I'm not sure why.

alt text http://img685.imageshack.us/img685/9130/upload2.png

alt text http://img695.imageshack.us/img695/2424/upload1e.png

Download Code

// Texture loading object nv::Image title; // Return true on success if(title.loadImageFromFile("test.png")) { glGenTextures(1, &titleTex); glBindTexture(GL_TEXTURE_2D, titleTex); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexImage2D(GL_TEXTURE_2D, 0, title.getInternalFormat(), title.getWidth(), title.getHeight(), 0, title.getFormat(), title.getType(), title.getLevel(0)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); } else MessageBox(NULL, "Failed to load texture", "End of the world", MB_OK | MB_ICONINFORMATION); 

Display Code

 glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, titleTex); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTranslatef(-800, 0, 0.0); glColor3f(1,1,1); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(0,0); glTexCoord2f(0.0, 1.0); glVertex2f(0,600); glTexCoord2f(1.0, 1.0); glVertex2f(1600,600); glTexCoord2f(1.0, 0.0); glVertex2f(1600,0); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); 

EDIT: I don't think I am stretching every pixel, there must be two in the coordinate system

 int width=800, height=600; int left = -400-(width-400); int right = 400+(width-400); int top = 400+(height-400); int bottom = -400-(height-400); gluOrtho2D(left,right,bottom,top); 
+4
source share
5 answers

OpenGL will (usually) require the texture itself to have a size of 2, so it may happen that your texture is scaled to a size where the sizes are 2, then it scales to its original size - during the scaling process, you lose quality twice.

You, apparently, just want to display the bitmap without any scaling, without wrapping it on the surface of another object or something like that (i.e. for any textures intended for objects). In this case, I would just display it as a bitmap and not a texture (for example, see glRasterPos2i and glBitmap ).

+3
source

Why do you want to use mipmapping and anisotropic filtering for a static image on the start screen in the first place? It seems unlikely that the image will be rotated (for what anisotropic filtering) or should be changed several times very quickly (which requires mipmapping).

If the texture is stretched: try using GL_NEAREST for your GL_MAG_FILTER , in which case it may give better results ( GL_LINEAR more accurate, but has a blurriness).

If texture is minimized: the same thing, try using GL_NEAREST_MIPMAP_NEAREST or better, try not using mipmaps and GL_NEAREST (or GL_LINEAR , whichever gives the best result).

+2
source

I suggest you make png a resolution of 2. Those. 1024x512 and place the part you want to draw in the upper left corner, still in screen resolution. Then drag texcoords to 800.0 / 1024.0 and 600.0 / 512.0 to get the desired part of the texture. I believe that what happens is that glTexImage2D can glTexImage2D handle widths and heights that have no power of 2, but then can scale the input image, thus filtering it.

An example of processing this can be viewed here (iPhone - OpenGLES - a project that captures part of the screen without permissions 2 and draws it into a 512x512 texture and drags the GL_TEXTURE matrix, line 123, instead of manually rescaling texcoords)

Here is another post that mentions this method.

+2
source

Here is the hypothesis:

Your window is 800x600 (and possibly your framebuffer too), but your client area is missing, due to the appearance of the window on the sides.

Thus, your frame buffer changes when changing in the client area of โ€‹โ€‹your window. Can you check the window creation code?

+1
source
  • Beware of the exact size of the client area of โ€‹โ€‹your window. A double check is what you expect from it.
  • Beware of pixel alignment rules. You may need to add 0.5 to the x / y coordinates to get to the centers of the pixels. A description for DirectX can be found here - however, OpenGL rules may vary.
0
source

Source: https://habr.com/ru/post/1308177/


All Articles