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.
private void useShader(GL gli) {
int v = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);
int t = 6;//Total Number of lines in shader
String fsrc[] = new String[t];
int lengths[] = new int[t];
//Shader Source Code to set a texture to 1/4 it's opacity.
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] = "}";
//Load variables with shader code information
String tmp;
for(int i = 0; i < t;i++){
tmp = fsrc[i];
lengths[i] = tmp.length();
}
//Apply Shader Source
gli.glShaderSource(v, t, fsrc, lengths, (int)0);
gli.glCompileShader(v);//Compile
int shaderprogram = gl.glCreateProgram();//Create prog
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.