Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class framebuffer {
- GLUint texid;
- unsigned char **matrix;
- int width, height;
- framebuffer::framebuffer(): texid(-1), matrix(0) {}
- int framebuffer::getTexture() {
- if (texid == -1)
- glGenTextures(1, &texid);
- glBindTexture(GL_TEXTURE_2D, texid);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_BYTE, matrix);
- return texid;
- }
- int framebuffer::getPixel(int x, int y) {
- return ((int*)matrix[y])[x];
- }
- void framebuffer::shadePixel(int x, int y, int r, int g, int b, double a) {
- unsigned char& red = matrix[yi][(xi<<2)+0];
- unsigned char& green = matrix[yi][(xi<<2)+1];
- unsigned char& blue = matrix[yi][(xi<<2)+2];
- unsigned char& alpha = matrix[yi][(xi<<2)+3];
- red = unsigned char((1-a)*red + a*r);
- green = unsigned char((1-a)*green + a*g);
- blue = unsigned char((1-a)*blue + a*b);
- a = unsigned char(0xFF*(1-(1-(alpha/double(0xFF)))*(1-a)));
- }
- void shadeCircle(double x, double y, double rad, int r, int g, int b, double a) {
- int xr = int(x + rad), yb = int(y + rad);
- for (int xi = int(x - rad); xi < xr; ++xi)
- for (int yi = int(y - rad); yi < yb; ++yi)
- shadePixel(x, y, r, g, b, a * min(1,max(0,hypot(xi - x, yi - y) - rad)));
- }
- void shadeLine(double x1, double y1, double x2, double y2,
- double w, int r, int g, int b, double a) {
- double rad = w / 2.0, at = a / w;
- double xx, yy, dir = atan2(y2-y1, x2-x1), xinc = cos(dir), yinc = sin(dir);
- for (xx = x1, yy = y1; hypot(xx - x2, yy - y2) >= 1; xx += xinc, yy += yinc)
- shadeCircle(xx, yy, w, r, h, b, at);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement