-1

I am using OpenGL to as part of a drawing application for iOS. When the user finishes drawing the texture is saved to a jpg using SOIL. The image appears correct in the view, when saved the output is oriented correctly (after inverting the image) but the image is scaled to a smaller size (based on device.. higher res devices produce smaller images) than what I am expecting.

The process I am following is:

unsigned char *pixels = (unsigned char*)malloc( 4* imgwidth* imgheight);
glBindTexture(GL_TEXTURE_2D, 0);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, imgwidth, imgheight);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 
glPixelStorei (GL_UNPACK_SKIP_ROWS, 1);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, 1);
glReadPixels(0, 0, imgwidth, imgheight, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) pixels);
invertPixels(pixels);
int result;
result = SOIL_save_image_quality(imagepath, SOIL_SAVE_TYPE_JPG, d, imgheight, 4, pixel_data, 99);
delete [] pixel;

I have analyzed the inversion algorithm to death and am confident its doing its job, without it the image is the same size but upside down. What could be causing this? Do I need to rescale my texture?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Randoramma
  • 123
  • 9

1 Answers1

0

I think this is related to contentsScale of your CAEAGLLayer (or contentScaleFactor of your GLKView). You can check the value of your application, which should be either 1.0, 2.0 or 3.0. The 1.0 gives us poor quality on retina displays. When we create textures for retina, we need to scale the size with contentScale of CAEAGLLayer for expected results. I mean we need to create larger size textures if not 1.0. I haven't used SOIL, but the opposite should be true. Therefore, I think, to get the image size you expect, you need to scale your images.

Note as noted here, we can change the contentsScale to trade quality for performance. My OpenGL app always sets contentScale to 2.0 even for iphone7+ for better rendering performance. So, don't hard code like iphone7 is 2.0 or iphone7+ is 3.0.

beshio
  • 794
  • 2
  • 7
  • 17
  • Thank you for your suggestion. Your post has helped me get closer to the issue, but adjusting the content scaling factor alone isn't the solution for me. By increasing the contentScalingFactor the image size is closer to expected, but now I have determined that it is also off center, (0,0,w,h) is cutting off the bottom and left of the image. The post (https://stackoverflow.com/questions/9155515/glreadpixels-only-saves-1-4-screen-size-snapshots) may be more what I am experiencing. I am working in c++ and not Obj-C and SOIL prevents changing the frame buffer type from unsigned byte. – Randoramma Sep 19 '17 at 19:11
  • Quick question: WAS your original content scaling 1.0 ? – beshio Sep 20 '17 at 00:21
  • No, it was set automatically by the EAGLcontext based on the device type. – Randoramma Sep 20 '17 at 16:33