get EAGLview screenshot with transparency in landscape mode

this is NOT mine actually. the original source can be found at the end of this post. i post here just for helping people who may need it. so they don’t need to spend whole day for “googling” this like i did. 😀

the key to get the transparency is this line:

[code language=”cpp”]
CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast;

now, this is the complete method. NOTE: this is for landscape mode (480 x 320), if you want in portrait, simply modify the size.

[code language=”cpp” wraplines=”false”]
– (UIImage*) getGLScreenshot {
NSInteger myDataLength = 480 * 320 * 4;

// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, 480, 320, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

// gl renders "upside down" so swap top to bottom into new array.
// there’s gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y <320; y++)
for(int x = 0; x < 480* 4; x++)
buffer2[(319 – y) * 480 * 4 + x] = buffer[y * 4 * 480 + x];

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

// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 480;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

/***************** to handle the transparency/alpha ******************/
CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast;
//CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;

CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

// make the cgimage
CGImageRef imageRef = CGImageCreate(480, 320, bitsPerComponent,
bitsPerPixel, bytesPerRow, colorSpaceRef,
bitmapInfo, provider, NULL, NO, renderingIntent);

// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
return myImage;



shiva3d causes memory leaks on iphone

if you are working with shiva3d game engine on iphone, you may notice two memory leaks once you convert the runtime package (.stk file) to xcode project using shiva authoring tools.

the memory leaks are
1. related to AudioToolbox framework
2. related to NSString

for the first one, i have no idea how to resolve it, since it was related to one of ios frameworks, and even google didn’t know :D.

and for the second, it seems the authoring tools forgot to release a dynamic NSString variable. see the image below. red rectangle is the suspect variable that you could find in initWithCoder method of S3DEngine_EAGLView class (blue rectangles). to resolve this, simply release the variable as shown in green rectangle.

click for bigger image

import existing C++ code and its Makefile in Eclipse (Linux)

Cuma catatan doank biar gampang nyari kalo bsok lupa.. 😀 kbetulan lagi pengen nyobain ngutak-ngatik source code punya orang.. kbetulan jg lagi pengen ngrasain make Eclipse di Linux..

1. Create a new project, File > New > C++ Project.

2. C++ Project window will appear.

a. Give the project name same as the existing C++ code’s folder.

b. in Project Type column, select Makefile project > Empty project.

c. select the compiler type in the Toolchain column.

d. click Next and then Read More …