PDA

View Full Version : best way to store, blit, and render pixel data



ishkabible
01-09-2011, 06:59 PM
ok so i finely got glew working so i have access to all these new(well new to me) features like FBO's PBO's and other stuff. i want to make a class in witch i can blit small images to a larger image and display that on the screen. i want to be able to have the class blit 1 things to another and then later have another class render this image quickly. how might i do that?

ishkabible
01-09-2011, 07:51 PM
ok i think frame buffers will actually work well here, i didn't realize you could blit them like that. alright i have it working so that i can blit images to the screen but i can't get the alpha Chanel to blit.

ZbuffeR
01-10-2011, 02:50 AM
Are you sure both source FBO and on screen framebuffer have alpha channel ?

ishkabible
01-10-2011, 10:22 AM
no, i know the on screen one dose but i don't know about the source frame buffer.

here is how i set it up


glGenFramebuffers(1,&fbo);
glBindFramebuffer(GL_FRAMEBUFFER,fbo);
glGenRenderbuffers(1,&rbo);
glBindRenderbuffer(GL_RENDERBUFFER,rbo); glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA,zomb ie->getWidth(),zombie->getHeight());
glBindRenderbuffer(GL_RENDERBUFFER,0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ ATTACHMENT0,GL_RENDERBUFFER, rbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, zombie->tex, 0);
glBindFramebuffer(GL_FRAMEBUFFER,0);


and here is how i blit it to the screen



glBindFramebuffer(GL_READ_FRAMEBUFFER,fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
glBlitFramebuffer(0,0,zombie->getWidth(),zombie->getHeight(),0,0,+zombie->getHeight(),zombie->getHeight(),GL_COLOR_BUFFER_BIT,GL_LINEAR);


edit: fbo is the frame buffer object and rbo is the render buffer object in case that wasn't clear.
also i think the ortho is set up differently becuase when i blit it to (0,0) it blits it to (0,800) with the width going the wrong way. ill post a picture of what i mean if want

ishkabible
01-10-2011, 02:34 PM
how do i check if my frame buffer supports an alpha channel?

ZbuffeR
01-10-2011, 03:13 PM
When frame buffer is bound, you can glDrawPixels on it with specific alpha values, then glReadPixels that to check alpha values are the same.

Do not forget to disable depth test, blending, stencil test etc.

ishkabible
01-10-2011, 09:34 PM
ok so i used the following to try and display the data, did i do something wrong because it's not showing up anywhere?



glBindFramebuffer(GL_READ_FRAMEBUFFER,fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
unsigned int* data = new unsigned int[(zombie->getWidth()+1)*(zombie->getHeight()+1)];
glReadPixels(0,0,zombie->getWidth(),zombie->getHeight(),GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,data);
glDrawPixels(zombie->getWidth(),zombie->getHeight(),GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,data);
delete [] data;