+ fb = 0; rb = 0;
+// glGenRenderbuffers(1, &rb);
+// glBindRenderbuffer(GL_RENDERBUFFER, rb);
+// glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, get_texture_w(), get_texture_w());
+ glGenFramebuffers(1, &fb);
+ glBindFramebuffer(GL_FRAMEBUFFER, fb);
+// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
+}
+
+fb_texture::~fb_texture()
+{
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glDeleteFramebuffers(1, (GLuint *)&fb);
+// glBindRenderbuffer(GL_RENDERBUFFER, 0);
+// glGenRenderbuffers(1, &rb);
+}
+
+void fb_texture::bind(int texture_unit)
+{
+ glBindFramebuffer(GL_FRAMEBUFFER, fb);
+// glBindRenderbuffer(GL_RENDERBUFFER, rb);
+ BC_Texture::bind(texture_unit);
+}
+
+void fb_texture::read_screen(int x, int y, int w, int h)
+{
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glReadBuffer(GL_BACK);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, x,y, w,h);
+}
+
+void fb_texture::set_output_texture()
+{
+ glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, get_texture_id(), 0);
+ GLenum dbo[1] = { GL_COLOR_ATTACHMENT0, }; // bind layout(location=0) out vec4 color;
+ glDrawBuffers(1, dbo);
+ int ret = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ if( ret != GL_FRAMEBUFFER_COMPLETE ) {
+ printf("glDrawBuffer error 0x%04x\n", ret);
+ return;
+ }
+}
+
+static void combineData(GLdouble coords[3],
+ GLdouble *vertex_data[4], GLfloat weight[4],
+ GLdouble **outData, void *data)
+{
+ ArrayList<double *> *invented = (ArrayList<double *> *)data;
+ GLdouble *vertex = new double[6];
+ invented->append(vertex);
+ vertex[0] = coords[0];
+ vertex[1] = coords[1];
+ vertex[2] = coords[2];
+ for( int i=3; i<6; ++i ) {
+ vertex[i] = weight[0] * vertex_data[0][i] +
+ weight[1] * vertex_data[1][i] +
+ weight[2] * vertex_data[2][i] +
+ weight[3] * vertex_data[3][i];
+ }
+ *outData = vertex;