I came across pseudo code in steve harrington old textbook that displays 3D f(u,v) function on 2D using x=u+0.5v and y=f(u,v)+0.5v.
I thought it would be easy to implement in modern opengl and connect lines of constant u and constant v to get the shape of the function but I got a blank screen, then I decided to just print points and still got blanks.
1225 vertexData points are generated with x and y between 0.0 and 0.75 for the chosen function and z is set to -1.0. I stared at the program for hours but could not figure out why nothing is displayed. the relevant parts are pasted below:
void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_POINTS, 0, vertexData.size());
glutSwapBuffers();
}
void resize(int w, int h)
{
glViewport(0, 0, w, h);
}
void setup()
{ // Create and compile our GLSL program from the shaders
programID = LoadShaders( "plot3D_Harrington.vshader", "plot3D_Harrington.fshader" );//"fshader.fshader");
// Use our shader
glUseProgram(programID);
//glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
glClearColor(0.0, 0.0, 0.0, 1.0);
generate_vertexData();
GLuint MVPID = glGetUniformLocation(programID, "MVP");
GLuint colorID = glGetUniformLocation(programID, "Color");
mat4 proj = ortho(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 2.0f);//frustum(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 2.0f);
glUniformMatrix4fv(MVPID, 1, GL_FALSE, &proj[0][0]);
float red[3] = {1.0, 0.0, 0.0};
glUniform1fv(colorID, 3, red);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &buf);
glBindBuffer(GL_ARRAY_BUFFER, buf);
glBufferData( GL_ARRAY_BUFFER, sizeof(vec3)*(vertexData.size()), &(vertexData[0][0]), GL_STATIC_DRAW);
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0 );
glEnableVertexAttribArray( 0 );
}
the shaders are simple. vshader setting the gl_Position and the fragment shader setting the color to red…
Need an expert eye to spot what’s wrong with the code…