Pretty much I have realized the only way to give my game any decent edge, means I need to explore GLSL. I figured what would be better than to start off with a simple Opacity shader.
I am pretty confused on the basic principles of shaders, so I figured boo ya Orange book!
The Orange book is cool, and it makes sense and all, but it's 600 some pages of reading when I am imagining I am looking at a problem involving possibly 20 lines of code... So I took what I could from it, and read the NeHe GLSL tutorial(not much help imo).
Here's the code I have generated for my shader, in setting a textured object's opacity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| private void useShader(GL gli) { int v = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);
int t = 6; String fsrc[] = new String[t]; int lengths[] = new int[t]; fsrc[0] = "uniform sampler2D BaseImage;"; fsrc[1] = "uniform float Opacity;"; fsrc[2] = "void main (void) {"; fsrc[3] = "vec4 base = texture2D(BaseImage, gl_TexCoord[0].xy);"; fsrc[4] = "gl_FragColor = base * 0.25"; fsrc[5] = "}";
String tmp; for(int i = 0; i < t;i++){ tmp = fsrc[i]; lengths[i] = tmp.length(); } gli.glShaderSource(v, t, fsrc, lengths, (int)0); gli.glCompileShader(v); int shaderprogram = gl.glCreateProgram(); gli.glAttachShader(shaderprogram, v); gli.glLinkProgram(shaderprogram); gli.glValidateProgram(shaderprogram);
gli.glUseProgram(shaderprogram); } |
Obviously it doesn't work otherwise I wouldn't be posting here haha. I think the problem is I am not passing the texture information to the GLSL program? But I guess I am just confused. I know everything compiles and runs as normal, however a tiny bit slower.
Pretty much I just wanna know how far off I am, if I should just sit down pull my hair out and read the orange book, if anyone has found any links to a shader similar to this, or any other interesting basic shader(just to play with), or perhaps a lame-mans terms tutorials.