kidult
Junior Member
Offline
Posts: 84
Re: changing a textures alpha
Reply #6 - Apr 9th , 2006, 8:33pm
in my program though i use copy... to copy certain parts of the image and save into an new PImage object the tranparency stops working. i tried changing the format parameter of both images but i didnt see any noticeable changes. also because of more complex manipulations in the large program i cannot use the mask function to mask the area i do not want to be visible. import processing.opengl.*; PImage a,b; PImage[] as,bs; int[][] xs, ys; int polygon_group_width, polygon_group_height, polygon_size, polygon_count; void setup(){ a = loadImage("CRUNK.gif"); b = loadImage("CRUNKtest.gif"); //a.format = ALPHA; //b.format = ALPHA; size(a.width+200,a.height+200,OPENGL); polygon_size = 45; polygon_group_width = ceil(a.width/polygon_size)+2; polygon_group_height = ceil(a.height/polygon_size)+2; polygon_count = (polygon_group_width) * ( polygon_group_height); xs = new int[polygon_group_width][polygon_group_height]; ys = new int[polygon_group_width][polygon_group_height]; for(int y = 0; y < polygon_group_height; y++) { for(int x = 0; x < polygon_group_width; x++) { xs[x][y] = x*polygon_size; ys[x][y] = y*polygon_size; } } as = new PImage[polygon_count]; bs = new PImage[polygon_count]; splitImage(); noStroke(); } void draw(){ background(255); renderSplitImage(); } void renderSplitImage() { pushMatrix(); translate((width/2-a.width/2),(height/2-a.height/2)); for(int y = 0; y < (polygon_group_height-1); y++) { for(int x = 0; x < (polygon_group_width-1); x++) { beginShape(QUADS); fill(255, 255, 255, 255); texture(as[x + y*polygon_group_width]); vertex(xs[x][y], ys[x][y],0,0); vertex(xs[x+1][y], ys[x+1][y],polygon_size,0); vertex(xs[x+1][y+1], ys[x+1][y+1],polygon_size,polygon_size); vertex(xs[x][y+1], ys[x][y+1],0,polygon_size); endShape(); } } popMatrix(); pushMatrix(); translate((width/2-b.width/2)+10,height/2-b.height/2); for(int y = 0; y < (polygon_group_height-1); y++) { for(int x = 0; x < (polygon_group_width-1); x++) { beginShape(QUADS); fill(255, 255, 255, 100); texture(bs[x + y*polygon_group_width]); vertex(xs[x][y], ys[x][y],0,0); vertex(xs[x+1][y], ys[x+1][y],polygon_size,0); vertex(xs[x+1][y+1], ys[x+1][y+1],polygon_size,polygon_size); vertex(xs[x][y+1], ys[x][y+1],0,polygon_size); endShape(); } } popMatrix(); } void splitImage() { int count = 0; for(int y = 0; y < polygon_group_height; y++) { for(int x = 0; x < polygon_group_width; x++) { as[count] = new PImage(polygon_size,polygon_size); //as[count] = copyImage(a, x*polygon_size,y*polygon_size, (x*polygon_size)+polygon_size, (y*polygon_size)+polygon_size, polygon_size, polygon_size); as[count].copy(a, x*polygon_size,y*polygon_size, polygon_size, polygon_size, 0, 0, polygon_size, polygon_size); bs[count] = new PImage(polygon_size,polygon_size); //bs[count] = copyImage(b, x*polygon_size,y*polygon_size, (x*polygon_size)+polygon_size, (y*polygon_size)+polygon_size, polygon_size, polygon_size); bs[count].copy(b, x*polygon_size,y*polygon_size, polygon_size, polygon_size, 0, 0, polygon_size, polygon_size); count++; } } } PImage copyImage(PImage c,int x1, int y1, int x2, int y2, int w, int h) { PImage d = new PImage(w,h); int count = 0; loadPixels(); for (int y = y1; y <y2; y++) { for (int x = x1; x < x2; x++) { d.pixels[count] = c.pixels[y*width+x]; count++; } } updatePixels(); return d; } http://newmedia.rit.edu/allclasses/ve_2005/students/bryanijeoma/CRUNK.gif http://newmedia.rit.edu/allclasses/ve_2005/students/bryanijeoma/CRUNKtest.gif http://newmedia.rit.edu/allclasses/ve_2005/students/bryanijeoma/transparencytest2.jpg