Held_OT
YaBB Newbies
Offline
Posts: 7
PGraphicsOffscreenGL + Alpha-Mask?
Jan 17th , 2008, 8:11am
Hello again... When I found the PGraphicsOffscreenGL-code I was quite glad because as it seems it solves my overlapping-problem pretty fast. And I thought, as I already have a shader-program here I can just as well add the soft-edge-blending here by using a alpha-mask from a file. I've been trying here for a while, but just can't seem to find a working solution. I'm not really sure what the problem is, but I guess I either mess up the creating of the texture... (In this case I did not even read the data from a file but just used a simple test-pattern "g2") --------------------------------------------------------- int b_size = my_width*my_height; g2 = new int[b_size*4];// = pg.getDrawTex(); for( int i = 0; i<g2.length;i++) { g2[i]=i%255; } gl.glActiveTexture(GL.GL_TEXTURE1); gl.glEnable( GL.GL_TEXTURE_2D ); IntBuffer pixBuffer=IntBuffer.wrap(g2); pixBuffer.rewind(); alph = new int[1]; gl.glGenTextures(1, alph,0); gl.glBindTexture(GL.GL_TEXTURE_2D, alph[0]); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP); gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, my_width,my_height, 0, GL.GL_BGRA,GL.GL_UNSIGNED_BYTE, pixBuffer); ------------------------------------------------------------ or I have some trouble with the binding of the textures: ------------------------------------------------------------ gl.glActiveTexture(GL.GL_TEXTURE0); gl.glEnable(GL.GL_TEXTURE_2D); gl.glBindTexture(GL.GL_TEXTURE_2D, pg.getDrawTex()); gl.glActiveTexture(GL.GL_TEXTURE1); gl.glEnable(GL.GL_TEXTURE_2D); gl.glBindTexture(GL.GL_TEXTURE_2D, alph[0]); gl.glColor4f(1.0, 1.0, 1.0, 1.0); gl.glBegin(GL.GL_QUADS); gl.glMultiTexCoord2f(GL.GL_TEXTURE0,0.0, 0.0); gl.glMultiTexCoord2f(GL.GL_TEXTURE1,0.0, 0.0); gl.glVertex2f(0.0, 0.0); gl.glMultiTexCoord2f(GL.GL_TEXTURE0,1.0, 0.0); gl.glMultiTexCoord2f(GL.GL_TEXTURE1,1.0, 0.0); gl.glVertex2f(width, 0.0); gl.glMultiTexCoord2f(GL.GL_TEXTURE0,1.0, 1.0); gl.glMultiTexCoord2f(GL.GL_TEXTURE1,1.0, 1.0); gl.glVertex2f(width, height); gl.glMultiTexCoord2f(GL.GL_TEXTURE0,0.0, 1.0); gl.glMultiTexCoord2f(GL.GL_TEXTURE1,0.0, 1.0); gl.glVertex2f(0.0, height); gl.glEnd(); ----------------------------------------------------------- Or might it be that multi-texturing is not going to work anyway with this PGraphicsOffscreenGL-Objects in use? The fragment-shader I'm using is: ----------------------- uniform sampler2D tex_rgb, tex_a; void main() { vec4 c = texture2D(tex_rgb, gl_TexCoord[0].st); vec4 c2 = texture2D(tex_a, gl_TexCoord[1].st); gl_FragColor = vec4(c.rgb,c2.a); } ----------------------- Has anybody some idea why this might not work? Some time ago (although I fear I do not remember what changes I made since then) I had the result that the alpha did come from the given array - but as far as I could see the value was not position-dependend as in a working alpha-mask, but it was constant... so it looks like the program took one value out of the array and used it over the entire Quad... Does anybody have any experiences in this regard that might help me or has any idea where I could look for help? Thanks in advance, Sven