I have 4 dimensional vertices(X,Y,A,B) that I'd like to draw as 6 separate 2D plots (XxY, XxA, XxB, YxA, ...)
My vertices are defined as follows:
GLint data[MAX_N_POINT][4];
I can draw the first (X,Y) of the 2D plots just fine with:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(4, GL_INT, 4*sizeof(GLint), &data[0][0]);
glDrawArrays(GL_POINTS, 0, MAX_N_POINT-1);
glDisableclientState(GL_VERTEX_ARRAY);
To draw the other 2D plots (XxA, AxB, etc...) I've decided to use a shader that swizzles the X,Y,Z,W dimensions of the vertices depending on which dimensions I want to draw.:
uniform int axes;
void main()
{
vec2 point;
if (axes == 0) {
point = gl_Vertex.xy;
} else if (axes == 1) {
point = gl_Vertex.xz;
} else if (axes == 2) {
point = gl_Vertex.xw;
} else if (axes == 3) {
point = gl_Vertex.yz;
} else if (axes == 4) {
point = gl_Vertex.yw;
} else if (axes == 5) {
point = gl_Vertex.zw;
}
gl_Position = gl_ModelViewProjectionMatrix * vec4(point.xy, 0.0, 1.0);
gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;
}
I've successfully loaded, compiled, added to the shader to a program, and linked the program.
Now that I have the shader program its not clear how to use the program such that is affects the way my vertex arrays are drawn. I've tried the following but it appears to have no effect as it draws things exactly like there were without the shader:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(4, GL_INT, 4*sizeof(GLint), &data1[0][0]);
//New shader code here
glUseProgram(shaderProg);
int plotAxes = rand()%4;
GLint axes = glGetUniformLocation(shaderProg, "axes");
glUniform1i(axes, plotAxes);
glDrawArrays(GL_POINTS, 0, MAX_N_POINT-1);
glDisableClientState(GL_VERTEX_ARRAY);
glUseProgram(0);
Is there something fundamental that I am missing or don't understand properly?
Edit 2: I've updated the shader code per Christian's suggestions. I've also verified that shade loads without errors however if I check for OpenGl errors after I call glUseProgram I get an OpenGL Error: invalid operation
error.
Edit 3: Here is the final shader that worked:
uniform int axes;
void main()
{
vec4 point;
if (axes == 0) {
point = gl_Vertex;
} else if (axes == 1) {
point = gl_Vertex.xzyw;
} else if (axes == 2) {
point = gl_Vertex.xwzy;
} else if (axes == 3) {
point = gl_Vertex.yzxw;
} else if (axes == 4) {
point = gl_Vertex.ywxz;
} else if (axes == 5) {
point = gl_Vertex.zwxy;
}
point.z = 0.0;
point.w = 1.0;
// eliminate w point
gl_Position = gl_ModelViewProjectionMatrix * point;
gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;
}