I’ve just recently (very recently) started looking at how to use VBO’s and whatnot with OpenGL (my teachers always taught me to use glBegin() and glEnd(), which I now see hasn’t been used for a few generations). However, now I’m quite desperately stuck on the first step of this ladder. I can’t even draw a single damned triangle. I found the “VBO - Just Examples” page of the wiki and tried using the second version (which doesn’t use depreciated Vertex/TexCoordPointer). It’s clearly incomplete, so I filled it in as best I could, but to no avail. The code is as follows:
#include <stdlib.h>
#include <windows.h>
#include <glee.h>
#include <glut.h>
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
struct MyVertex
{
float x, y, z; //Vertex
float nx, ny, nz; //Normal
float s0, t0; //Texcoord0
};
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
gluLookAt(0,0,4,0,0,3,0,1,0);
MyVertex pvertex[3];
//VERTEX 0
pvertex[0].x = 0.0;
pvertex[0].y = 0.0;
pvertex[0].z = 0.0;
pvertex[0].nx = 0.0;
pvertex[0].ny = 0.0;
pvertex[0].nz = 1.0;
pvertex[0].s0 = 0.0;
pvertex[0].t0 = 0.0;
//VERTEX 1
pvertex[1].x = 1.0;
pvertex[1].y = 0.0;
pvertex[1].z = 0.0;
pvertex[1].nx = 0.0;
pvertex[1].ny = 0.0;
pvertex[1].nz = 1.0;
pvertex[1].s0 = 1.0;
pvertex[1].t0 = 0.0;
//VERTEX 2
pvertex[2].x = 0.0;
pvertex[2].y = 1.0;
pvertex[2].z = 0.0;
pvertex[2].nx = 0.0;
pvertex[2].ny = 0.0;
pvertex[2].nz = 1.0;
pvertex[2].s0 = 0.0;
pvertex[2].t0 = 1.0;
GLuint VertexVBOID,IndexVBOID;
glGenBuffers(1, &VertexVBOID);
glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
glBufferData(GL_ARRAY_BUFFER, sizeof(MyVertex)*3, &pvertex[0].x, GL_STATIC_DRAW);
unsigned short pindices[3];
pindices[0] = 0;
pindices[1] = 1;
pindices[2] = 2;
glGenBuffers(1, &IndexVBOID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*3, pindices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), BUFFER_OFFSET(12));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0)); //The starting point of the IBO
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(500,300);
glutCreateWindow("Camera");
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}
The screen appears, is cleared, but no triangle appears. I have literally just started using the VBO concept, so I’m absolutely certain I made a completely beginner mistake. But I don’t know what it is, so… help?
Should it be relevant, I’m using OpenGL 3.3, since it’s the latest my video card runs (on updated drivers).