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,
GL_ARRAY_BUFFER_ARB, GL_DYNAMIC_DRAW_ARB);
rInfo.vboId2 = createVBO(model.xndisp.nodepts, DIMENSIONS*sizeof(float)*model.xndisp.entries,
GL_ARRAY_BUFFER_ARB, GL_DYNAMIC_DRAW_ARB);*/
id = createVBO(&data[0], sizeof(data), GL_ARRAY_BUFFER_ARB, GL_STATIC_DRAW_ARB);
}
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &data[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableClientState(GL_VERTEX_ARRAY);
SDL_GL_SwapBuffers();
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 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s
", SDL_GetError());
exit(1);
}
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
",
SDL_GetError());
exit(1);
}
// clear foreground color
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
SDL_FillRect(screen,NULL,0x000000);
videoinfo = SDL_GetVideoInfo();
printf("%i", videoinfo->blit_hw);
// set up double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// 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)
pglBindBufferARB = (PFNGLBINDBUFFERARBPROC)
SDL_GL_GetProcAddress("glBindBufferARB");
pglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)
SDL_GL_GetProcAddress("glGenBuffersARB");
pglBufferDataARB = (PFNGLBUFFERDATAARBPROC)
SDL_GL_GetProcAddress("glBufferDataARB");
pglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)
SDL_GL_GetProcAddress("glDeleteBuffersARB");
pglGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)
SDL_GL_GetProcAddress("glGetBufferParameterivARB");
#endif
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).