vertex buffer objects

After looking at this tutorial and even importing the useful parts of the tutorial code, I am lost on the part with the vertex coordinates and indices buffer. Is it absolutely essential in terms of ease to have a buffer for the indices? I have two separate arrays that are stored as [x1 y1 z1 … xn yn zn], but I don’t have any indices of each node. What would be your recommendations if I don’t have an index buffer? Make something up?


Indices are not necessary. When you have a mesh where many triagles share a vertex plus texture coordinates, normals and other per-vertex attributte, indices can save you a lot of memory. Also if, for example, you are animating your mesh, with inidices you just have to modify one vertex and all the triangles connected to it will be updated.
Of course if you only have vertices and you are not editing them, and no connected primitives are used, just send the vertexs :).

I ended up didn’t use this tutorial other than for references on the functions only. I followed this instead. I used vbo without the indices, but I can find out the indexing information if it’s helpful on reducing significant memory usage. However, I didn’t have anything rendered in the image.

I have uploaded the relevant source code, libraries, and binary files to as a public repository for now in case if you want to make any comments on what I did that may have caused the project not to render the points. Meanwhile, it would also be helpful to hear the most common issues with using vertex buffer objects in order to render arrays that contain all the vertices. Thanks.

You use
glVertexPointer(3, GL_FLOAT, 0, 0);
but I don’t see you enable that pointer:

I used vbo without the indices, but I can find out the indexing information if it’s helpful on reducing significant memory usage. However, I didn’t have anything rendered in the image.

Take a sphere with n vertical division and m horizontal division.
You will have n triangle on the top, n on the bottom and a grid of m*(n-1) quad = 2 * m(n-1) triangle and nm+2 vertices.
Without indexing you have to memorize
3 * (2 * n + m(n-1)) triangle vertices
with indexing you have to memorize
n+2 vertices and 3 * (2 * n + m(n-1)) index
Every vertices (if you memorize only the position) is tree float, every index is an integer (but you can use short or even byte).
With n = 10; m = 10 you have
3 * (2* 10 + 10 * 9) * 3 * sizeof(float) = 3960 byte with non index mode and
3 * (2* 10 + 10 * 9) * sizeof(int) + (10*10+2)3sizeof(float) = 2544 byte with index mode.
the memory consumption become much worse for non index mode if you have normal, texture coordinates and colour in your vertex structures.
The only bad thing about index mode is that you have to split vertices if triangle don’t share some attribute (like normal in sharp edge or texCoord on texture cut) that’s why I choose a sphere for the example. :smiley:

I have added a few lines in the appropriate areas (what I think is appropriate based on what I read on relevant resources on vbo), and updated it to the repository ( However, it still doesn’t render anything on the screen (i.e. pitch black). I have also tried a much simpler example of drawing a triangle using vbo on the screen, but not much luck either. I’m not sure if it would have anything to do with sdl toolkit initialization problem.

I haven’t started working out on the example of the indices and the nodes yet for the sphere. I have been trying to get a simple example working, and then work on the vertex indices later.

Indices are also good because some of the vertices can be precached, but that’s not always the case with all those shaders nowadays.

But if it’s simple geometry, call glDrawArrays(…?..? GL_TRIANGLES …?..?);

I did call glDrawArrays() function with the 3 parameters as I wrote in the code. I’m going to double-check if I set up the SDL toolkit on OpenGL properly.

Cross-check whether with simple arrays (no vbos) anything is drawn at all.

glVertexPointer(3, GL_FLOAT, 0, myVertices);
It could be something as simple as having foreground color = clear (background) color, or camera is not looking at object at all.

I have tried to render simple vertex arrays using the following method:

/* Vertices of a triangle (counter-clockwise winding) */
	float data[] = {1.0, 0.0, 1.0, 0.0, 0.0, -1.0, -1.0, 0.0, 1.0};

	if (rInfo.vboSupported)
	/*	rInfo.vboId1 = createVBO(model.xall.nodepts, DIMENSIONS*sizeof(float)*model.xall.entries,
		rInfo.vboId2 = createVBO(model.xndisp.nodepts, DIMENSIONS*sizeof(float)*model.xndisp.entries,
		id = createVBO(&data[0], sizeof(data), GL_ARRAY_BUFFER_ARB, GL_STATIC_DRAW_ARB);


	glVertexPointer(3, GL_FLOAT, 0, &data[0]);

	glDrawArrays(GL_TRIANGLES, 0, 3);



At the same time, I have also attempted to clear the foreground color as well as attempting to set a camera view in the initialization function:

void renderInfo::initialize()
	if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
			"Couldn't initialize SDL: %s
", SDL_GetError());

	SDL_WM_SetCaption("My first OpenGL program", NULL);		// change the name later
	screen = SDL_SetVideoMode(640, 480, 32, flags);
	if ( screen == NULL ) {
		fprintf(stderr, "Couldn't set 640x480x8 video mode: %s

	// clear foreground color
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);

	videoinfo = SDL_GetVideoInfo();

	printf("%i", videoinfo->blit_hw);

	// set up double buffering

	// set up RGBA
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

	// set up camera
	gluPerspective(45.0f, // 45 degrees
				   (float) screen->w / (float) screen->h, // 1:1 aspect ratio
				   0.01f, // distance from the viewer to the near clipping plane
				   100.0f // distance from the viewer to the far clipping plane
	gluLookAt(5, 5, 5,
			  1, 0, 0,
			  0, 0, 1);

	// check if the video card and operating system supports VBO
	if (strstr((char*) glGetString(GL_EXTENSIONS),"ARB_vertex_buffer_object"))
#ifdef _WIN32			// if running under Windows, retrieve the function pointers; otherwise, no need
		//get function pointers using SDL_GL_GetProcAddress(..)
		// (could be using wglGetProcAddress(..) too)

		vboSupported = true;

However, nothing still is rendering. Could there be other factors other than the undesired foreground color and improper setup of the camera viewpoint? Thanks. (I have also updated the changes to the repository in case if you want to take a look).

Setting the clear-color is done via glClearColor()

Start with something simpler. See it work. Add a few lines, see it work. Then jump onto VBOs (though as you see it’s easy).