We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 2 
Shaderlib (Read 9519 times)
Re: Shaderlib
Reply #15 - Jul 15th, 2009, 2:10am
 
tane,

thanks for testing it out for me, now i know it works on macs =)

1. the error in the GLSL example. it seems weird to me. it fails in compiling the vertex shader for the error you showed to me. maybe you can try something.

in the "simplevertex.glsl" change the line

  gl_Position = ftransform();
to:
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

ftransform will or is dead already, so that might fix it. if it does i still find it weird since it works here. anyway i can't be sure of anything when talking about macs.

2. as for your program, the way you create the opengl textures is wrong. you shouldn't create a new texture for every frame, you should be updating the texture instead.

i send you your example here now working. it uses JMyron instead since i don't have VDIG installed, but its easy for you to get back to processing Capture =)


www.pixelnerve.com/temp/test0.zip


now,
what did i do/change

in setup, first you need to create a new opengl texture:

Code:
  
tex = new VTexture();
tex.createGL( 320, 240 );  // dimensions



in mainloop get data from camera and update the texture:

Code:

m.update();  // get image from jmyron
int[] imgtmp = m.image(); // just saving an array
tex.update( imgtmp ); // update texture with new data




this is the new method i added to the Texture class. it already had an update() method which worked with an internal array. this just lets you pass the array you want.

Code:
// Update a texture with give data. The dimensions of the pixels should be the same from the texture
 void update( int[] pixels )
 {
   _gl.glBindTexture( GL.GL_TEXTURE_2D, _id );
   _gl.glPixelStorei( GL.GL_UNPACK_ALIGNMENT, 1 );
   _gl.glTexSubImage2D( GL.GL_TEXTURE_2D, 0, 0, 0, _width, _height, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(pixels) );
   _gl.glBindTexture( GL.GL_TEXTURE_2D, 0 );
 }


have fun.

Re: Shaderlib
Reply #16 - Jul 15th, 2009, 12:53pm
 
V wrote on Jul 15th, 2009, 2:10am:
tane,

thanks for testing it out for me, now i know it works on macs =)


Thanks for your fast follow up, V!  I tried test0 (it worked fine),  subsequently made my own version using the Capture lib (summarized below) and it works fine too!

V wrote on Jul 15th, 2009, 2:10am:
1. the error in the GLSL example. it seems weird to me. it fails in compiling the vertex shader for the error you showed to me. maybe you can try something.

in the "simplevertex.glsl" change the line
  gl_Position = ftransform();
to:
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

ftransform will or is dead already, so that might fix it. if it does i still find it weird since it works here. anyway i can't be sure of anything when talking about macs.


Just tried what you suggested  and got essentially the same error unfortunately. FWIW, i run it on my MacBook Pro 3.1 with a GeForce 8600M GT. When using Andres Colubri's glgraphics libs to chain a few GLSL shaders, i intermittently (aka once in a while and not in a deterministic manner) get an "Invalid memory access of location" so i'm starting to wonder whether this couldn't be due to a bug in the mac driver for my video card instead of a problem with either of the libs (glgraphics or shaderlib).

For the time being, i will probably try to mix and match glgraphics for GLSL shaders and use shaderlib for Cg shaders.

V wrote on Jul 15th, 2009, 2:10am:
2. as for your program, the way you create the opengl textures is wrong. you shouldn't create a new texture for every frame, you should be updating the texture instead.

i send you your example here now working. it uses JMyron instead since i don't have VDIG installed, but its easy for you to get back to processing Capture =)


Indeed! :) Here are the main changes for people who would stumble upon this thread:

in setup, first you need to create a new opengl texture:

Code:
  
 tex = new VTexture();
 tex.createGL( width, height );


and in draw():

Quote:
    if (video.available()) {
      video.read();
      video.loadPixels();
      tex.update(video.pixels);


along with the new method you provided.

Thanks again for your help and for the lib itsef. Gonna get my video card busy testing Cg shaders and then i'll try to combine the GLSL and Cg ones!

Pierre
Re: Shaderlib
Reply #17 - Feb 13th, 2010, 8:06pm
 
I just figured out what was wrong with GLSL on Mac!

In the checkStatus method of ShaderGLSL.java you just need to check that length > 0 before calling:
_gl.glGetInfoLogARB( obj, length, iVal, infoLog );

Just wrap the end of that method in if(length>0) and everything seems to work great on mac.
Re: Shaderlib
Reply #18 - Feb 24th, 2010, 11:50pm
 
ahh nice. thanks for reporting that back.
Pages: 1 2