1

I am replacing the OpenGL code of my app with code that uses OpenSceneGraph.

I am working with large images (resolution higher than 5000x5000px), therefore images are split into smaller tiles.

The OpenGL code to draw the tiles uses glTexImage2D(GL_TEXTURE_2D, ..., imageData), where imageData is the tile byte array.

With OpenSceneGraph, I create an osg::Image with the same imageData and use this osg::Image to texture a simple quad.

The problem is that I have an ugly display resulting for certain osg::Image dimensions.

For tiles likes 256x128, everything is OK.

That's how the original image loogs with OpenGL enter image description here

But here's how it looks for 254x130 tile and osg::Image:

enter image description here

I would like to understand what the problem is. Since OpenSceneGraph is based on OpenGL, I guess the OpenSceneGraph code I wrote is equivalent to the old OpenGL one. Furthermore, I cannot change the tile size, so I really need to make it work with 254x130 tiles.

image creation code :

`osg::Image * image = new osg::Image();
//width, height, textFormat, pixelFormat, type and data 
//are the ones that were used with glTexImage2D
image->setImage(width, height, 1, textFormat, pixelFormat, type, data, NO_DELETE);
osg::Texture2D * texture = new osg::Texture2D;
texture->setImage(image);
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);`
Krag
  • 79
  • 1
  • 9
  • Please share some code on how you create, allocate and fill the osg::Image - is the wrong image even supposed to be black and white? – rickyviking Apr 29 '16 at 09:05
  • I added some code in the original message. And the grey image is supposed to look like the green one. I also noticed that every tiles are tilted. – Krag Apr 29 '16 at 12:09

1 Answers1

0

I think it's most likely a mismatch between the pixel data and the format/type you pass to setImage().
For instance, if your image data is RGB with one byte per color, you should call

 image->setImage(w, h, 1, GL_RGBA8, GL_RGB, GL_UNSIGNED_BYTE, data, osg::Image::NO_DELETE);

If your texture is flipped vertically, it's because openGL always consider the texture origin in the bottom left corner, so you either have to flip the image data before invoking setImage() (or invert the UV coordinates of your geometries).

rickyviking
  • 846
  • 6
  • 17
  • I made some test in that direction, and no, the pixel data, format and type are ok. For a fixed set of pixel data, format type and source image, the only factor ruining the display is OpenSceneGraph AND non multiple of 4 tile size. – Krag May 02 '16 at 07:47