Think doing VBOs right, but cannot see output

Think doing VBOs right, but cannot see output.

My code is:


        std::vector<GLfloat> vertices;
	std::vector<GLfloat> normals;

	for (int j = 0; j < vecf.size(); j++) {
		normals.push_back(vecn[vecf.at(j)[2] - 1][0]); normals.push_back(vecn[vecf.at(j)[2] - 1][1]); normals.push_back(vecn[vecf.at(j)[2] - 1][2]);
		vertices.push_back(vecv[vecf.at(j)[0] - 1][0]); vertices.push_back(vecv[vecf.at(j)[0] - 1][1]); vertices.push_back(vecv[vecf.at(j)[0] - 1][2]);
		normals.push_back(vecn[vecf.at(j)[5] - 1][0]); normals.push_back(vecn[vecf.at(j)[5] - 1][1]); normals.push_back(vecn[vecf.at(j)[5] - 1][2]);
		vertices.push_back(vecv[vecf.at(j)[3] - 1][0]); vertices.push_back(vecv[vecf.at(j)[3] - 1][1]); vertices.push_back(vecv[vecf.at(j)[3] - 1][2]);
		normals.push_back(vecn[vecf.at(j)[8] - 1][0]); normals.push_back(vecn[vecf.at(j)[8] - 1][1]); normals.push_back(vecn[vecf.at(j)[8] - 1][2]);
		vertices.push_back(vecv[vecf.at(j)[6] - 1][0]); vertices.push_back(vecv[vecf.at(j)[6] - 1][1]); vertices.push_back(vecv[vecf.at(j)[6] - 1][2]);
	}

	glEnableClientState(0);
	glEnableClientState(1);

	glVertexPointer(3, GL_FLOAT, 0, &vertices[0]);
	glNormalPointer(GL_FLOAT, 0, &normals[0]);

	/*glDrawArrays(GL_TRIANGLES, 0, vertices.size());*/
	glDrawElements(GL_TRIANGLES, vertices.size(), GL_FLOAT, &vertices[0]);

	glDisableClientState(0);
	glDisableClientState(1);

The above code runs without errors, but I see nothing drawn, just black screen.

I’ve followed these:

https://www.opengl.org/discussion_boards/showthread.php/141959-How-do-I-use-glVertexPointer
https://github.com/sriharshachilakapati/LWJGL-Tutorial-Series/blob/a1a66d2bfb53d1da4205425402b96712277e0f39/src/com/shc/tutorials/lwjgl/tutorial4/Tutorial4.java

My existing and working code with glBegin(GL_TRIANGLES); glEnd(); is:


        glBegin(GL_TRIANGLES);

	for(int j = 0; j < vecf.size(); j++){
		glNormal3f(vecn[vecf.at(j)[2]-1][0], vecn[vecf.at(j)[2]-1][1], vecn[vecf.at(j)[2]-1][2]);
		glVertex3f(vecv[vecf.at(j)[0]-1][0], vecv[vecf.at(j)[0]-1][1], vecv[vecf.at(j)[0]-1][2]);
		glNormal3f(vecn[vecf.at(j)[5]-1][0], vecn[vecf.at(j)[5]-1][1], vecn[vecf.at(j)[5]-1][2]);
		glVertex3f(vecv[vecf.at(j)[3]-1][0], vecv[vecf.at(j)[3]-1][1], vecv[vecf.at(j)[3]-1][2]);
		glNormal3f(vecn[vecf.at(j)[8]-1][0], vecn[vecf.at(j)[8]-1][1], vecn[vecf.at(j)[8]-1][2]);
		glVertex3f(vecv[vecf.at(j)[6]-1][0], vecv[vecf.at(j)[6]-1][1], vecv[vecf.at(j)[6]-1][2]);
	}

	glEnd();

Note that your code doesn’t use VBOs (vertex buffer objects), but uses client-side vertex arrays. If you’re trying to convert glBegin/glEnd code to use VBOs, client-side vertex arrays are a reasonable intermediate step.

This should almost work (assuming that [var]vertices[/var] and [var]normals[/var] contain valid data). However, the last parameter should be divided by 3 (it’s the number of vertices, but vertices.size() is the number of individual floats).

This definitely won’t work, as the last parameter needs to be an array of indices.

I’m using the code that I have BTW, because I noticed that I was bound to freeGLUT 2.0.1 and OpenGL 3.3. I couldn’t find newer functions than these.

I wonder if the versions I have even support VBOs?

I will check those mentions.

Okay I tried the:

glDrawArrays(GL_TRIANGLES, 0, vertices.size()/3);

added to the above. Still no output.

The normals and vertices I believe should be correct, because my glBegin(GL_TRIANGLES); glEnd(); block looked like:


        glBegin(GL_TRIANGLES);

	for(int j = 0; j < vecf.size(); j++){
		glNormal3f(vecn[vecf.at(j)[2]-1][0], vecn[vecf.at(j)[2]-1][1], vecn[vecf.at(j)[2]-1][2]);
		glVertex3f(vecv[vecf.at(j)[0]-1][0], vecv[vecf.at(j)[0]-1][1], vecv[vecf.at(j)[0]-1][2]);
		glNormal3f(vecn[vecf.at(j)[5]-1][0], vecn[vecf.at(j)[5]-1][1], vecn[vecf.at(j)[5]-1][2]);
		glVertex3f(vecv[vecf.at(j)[3]-1][0], vecv[vecf.at(j)[3]-1][1], vecv[vecf.at(j)[3]-1][2]);
		glNormal3f(vecn[vecf.at(j)[8]-1][0], vecn[vecf.at(j)[8]-1][1], vecn[vecf.at(j)[8]-1][2]);
		glVertex3f(vecv[vecf.at(j)[6]-1][0], vecv[vecf.at(j)[6]-1][1], vecv[vecf.at(j)[6]-1][2]);
	}

	glEnd();

And my new code essentially constructs std::vector<GLfloat> using the same loop and same elements.

Even if there was errors in the construction, I’d expect to see at least something.

Okay I found the issue.

I had to replace


glEnableClientState(0);
glEnableClientState(1);
...
glDisableClientState(0);
glDisableClientState(1);

with


glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
...
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

Does this mean that one cannot have multiple GL_VERTEX_ARRAYs identified using different identifiers?

Does this mean that one cannot have multiple GL_VERTEX_ARRAYs identified using different identifiers?

So long as you’re using the old fixed-function vertex attributes, no, you cannot have multiple GL_VERTEX_ARRAYs at the same time.

However, since you’re using fixed-function rendering, that wouldn’t make sense anyway. GL_VERTEX_ARRAY has a very well-defined meaning: the array containing the position of the vertices. Vertices cannot have more than one position in fixed-function rendering, so it doesn’t make sense to allow multiple such arrays. Similarly, vertices cannot have more than one normal.

[QUOTE=Alfonse Reinheart;1292167]So long as you’re using the old fixed-function vertex attributes, no, you cannot have multiple GL_VERTEX_ARRAYs at the same time.

However, since you’re using fixed-function rendering, that wouldn’t make sense anyway. GL_VERTEX_ARRAY has a very well-defined meaning: the array containing the position of the vertices. Vertices cannot have more than one position in fixed-function rendering, so it doesn’t make sense to allow multiple such arrays. Similarly, vertices cannot have more than one normal.[/QUOTE]

So is the idea that one puts all one’s objects to a single array and then renders them from it using index ranges?

That’s one option. Another is to switch between arrays by calling glVertexPointer() etc between draw calls.