PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Blitting to displaybuffer?

Hi,
I read on 30daygame the following text:

"Edgelib does allow blitting to and from the display buffer which makes things a lot easier - if we are to do any sequel games it’s essential the engine is as perfect as it can be to avoid major issues later on."

This is something I've been looking for, could you provide more info, ie what functions I should look into, or is there a sample that does this?

Also what speeds could I expect on a 2G doing a full screen blit? (I know about dirty rectangles, but full screen is a good indicator for me)

Thanks,
Kaj
Hi,

You can lock and blit to/from the backbuffer, but not using OpenGL ES isn't recommended (OpenGL ES is faster). Your FPS count will probably be in the 25-30fps range.

If you do use OpenGL ES, your game will be able to run at 60fps. If you want to capture certain parts you've already rendered in OpenGL ES, we recommend using render-to-texture.

An example on how to create and release a renderbuffer:
Code:

//Create framebuffer and renderbuffer
GLuint fbo, renderbuffer;
unsigned long width = 64, height = 64;
glGenFramebuffersOES(1, &fbo;);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);
glGenRenderbuffersOES(1, &renderbuffer;);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, renderbuffer);

//Restore rendering
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 1);


//Cleanup
glDeleteRenderbuffersOES(1, &renderbuffer;);
glDeleteFramebuffersOES(1, &fbo;);


And an example on how to create a rendertexture, linked to the renderbuffer:
Code:

unsigned int texid = 0;
GLenum glformat = GL_RGB, gltype = GL_UNSIGNED_BYTE;
glGenTextures(1, &texid;);
if (texid > 0)
{
unsigned long width = 64, height = 64;
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);
glBindTexture(GL_TEXTURE_2D, texid);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, glformat, width, height, 0, glformat, gltype, NULL);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texid, 0);
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 1);
if (status != GL_FRAMEBUFFER_COMPLETE_OES)
glDeleteTextures(1, &texid;);
}
return(texid);


And finally how to set/clear this texture as a rendertexture:
Code:

//Set render texture
unsigned long rendertexwidth = 64, rendertexheight = 64;
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);
glViewport(0, 0, rendertexwidth, rendertexheight);

//Clear render texture
unsigned long displaywidth = 320, displayheight = 480;
glViewport(0, 0, displaywidth, displayheight);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 1);
Hi, would it be possible to use an E2DSurface uploaded to OpenGL in the below example? For example would it be possible to retrieve the texture ID of an uploaded E2DSurface and supply it to the fbo?
Hi,

You can't access the surface texture ID directly, however you could bind it manually and retrieve the texture ID from OpenGL using glGetIntegerv and GL_TEXTURE_BINDING_2D.

I'm not sure if it works the way you expect though.