I still haven’t found any jogl shader resources, but I have been trying my best to work through the examples in C which is a little slow having never learned C. I seem to be in the same spot that I was when I last posted (I can’t figure out how to get the shader to interface with my jogl program).
Here is what I have in my attempt to color an otherwise red quad blue via a fragment shader:
I have made a class that implements GLEventListener and inside the init(GLAutoDrawable) method I have this among other things:
//SHADER CREATION
int shaderProgram = gl.glCreateProgram(); //this int is available to all methods in the class
int fragShader = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);
try
{
BufferedReader fragShaderReader = new BufferedReader(new FileReader("fragShader.glsl"));
String fragShaderSource = "", tempFragSCR;
while((tempFragSCR = fragShaderReader.readLine()) != null)
{
fragShaderSource += tempFragSCR + "\n";
}
String[] fragSourceArray = {fragShaderSource};
int[] strLength = {fragShaderSource.length()};
gl.glShaderSource(fragShader,1,fragSourceArray,strLength,0);
}catch(Exception e){System.out.println(e);}
gl.glCompileShader(fragShader);
gl.glAttachShader(shaderProgram,fragShader);
gl.glLinkProgram(shaderProgram);
I am not certain if I am doing the glShaderSource method correctly.
In my display(GLAutoDrawable) method, I have these lines which successfully draws a red quad in the center of my canvas. I figured that the line “gl.glUseProgram(shaderProgram);” would apply the fragment shader and make all the pixels blue, but it seems to have no effect:
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glUseProgram(shaderProgram);
gl.glPushMatrix();
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(10.0f,10.0f,0.0f);
gl.glVertex3f(-10.0f,10.0f,0.0f);
gl.glVertex3f(-10.0f,-10.0f,0.0f);
gl.glVertex3f(10.0f,-10.0f,0.0f);
gl.glEnd();
gl.glPopMatrix();
And finally my shader code which is in a text file called “fragShader.glsl”. I have not spent any time learning the actual glsl since I first have to figure out how to get a shader running in the first place. I took this code from the 3D lighthouse tutorial (it said it colors pixels a blue shade):
void main()
{
gl_FragColor = vec4(0.4,0.4,0.8,1.0);
}
I don’t know if there should be more to this or not. Based on what I read, it seems to imply this these lines are all there is.
Perhaps someone can point out my error(s). Thanks