2

I have troubles with using Textures in OpenGl (only 2D)

I want to show a Level (size 15x15) and every Field can have a different value/Picture.
I have about 100 different Fieldtypes and according to the leveldesign, I have to display a different image for every type.
If I use an single tga-Image for every possible Field (100 files), everything works fine, but now I put all Images together in one File and, depending on the field-type, I'm always displaying a different part from the image.

The Problem: sometimes thin Lines in the images aren't displayed and between the different sprites, there are often black or gray lines which makes the whole graphics ugly.

Is there a way to solve this problem easily?
(Maybe I have to load the tga-image into one GLuint and then split it up into 100 different GLunint's? Or is there an setting to improve the rendering? Or do I have to change the resolution of the tga-image file itself?)

Here's a part of my image-File, every element has a resolution of 220x220 pixels --> whole pic.: 2200x2200 pixels Sprite-Images

And that's the OpenGl-output:
OpenGl-Output

I really don't want to have hundrets of image-files. Especially because loading all these Files consumes a lot of time and I'm sure there's a solution out there

EDIT:

I'm using the following settings:

// Specify filtering and edge actions
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

EDIT2:

Now I changed GL_LINEAR to GL_NEAREST and added a half texel in the texture-coordinates there are no lines between the images anymore :)
But I still have the other problem:
pixel-bug
Small elements (lines) in the image aren't displayed correctly.
This is how it should look like:
howitshouldlook

maja
  • 17,250
  • 17
  • 82
  • 125

2 Answers2

2

"Keep in mind, that OpenGL samples textures at the texel centers"

Have a look at the answer here: OpenGL ES Texture Coordinates Slightly Off

Community
  • 1
  • 1
D-rk
  • 5,513
  • 1
  • 37
  • 55
  • thanks, that explained and solved the problem with the black and gray lines everywhere – maja Oct 29 '12 at 15:54
  • isn't that because of your change from GL_LINEAR to GL_NEAREST? how does it look with GL_LiNEAR? – D-rk Oct 29 '12 at 20:32
  • no the lines were due to the half texel. When I change GL_LINEAR with GL_NEAREST now, I can't see any differences – maja Oct 31 '12 at 17:26
  • the elements in the image with the missing lines seem to be smaller than in the one below. Perhaps thats why it doesn't happen in the bottom image? – D-rk Oct 31 '12 at 18:49
  • Wow, when I thought the program which has one file for every field would work perfectly, but when I decrease the resolution, I have the same problem - so you are right But Is there a way to change the rendering in order to display even small details correctly? – maja Nov 01 '12 at 18:41
  • you could try to use mipmapping (see: glGenerateMipmap) but I'm not sure if it helps: Suppose you have a texture with a 1 pixel thick vertical line and now you shrink the texture along the x-axis. At some point the line thickness in the shrunk texture goes from 1 to 0 and the line is gone. – D-rk Nov 01 '12 at 18:53
0

You need to add padding pixels to your textures, to avoid lines along their edges. So that when OpenGL samples pixels from texture to be drawn (including mipmap levels if you render them in smaller size than they are in your files), there are no wrongly colored pixels used.

Kromster
  • 7,181
  • 7
  • 63
  • 111