Problems with copyContentsToMemory and device orientation

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Problems with copyContentsToMemory and device orientation

Post by Brocan »

Hi all,

I'm trying to make an screenshot to save it in an UIImage and store in the photo album, but i'm dealing with tons of problems.

First of all, I need to have the viewport rotations locked, i never call the function setNeedsLayout, but i dont know if this is enough or ogre internally takes care about orientations....

After all, the moment to take the screenshot arrives. If i start ogre with portrait orientation, all runs "well", i can make an screenshot (although its vertically flipped), even if i rotate the phone the photos are right taken.

But if i start the app in other orientation mode "Landscape Left" or "Landscape Right" (specified in ogre.cfg) the images are broken. Although i'm in landscape, the image is created with 480x320 but the function copyContentsToMemory returns a portrait image with a 160 white pixels (i'm running in 3Gs with 480x320) at right, of course the image is cut in the bottom (is like if the copyContentsToMemory always returns a 320x480 image...). I've tried to swap witdh and height, but i get crashes or malformed images (with white pixels also!). Even, if I run in landscape mode, and move the phone to portrait, then the image is all white.

Plus, sometimes, when i push the screenshot button, the whole image is white! can be any kind of threading problem?

Here is the code where i call the function, this code has been changed several times:

Code: Select all

int left, top, width, height;
m_pOgreViewport->getActualDimensions(left, top, width, height);
	
Ogre::PixelFormat format = Ogre::PF_BYTE_RGBA;
outWidth = width;
outHeight = height;
outBytesPerPixel = Ogre::PixelUtil::getNumElemBytes(format);
	
printf("Left %d, Top %d, Width: %d, Height: %d\n", left, top, width, height);
	
unsigned char *data = new unsigned char [outWidth*outHeight*outBytesPerPixel];
//Ogre::PixelBox box = Ogre::PixelBox(outWidth, outHeight, 1, format, data);
//m_pOgreRenderWnd->copyContentsToMemory(box);
	
//Ogre::uchar *data = OGRE_ALLOC_T(Ogre::uchar, width * height * outBytesPerPixel, Ogre::MEMCATEGORY_RENDERSYS);
Ogre::Box extents(left, top, left + width, top + height);
Ogre::PixelBox pb(extents, format, data);
	
printf("PixelBox: %d, %d, w: %d, h: %d\n", pb.left, pb.right, pb.getWidth(), pb.getHeight());
	
