+ dbg("fillbitmap");
+ internal_t*i = (internal_t*)dev->internal;
+ char running = 0;
+ int len = 0;
+ double*xyz=0;
+ gfxline_t*l=0;
+ glColor4f(1.0,0,0,1.0);
+
+ GLuint texIDs[1];
+ glGenTextures(1, texIDs);
+
+ int width_bits = 0;
+ int height_bits = 0;
+ while(1<<width_bits < img->width)
+ width_bits++;
+ while(1<<height_bits < img->height)
+ height_bits++;
+ int newwidth = 1<<width_bits;
+ int newheight = 1<<height_bits;
+
+ unsigned char*data = malloc(newwidth*newheight*4);
+ int x,y;
+ for(y=0;y<img->height;y++) {
+ for(x=0;x<img->width;x++) {
+ data[(y*newwidth+x)*4+0] = img->data[y*img->width+x].r;
+ data[(y*newwidth+x)*4+1] = img->data[y*img->width+x].g;
+ data[(y*newwidth+x)*4+2] = img->data[y*img->width+x].b;
+ data[(y*newwidth+x)*4+3] = img->data[y*img->width+x].a;
+ }
+ }
+
+ gfxmatrix_t m2;
+ gfxmatrix_invert(matrix, &m2);
+ m2.m00 /= newwidth;
+ m2.m10 /= newwidth;
+ m2.tx /= newwidth;
+ m2.m01 /= newheight;
+ m2.m11 /= newheight;
+ m2.ty /= newheight;
+
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, texIDs[0]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, newwidth, newheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+ glEnable(GL_TEXTURE_2D);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+
+ gluTessBeginPolygon(i->tesselator_tex, NULL);
+ l = line;
+ len = 0;
+ while(l) {
+ len++;
+ l = l->next;
+ }
+ xyz = malloc(sizeof(double)*5*len);
+ l = line;
+ len = 0;
+ while(l) {
+ if(l->type == gfx_moveTo) {
+ if(running) {
+ running = 0;
+ gluTessEndContour(i->tesselator_tex);
+ }
+ }
+ if(!running) {
+ running = 1;
+ gluTessBeginContour(i->tesselator_tex);
+ }
+
+ xyz[len*5+0] = l->x;
+ xyz[len*5+1] = l->y;
+ xyz[len*5+2] = (i->currentz*ZSTEP);
+ xyz[len*5+3] = 0;
+ xyz[len*5+4] = 0;
+ gfxmatrix_transform(&m2, /*src*/&xyz[len*5+0], /*dest*/&xyz[len*5+3]);
+
+ gluTessVertex(i->tesselator_tex, &xyz[len*5], &xyz[len*5]);
+ len++;
+
+ l=l->next;
+ }
+
+ if(running) {
+ running = 0;
+ gluTessEndContour(i->tesselator_tex);
+ }
+ gluTessEndPolygon(i->tesselator_tex);
+ i->currentz ++;
+ free(xyz);
+
+ glDisable(GL_TEXTURE_2D);