BOOL BeginTarget(image_p _img,uint8_t clear){
static int cacheid = 0;
if(!_img)
return FALSE;
BIND_AND_TEST_CACHE(_img);
target_w = _img->w;
target_h = _img->h;
//reset to target_clip
target_clip = 1;
ResetClip();
glBlendEquationSeparate(GL_FUNC_ADD, GL_MAX);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, cacheid, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,_img->w,0,_img->h, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,_img->w, _img->h);
if(clear){
glClearColor( COLOR_T_R(screen_c), COLOR_T_G(screen_c), COLOR_T_B(screen_c), COLOR_T_A(screen_c) );
glClear( GL_COLOR_BUFFER_BIT);
}
return TRUE;
}
void EndTarget(){
glViewport(0,0, nge_screen.width, nge_screen.height);
glPopAttrib();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,nge_screen.ori_width,nge_screen.ori_height,0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glBlendEquation(GL_FUNC_ADD);
//reset to screen clip
target_clip = 0;
ResetClip();
}
BOOL BeginTarget(image_p _img,uint8_t clear){
static int cacheid = 0;
if(!_img)
return FALSE;
BIND_AND_TEST_CACHE(_img);
target_w = _img->w;
target_h = _img->h;
//reset to target_clip
target_clip = 1;
ResetClip();
glBlendEquationSeparate(GL_FUNC_ADD, GL_MAX);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, cacheid, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,_img->w,0,_img->h, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,_img->w, _img->h);
if(clear){
glClearColor( COLOR_T_R(screen_c), COLOR_T_G(screen_c), COLOR_T_B(screen_c), COLOR_T_A(screen_c) );
glClear( GL_COLOR_BUFFER_BIT);
}
return TRUE;
}
void EndTarget(){
glViewport(0,0, nge_screen.width, nge_screen.height);
glPopAttrib();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,nge_screen.ori_width,nge_screen.ori_height,0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glBlendEquation(GL_FUNC_ADD);
//reset to screen clip
target_clip = 0;
ResetClip();
}