m_pOgreRenderWnd->copyContentsToMemory(pb);
Furthermore, if I use a PF_BYTE_RGB i get a beautiful seg fault when copyContentsToMemory is called :(
2011-08-02 11:36:42.521 Ogre[546:307] **** Taking screenshot
Left 0, Top 0, Width: 480, Height: 320
PixelBox: 0, 480, w: 480, h: 320
Assertion failed: (_Unwind_SjLj_Resume() can't return), function _Unwind_SjLj_Resume, file /SourceCache/libunwind/libunwind-24.1/src/Unwind-sjlj.c, line 326.
Program received signal: “SIGABRT”.
Any ideas?

I'm running in IPhone 3Gs, Ogre 1.7.3, iOS SDK 4.3, target platform 4.1, compiling for device, and device running iOS 4.2.1.

Thanks in advance!

PS: Ogre.log in landscape right

Code: Select all

Creating resource group General
Creating resource group Internal
Creating resource group Autodetect
SceneManagerFactory for type 'DefaultSceneManager' registered.
Registering ResourceManager for type Material
Registering ResourceManager for type Mesh
Registering ResourceManager for type Skeleton
MovableObjectFactory for type 'ParticleSystem' registered.
OverlayElementFactory for type Panel registered.
OverlayElementFactory for type BorderPanel registered.
OverlayElementFactory for type TextArea registered.
Registering ResourceManager for type Font
ArchiveFactory for archive type FileSystem registered.
ArchiveFactory for archive type Zip registered.
DDS codec registering
FreeImage version: 3.15.0
This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
Supported formats: jpg,jif,jpeg,jpe,png,tga,targa,tif,tiff
PVRTC codec registering
Registering ResourceManager for type HighLevelGpuProgram
Registering ResourceManager for type Compositor
MovableObjectFactory for type 'Entity' registered.
MovableObjectFactory for type 'Light' registered.
MovableObjectFactory for type 'BillboardSet' registered.
MovableObjectFactory for type 'ManualObject' registered.
MovableObjectFactory for type 'BillboardChain' registered.
MovableObjectFactory for type 'RibbonTrail' registered.
*-*-* OGRE Initialising
*-*-* Version 1.7.3 (Cthugha)
Installing plugin: OpenGL ES 1.x RenderSystem
OpenGL ES 1.x Rendering Subsystem created.
Plugin successfully installed
CPU Identifier & Features
-------------------------
 *   CPU ID: ARMv7
 *      VFP: no
 *     NEON: yes
-------------------------
GLESRenderSystem::_createRenderWindow "Test", 320x480 fullscreen  miscParams: FSAA=4x contentScalingFactor=1 displayFrequency=0 Hz orientation=Landscape Right 
iOS: Window created 320 x 480 with backing store size 320 x 480 using content scaling factor 1.0
GL_VERSION = OpenGL ES-CM 1.1 IMGSGX535-48.20
GL_VENDOR = Imagination Technologies
GL_RENDERER = PowerVR SGX 535
GL_EXTENSIONS = GL_APPLE_framebuffer_multisample GL_APPLE_texture_2D_limited_npot GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_EXT_read_format_bgra GL_EXT_texture_filter_anisotropic GL_EXT_texture_lod_bias GL_IMG_read_format GL_IMG_texture_compression_pvrtc GL_OES_blend_equation_separate GL_OES_blend_func_separate GL_OES_blend_subtract GL_OES_compressed_paletted_texture GL_OES_depth24 GL_OES_draw_texture GL_OES_fbo_render_mipmap GL_OES_framebuffer_object GL_OES_mapbuffer GL_OES_matrix_palette GL_OES_packed_depth_stencil GL_OES_point_size_array GL_OES_point_sprite GL_OES_read_format GL_OES_rgb8_rgba8 GL_OES_stencil8 GL_OES_stencil_wrap GL_OES_texture_mirrored_repeat GL_OES_vertex_array_object 
EXT:GL_APPLE_framebuffer_multisample
EXT:GL_APPLE_texture_2D_limited_npot
EXT:GL_APPLE_texture_format_BGRA8888
EXT:GL_APPLE_texture_max_level
EXT:GL_EXT_blend_minmax
EXT:GL_EXT_discard_framebuffer
EXT:GL_EXT_read_format_bgra
EXT:GL_EXT_texture_filter_anisotropic
EXT:GL_EXT_texture_lod_bias
EXT:GL_IMG_read_format
EXT:GL_IMG_texture_compression_pvrtc
EXT:GL_OES_blend_equation_separate
EXT:GL_OES_blend_func_separate
EXT:GL_OES_blend_subtract
EXT:GL_OES_compressed_paletted_texture
EXT:GL_OES_depth24
EXT:GL_OES_draw_texture
EXT:GL_OES_fbo_render_mipmap
EXT:GL_OES_framebuffer_object
EXT:GL_OES_mapbuffer
EXT:GL_OES_matrix_palette
EXT:GL_OES_packed_depth_stencil
EXT:GL_OES_point_size_array
EXT:GL_OES_point_sprite
EXT:GL_OES_read_format
EXT:GL_OES_rgb8_rgba8
EXT:GL_OES_stencil8
EXT:GL_OES_stencil_wrap
EXT:GL_OES_texture_mirrored_repeat
EXT:GL_OES_vertex_array_object
**************************************
*** OpenGL ES 1.x Renderer Started ***
**************************************
Registering ResourceManager for type GpuProgram
GL ES: Using GL_OES_framebuffer_object for rendering to textures (best)
FBO PF_UNKNOWN depth/stencil support: D16S0 D24S0 Packed-D24S8 
FBO PF_R5G6B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_B5G6R5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_A4R4G4B4 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_A1R5G5B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_A8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_X8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_X8B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
[GLES] : Valid FBO targets PF_UNKNOWN PF_R5G6B5 PF_B5G6R5 PF_A4R4G4B4 PF_A1R5G5B5 PF_R8G8B8 PF_B8G8R8 PF_A8R8G8B8 PF_X8R8G8B8 PF_X8B8G8R8 
RenderSystem capabilities
-------------------------
RenderSystem Name: OpenGL ES 1.x Rendering Subsystem
GPU Vendor: imagination technologies
Device Name: PowerVR SGX 535
Driver Version: 0.0.0.0
 * Fixed function pipeline: yes
 * Hardware generation of mipmaps: yes
 * Texture blending: yes
 * Anisotropic texture filtering: yes
 * Dot product texture operation: yes
 * Cube mapping: no
 * Hardware stencil buffer: no
 * Hardware vertex / index buffers: yes
 * Vertex programs: no
 * Number of floating-point constants for vertex programs: 0
 * Number of integer constants for vertex programs: 0
 * Number of boolean constants for vertex programs: 0
 * Fragment programs: no
 * Number of floating-point constants for fragment programs: 0
 * Number of integer constants for fragment programs: 0
 * Number of boolean constants for fragment programs: 0
 * Geometry programs: no
 * Number of floating-point constants for geometry programs: 0
 * Number of integer constants for geometry programs: 0
 * Number of boolean constants for geometry programs: 0
 * Supported Shader Profiles:
 * Texture Compression: yes
   - DXT: no
   - VTC: no
   - PVRTC: yes
 * Scissor Rectangle: yes
 * Hardware Occlusion Query: no
 * User clip planes: yes
 * VET_UBYTE4 vertex element type: yes
 * Infinite far plane projection: yes
 * Hardware render-to-texture: yes
 * Floating point textures: no
 * Non-power-of-two textures: no
 * Volume textures: no
 * Multiple Render Targets: 1
   - With different bit depths: no
 * Point Sprites: yes
 * Extended point parameters: yes
 * Max Point Size: 511
 * Vertex texture fetch: no
 * Number of world matrices: 0
 * Number of texture units: 8
 * Stencil buffer depth: 0
 * Number of vertex blend matrices: 0
 * Render to Vertex Buffer : no
 * GL 1.5 without VBO workaround: no
 * Frame Buffer objects: yes
 * Frame Buffer objects (ARB extension): no
 * Frame Buffer objects (ATI extension): no
 * PBuffer support: no
 * GL 1.5 without HW-occlusion workaround: no
Registering ResourceManager for type Texture
DefaultWorkQueue('Root') initialising on thread 0x83f930.
DefaultWorkQueue('Root')::WorkerFunc - thread 0x845b40 starting.
Particle Renderer Type 'billboard' registered
****** BundlePath /var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app
Creating resource group Bootstrap
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./OgreCore.zip' of type 'Zip' to resource group 'Bootstrap'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/.' of type 'FileSystem' to resource group 'General'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./media' of type 'FileSystem' to resource group 'General'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./media/materials' of type 'FileSystem' to resource group 'General'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./media/models' of type 'FileSystem' to resource group 'General'
Parsing scripts for resource group Autodetect
Finished parsing scripts for resource group Autodetect
Parsing scripts for resource group Bootstrap
Parsing script OgreCore.material
Parsing script OgreProfiler.material
Parsing script Ogre.fontdef
Parsing script OgreDebugPanel.overlay
Texture: New_Ogre_Border_Center.png: Loading 1 faces(PF_A8B8G8R8,256x128x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x128x1.
Texture: New_Ogre_Border.png: Loading 1 faces(PF_A8B8G8R8,256x256x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x256x1.
Texture: New_Ogre_Border_Break.png: Loading 1 faces(PF_A8B8G8R8,32x32x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,32x32x1.
Texture: ogretext.png: Loading 1 faces(PF_A8B8G8R8,256x128x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x128x1.
Parsing script OgreLoadingPanel.overlay
Finished parsing scripts for resource group Bootstrap
Parsing scripts for resource group General
Parsing script Ogre.material
Parsing script barco.material
Finished parsing scripts for resource group General
Parsing scripts for resource group Internal
Finished parsing scripts for resource group Internal
And in portrait mode:

Code: Select all

Creating resource group General
Creating resource group Internal
Creating resource group Autodetect
SceneManagerFactory for type 'DefaultSceneManager' registered.
Registering ResourceManager for type Material
Registering ResourceManager for type Mesh
Registering ResourceManager for type Skeleton
MovableObjectFactory for type 'ParticleSystem' registered.
OverlayElementFactory for type Panel registered.
OverlayElementFactory for type BorderPanel registered.
OverlayElementFactory for type TextArea registered.
Registering ResourceManager for type Font
ArchiveFactory for archive type FileSystem registered.
ArchiveFactory for archive type Zip registered.
DDS codec registering
FreeImage version: 3.15.0
This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
Supported formats: jpg,jif,jpeg,jpe,png,tga,targa,tif,tiff
PVRTC codec registering
Registering ResourceManager for type HighLevelGpuProgram
Registering ResourceManager for type Compositor
MovableObjectFactory for type 'Entity' registered.
MovableObjectFactory for type 'Light' registered.
MovableObjectFactory for type 'BillboardSet' registered.
MovableObjectFactory for type 'ManualObject' registered.
MovableObjectFactory for type 'BillboardChain' registered.
MovableObjectFactory for type 'RibbonTrail' registered.
*-*-* OGRE Initialising
*-*-* Version 1.7.3 (Cthugha)
Installing plugin: OpenGL ES 1.x RenderSystem
OpenGL ES 1.x Rendering Subsystem created.
Plugin successfully installed
CPU Identifier & Features
-------------------------
 *   CPU ID: ARMv7
 *      VFP: no
 *     NEON: yes
-------------------------
GLESRenderSystem::_createRenderWindow "Test", 320x480 fullscreen  miscParams: FSAA=4x contentScalingFactor=1 displayFrequency=0 Hz orientation=Portrait 
iOS: Window created 320 x 480 with backing store size 320 x 480 using content scaling factor 1.0
GL_VERSION = OpenGL ES-CM 1.1 IMGSGX535-48.20
GL_VENDOR = Imagination Technologies
GL_RENDERER = PowerVR SGX 535
GL_EXTENSIONS = GL_APPLE_framebuffer_multisample GL_APPLE_texture_2D_limited_npot GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_EXT_blend_minmax GL_EXT_discard_framebuffer GL_EXT_read_format_bgra GL_EXT_texture_filter_anisotropic GL_EXT_texture_lod_bias GL_IMG_read_format GL_IMG_texture_compression_pvrtc GL_OES_blend_equation_separate GL_OES_blend_func_separate GL_OES_blend_subtract GL_OES_compressed_paletted_texture GL_OES_depth24 GL_OES_draw_texture GL_OES_fbo_render_mipmap GL_OES_framebuffer_object GL_OES_mapbuffer GL_OES_matrix_palette GL_OES_packed_depth_stencil GL_OES_point_size_array GL_OES_point_sprite GL_OES_read_format GL_OES_rgb8_rgba8 GL_OES_stencil8 GL_OES_stencil_wrap GL_OES_texture_mirrored_repeat GL_OES_vertex_array_object 
EXT:GL_APPLE_framebuffer_multisample
EXT:GL_APPLE_texture_2D_limited_npot
EXT:GL_APPLE_texture_format_BGRA8888
EXT:GL_APPLE_texture_max_level
EXT:GL_EXT_blend_minmax
EXT:GL_EXT_discard_framebuffer
EXT:GL_EXT_read_format_bgra
EXT:GL_EXT_texture_filter_anisotropic
EXT:GL_EXT_texture_lod_bias
EXT:GL_IMG_read_format
EXT:GL_IMG_texture_compression_pvrtc
EXT:GL_OES_blend_equation_separate
EXT:GL_OES_blend_func_separate
EXT:GL_OES_blend_subtract
EXT:GL_OES_compressed_paletted_texture
EXT:GL_OES_depth24
EXT:GL_OES_draw_texture
EXT:GL_OES_fbo_render_mipmap
EXT:GL_OES_framebuffer_object
EXT:GL_OES_mapbuffer
EXT:GL_OES_matrix_palette
EXT:GL_OES_packed_depth_stencil
EXT:GL_OES_point_size_array
EXT:GL_OES_point_sprite
EXT:GL_OES_read_format
EXT:GL_OES_rgb8_rgba8
EXT:GL_OES_stencil8
EXT:GL_OES_stencil_wrap
EXT:GL_OES_texture_mirrored_repeat
EXT:GL_OES_vertex_array_object
**************************************
*** OpenGL ES 1.x Renderer Started ***
**************************************
Registering ResourceManager for type GpuProgram
GL ES: Using GL_OES_framebuffer_object for rendering to textures (best)
FBO PF_UNKNOWN depth/stencil support: D16S0 D24S0 Packed-D24S8 
FBO PF_R5G6B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_B5G6R5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_A4R4G4B4 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_A1R5G5B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_A8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_X8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
FBO PF_X8B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8 
[GLES] : Valid FBO targets PF_UNKNOWN PF_R5G6B5 PF_B5G6R5 PF_A4R4G4B4 PF_A1R5G5B5 PF_R8G8B8 PF_B8G8R8 PF_A8R8G8B8 PF_X8R8G8B8 PF_X8B8G8R8 
RenderSystem capabilities
-------------------------
RenderSystem Name: OpenGL ES 1.x Rendering Subsystem
GPU Vendor: imagination technologies
Device Name: PowerVR SGX 535
Driver Version: 0.0.0.0
 * Fixed function pipeline: yes
 * Hardware generation of mipmaps: yes
 * Texture blending: yes
 * Anisotropic texture filtering: yes
 * Dot product texture operation: yes
 * Cube mapping: no
 * Hardware stencil buffer: no
 * Hardware vertex / index buffers: yes
 * Vertex programs: no
 * Number of floating-point constants for vertex programs: 0
 * Number of integer constants for vertex programs: 0
 * Number of boolean constants for vertex programs: 0
 * Fragment programs: no
 * Number of floating-point constants for fragment programs: 0
 * Number of integer constants for fragment programs: 0
 * Number of boolean constants for fragment programs: 0
 * Geometry programs: no
 * Number of floating-point constants for geometry programs: 0
 * Number of integer constants for geometry programs: 0
 * Number of boolean constants for geometry programs: 0
 * Supported Shader Profiles:
 * Texture Compression: yes
   - DXT: no
   - VTC: no
   - PVRTC: yes
 * Scissor Rectangle: yes
 * Hardware Occlusion Query: no
 * User clip planes: yes
 * VET_UBYTE4 vertex element type: yes
 * Infinite far plane projection: yes
 * Hardware render-to-texture: yes
 * Floating point textures: no
 * Non-power-of-two textures: no
 * Volume textures: no
 * Multiple Render Targets: 1
   - With different bit depths: no
 * Point Sprites: yes
 * Extended point parameters: yes
 * Max Point Size: 511
 * Vertex texture fetch: no
 * Number of world matrices: 0
 * Number of texture units: 8
 * Stencil buffer depth: 0
 * Number of vertex blend matrices: 0
 * Render to Vertex Buffer : no
 * GL 1.5 without VBO workaround: no
 * Frame Buffer objects: yes
 * Frame Buffer objects (ARB extension): no
 * Frame Buffer objects (ATI extension): no
 * PBuffer support: no
 * GL 1.5 without HW-occlusion workaround: no
Registering ResourceManager for type Texture
DefaultWorkQueue('Root') initialising on thread 0x839290.
DefaultWorkQueue('Root')::WorkerFunc - thread 0x83f2a0 starting.
Particle Renderer Type 'billboard' registered
****** BundlePath /var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app
Creating resource group Bootstrap
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./OgreCore.zip' of type 'Zip' to resource group 'Bootstrap'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/.' of type 'FileSystem' to resource group 'General'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./media' of type 'FileSystem' to resource group 'General'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./media/materials' of type 'FileSystem' to resource group 'General'
Added resource location '/var/mobile/Applications/7C15F3BA-EE0B-435D-9638-8EB576A206FB/Ogre.app/./media/models' of type 'FileSystem' to resource group 'General'
Parsing scripts for resource group Autodetect
Finished parsing scripts for resource group Autodetect
Parsing scripts for resource group Bootstrap
Parsing script OgreCore.material
Parsing script OgreProfiler.material
Parsing script Ogre.fontdef
Parsing script OgreDebugPanel.overlay
Texture: New_Ogre_Border_Center.png: Loading 1 faces(PF_A8B8G8R8,256x128x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x128x1.
Texture: New_Ogre_Border.png: Loading 1 faces(PF_A8B8G8R8,256x256x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x256x1.
Texture: New_Ogre_Border_Break.png: Loading 1 faces(PF_A8B8G8R8,32x32x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,32x32x1.
Texture: ogretext.png: Loading 1 faces(PF_A8B8G8R8,256x128x1) with 5 hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,256x128x1.
Parsing script OgreLoadingPanel.overlay
Finished parsing scripts for resource group Bootstrap
Parsing scripts for resource group General
Parsing script Ogre.material
Parsing script barco.material
Finished parsing scripts for resource group General
Parsing scripts for resource group Internal
Finished parsing scripts for resource group Internal
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: Problems with copyContentsToMemory and device orientatio

Post by Brocan »

No ideas?

Regarding to the white screens, i asked to a friend that uses OpenGLES as is, and suffers the same problem. So... it can be something related to OGLES. OpenGLES2 can be used on iPhone? the ogre official sdk doesn't provide this render system.

Thanks in advance!
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Problems with copyContentsToMemory and device orientatio

Post by masterfalcon »

To be honest, this is the first I've heard of anyone using copyContentsToMemory on iOS. It probably doesn't work so I'll have to take a look at it. Thanks for the code BTW, that will be very helpful.

As far as GL ES 2 goes, it is not supported in Ogre 1.7. The unstable 1.8 branch does include the render system. It's actually in pretty good shape but any additional testing would be fantastic.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: Problems with copyContentsToMemory and device orientatio

Post by Brocan »

masterfalcon wrote:To be honest, this is the first I've heard of anyone using copyContentsToMemory on iOS. It probably doesn't work so I'll have to take a look at it. Thanks for the code BTW, that will be very helpful.
I need to make screenshots to store it in the gallery, and i think that this is the best solution to create a UIImage :D . If you need more code, ask for it!

I think that the white screen is an OglES problem (maybe glReadPixels needs to have a glFlush before or something that can be done from Ogre), but the orientation issues should be an ogre problem.
Last edited by Brocan on Sat Oct 20, 2012 2:29 pm, edited 1 time in total.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: Problems with copyContentsToMemory and device orientatio

Post by Brocan »

I've builded ogre from trunk successfully and loaded the OGLES2 render system. But now the app launchs a singleton assertion about control manager :| (i think that it happens when renderOneFrame is called) . After creating myself the Ogre::ControlManager, i've success in launching, but then in ogreroot->renderOneFrame i got a EXC_BAD_ACCESS and the app crashes.

Unfortunately i couldn't test the sample browser for checking if the ogre build runs well. I will try it again this friday.

Cheers!
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Problems with copyContentsToMemory and device orientatio

Post by masterfalcon »

Been working on getting copyContentsToMemory to work right the last couple days. Probably just for 1.8 though since it's not an often used feature on iOS and the windowing changes in 1.8 mean that the implementations will be significantly different. In the meantime though there are some UIImage and CoreGraphics API's to take screen grabs and get the raw data that should do the trick for you. I'd check out Apple's docs, I think they have some tech notes to illustrate their usage as well.
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10

Re: Problems with copyContentsToMemory and device orientatio

Post by DanielSefton »

Here's my non-copyContentsToMemory solution. The only thing is the quality isn't as good as if you take a raw screenshot, not sure why. Hope it helps. :)

Code: Select all

-(void)takeScreenshot
{
	GLint backingWidth = 320;
	GLint backingHeight = 480;
	
	//if iphone 4
	{
		backingWidth = 640;
		backingHeight = 960;
	}
	
	NSInteger myDataLength = backingWidth * backingHeight * 4;

	// allocate array and read pixels into it.
	GLuint* buffer = (GLuint *) malloc(myDataLength);
	glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

	// gl renders “upside down” so swap top to bottom into new array.
	for (int y = 0; y < backingHeight / 2; ++y)
	{
		for (int x = 0; x < backingWidth; ++x)
		{
			//Swap top and bottom bytes
			GLuint top = buffer[y * backingWidth + x];
			GLuint bottom = buffer[(backingHeight - 1 - y) * backingWidth + x];
			buffer[(backingHeight - 1 - y) * backingWidth + x] = top;
			buffer[y * backingWidth + x] = bottom;
		}
	}

	// make data provider with data.
	CGDataProviderRef provider = CGDataProviderCreateWithData(
		NULL, buffer, myDataLength, releaseScreenshotData);

	// prep the ingredients
	const int bitsPerComponent = 8;
	const int bitsPerPixel = 4 * bitsPerComponent;
	const int bytesPerRow = 4 * backingWidth;
	CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
	CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
	CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

	// make the cgimage
	CGImageRef imageRef = CGImageCreate((int)backingWidth, (int)backingHeight, bitsPerComponent, 
		bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, 
			NULL, NO, renderingIntent);
	CGColorSpaceRelease(colorSpaceRef);
	CGDataProviderRelease(provider);

	// then make the UIImage from that
	UIImage* myImage = [UIImage imageWithCGImage:imageRef];
	CGImageRelease(imageRef);

	UIImageWriteToSavedPhotosAlbum([self scaleAndRotateImage:myImage], nil, nil, nil);
}

// Code from: http://discussions.apple.com/thread.jspa?messageID=7949889
- (UIImage*)scaleAndRotateImage:(UIImage*)image
{
	int kMaxResolution = 960;

	CGImageRef imgRef = image.CGImage;

	CGFloat width = CGImageGetWidth(imgRef);
	CGFloat height = CGImageGetHeight(imgRef);

	CGAffineTransform transform = CGAffineTransformIdentity;
	CGRect bounds = CGRectMake(0, 0, width, height);
	if (width > kMaxResolution || height > kMaxResolution) {
		CGFloat ratio = width/height;
		if (ratio > 1) {
			bounds.size.width = kMaxResolution;
			bounds.size.height = roundf(bounds.size.width / ratio);
		}
		else {
			bounds.size.height = kMaxResolution;
			bounds.size.width = roundf(bounds.size.height * ratio);
		}
	}

	CGFloat scaleRatio = bounds.size.width / width;
	CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
	CGFloat boundHeight;

	boundHeight = bounds.size.height;
	bounds.size.height = bounds.size.width;
	bounds.size.width = boundHeight;
	transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width/2.0);
	transform = CGAffineTransformRotate(transform, M_PI / 2.0);

	UIGraphicsBeginImageContext(bounds.size);

	CGContextRef context = UIGraphicsGetCurrentContext();

	UIImageOrientation orient = image.imageOrientation;

	if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
		CGContextScaleCTM(context, -scaleRatio, scaleRatio);
		CGContextTranslateCTM(context, -height, 0);
	}
	else {
		CGContextScaleCTM(context, scaleRatio, -scaleRatio);
		CGContextTranslateCTM(context, 0, -height);
	}

	CGContextConcatCTM(context, transform);

	CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
	UIImage* imageCopy = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();

	return imageCopy;
}
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: Problems with copyContentsToMemory and device orientatio

Post by Brocan »

DanielSefton wrote:Here's my non-copyContentsToMemory solution. The only thing is the quality isn't as good as if you take a raw screenshot, not sure why. Hope it helps. :)

Code: Select all

-(void)takeScreenshot
{
	GLint backingWidth = 320;
	GLint backingHeight = 480;
	
	//if iphone 4
	{
		backingWidth = 640;
		backingHeight = 960;
	}
	
	NSInteger myDataLength = backingWidth * backingHeight * 4;

	// allocate array and read pixels into it.
	GLuint* buffer = (GLuint *) malloc(myDataLength);
	glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

	// gl renders “upside down” so swap top to bottom into new array.
	for (int y = 0; y < backingHeight / 2; ++y)
	{
		for (int x = 0; x < backingWidth; ++x)
		{
			//Swap top and bottom bytes
			GLuint top = buffer[y * backingWidth + x];
			GLuint bottom = buffer[(backingHeight - 1 - y) * backingWidth + x];
			buffer[(backingHeight - 1 - y) * backingWidth + x] = top;
			buffer[y * backingWidth + x] = bottom;
		}
	}

	// make data provider with data.
	CGDataProviderRef provider = CGDataProviderCreateWithData(
		NULL, buffer, myDataLength, releaseScreenshotData);

	// prep the ingredients
	const int bitsPerComponent = 8;
	const int bitsPerPixel = 4 * bitsPerComponent;
	const int bytesPerRow = 4 * backingWidth;
	CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
	CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
	CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

	// make the cgimage
	CGImageRef imageRef = CGImageCreate((int)backingWidth, (int)backingHeight, bitsPerComponent, 
		bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, 
			NULL, NO, renderingIntent);
	CGColorSpaceRelease(colorSpaceRef);
	CGDataProviderRelease(provider);

	// then make the UIImage from that
	UIImage* myImage = [UIImage imageWithCGImage:imageRef];
	CGImageRelease(imageRef);

	UIImageWriteToSavedPhotosAlbum([self scaleAndRotateImage:myImage], nil, nil, nil);
}

// Code from: http://discussions.apple.com/thread.jspa?messageID=7949889
- (UIImage*)scaleAndRotateImage:(UIImage*)image
{
	int kMaxResolution = 960;

	CGImageRef imgRef = image.CGImage;

	CGFloat width = CGImageGetWidth(imgRef);
	CGFloat height = CGImageGetHeight(imgRef);

	CGAffineTransform transform = CGAffineTransformIdentity;
	CGRect bounds = CGRectMake(0, 0, width, height);
	if (width > kMaxResolution || height > kMaxResolution) {
		CGFloat ratio = width/height;
		if (ratio > 1) {
			bounds.size.width = kMaxResolution;
			bounds.size.height = roundf(bounds.size.width / ratio);
		}
		else {
			bounds.size.height = kMaxResolution;
			bounds.size.width = roundf(bounds.size.height * ratio);
		}
	}

	CGFloat scaleRatio = bounds.size.width / width;
	CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
	CGFloat boundHeight;

	boundHeight = bounds.size.height;
	bounds.size.height = bounds.size.width;
	bounds.size.width = boundHeight;
	transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width/2.0);
	transform = CGAffineTransformRotate(transform, M_PI / 2.0);

	UIGraphicsBeginImageContext(bounds.size);

	CGContextRef context = UIGraphicsGetCurrentContext();

	UIImageOrientation orient = image.imageOrientation;

	if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
		CGContextScaleCTM(context, -scaleRatio, scaleRatio);
		CGContextTranslateCTM(context, -height, 0);
	}
	else {
		CGContextScaleCTM(context, scaleRatio, -scaleRatio);
		CGContextTranslateCTM(context, 0, -height);
	}

	CGContextConcatCTM(context, transform);

	CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
	UIImage* imageCopy = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();

	return imageCopy;
}
Thanks Daniel! so, do you call gl directly altought you are using ogre?
masterfalcon wrote:Been working on getting copyContentsToMemory to work right the last couple days. Probably just for 1.8 though since it's not an often used feature on iOS and the windowing changes in 1.8 mean that the implementations will be significantly different. In the meantime though there are some UIImage and CoreGraphics API's to take screen grabs and get the raw data that should do the trick for you. I'd check out Apple's docs, I think they have some tech notes to illustrate their usage as well.
Thanks for looking for the problem! I'll check this docs, but the problem is that my app has a child view with buttons over the ogre view, and i only want to make the screenshot of the ogre view, not the buttons view.

On other hand, i've looking for the best way to make my hierarchy of views. I want to have a navigation controller as init, and when i push a button in the navigation controller, push the ogre view controller to show the ogre view. What do you think that is the best way? i should pass the app window as external window to ogre? after that i need to make the navigation controller root controller again because ogre steals my window :lol: . Or maybe i should let ogre to create their own window and use it to attach the navigation controller? Or maybe let ogre to create their own window and ignore it?

If the ogre view is attached to a window if I can attach successfully the view to a other window or view with addsubview? (maybe can be a problem with the handles and get the ogre view white?, this happens to me in 1.7.3 :( )

The mac learning is being difficult for me :lol:

Thanks in advance!!
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Problems with copyContentsToMemory and device orientatio

Post by masterfalcon »

Well, sadly the code in 1.7 isn't well suited to use with view controllers. I rewrote it for 1.8 and it should play much nicer now.