Simple 2D plot program displays blank

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()
  glDrawArrays(GL_POINTS, 0, vertexData.size());
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
  //glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
  glClearColor(0.0, 0.0, 0.0, 1.0);
  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);

  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…

I need some more info to know how your data is actually structured.

  1. What exactly does generate_vertexData do? How does it generate the data, some code would be really helpful
  2. How is vertexData defined? I’m assuming it’s an array of arrays by this expression &(vertexData[0][0]), but of what type?

Here is the required info:

static vector<vec3> vertexData;

float F(float u, float v) {return 0.5*sin(8.0*M_PI*u)*sin(4.0*M_PI*v);}
void generate_vertexData()
	float Maxtable[3*NumCurves];
	for (int i=0; i<3*NumCurves;i++) Maxtable[i]=0.0;
	float dv = 0.5/(NumCurves-1);
	float du = 0.5*dv;
	float v = 0.0;
	for (int t=0; t<NumCurves;t++) {
		float u =0.0;
		for (int k=0;k<2*NumCurves-1;k++) {
			float w = F(u,v);
			float x = u+0.5*v;
			float y = w+0.5*v;
			Maxtable[t+k] = (y>=Maxtable[t+k]?y:Maxtable[t+k]);
/*	for (int k=0; k<2*NumCurves-1; k++) {
		for (int t=0; t<NumCurves; t++) {

a vector of vec3 is the type of vertexData

I can’t really test generate_vertexData because it has a few formatting issues which I can’t resolve by just guessing.
However, everything else seems to work, I assume the problem is somewhere inside generate_vertexData.
I can give you a tip, try to use simpler points. Instead of generating them, try manually creating a list of points, at positions you recognize.

vertexData =
    glm::vec3(0.0f, 0.0f, 0.0f),
    glm::vec3(0.25f, 0.0f, 0.0f),
    glm::vec3(0.50f, 0.0f, 0.0f),
    glm::vec3(0.75f, 0.0f, 0.0f),

This will help you verify that your initialization is at least correct

Actually, your program runs fine. Can you show me your shader code?
Vertex and fragment shader, please

Here is the vertex shader:

#version 450

layout( location = 0 ) in vec3 vPosition;
uniform mat4 MVP;
    gl_Position = MVP*vec4(, 1.0);

and here is the fragment shader:

#version 450 core

uniform vec3 Color;
out vec4 fColor;

void main()
    fColor = vec4(Color.rgb, 1.0);

Try changing glUniform1fv(colorID, 3, red) to glUniform3fv(colorID, 1, red), in setup function

this is how i did it (in 2D, y=f(x))

I did, also I had the call generate_vertexData() after allocating the buffer. Now everything is working as expected. Thanks for your help, it was a great asset…

Great work, but the problem here is w=f(u,v), that is in 3D and its plot is projected into 2D. u(x axis) moves the plot right(x axis) and v(y axis) moves the plot right and up(both x and y) and w(z axis) moves the plot up (y axis); hence the formula x = u + 0.5v and y=w + 0.5v.