add makeBuffer() and triangle data

This commit is contained in:
Josh Holtrop 2011-04-30 09:08:58 -04:00
parent 9a0ffa8cbe
commit d76fb43a3c

View File

@ -12,7 +12,18 @@ using namespace std;
#define WIDTH 800
#define HEIGHT 600
GLuint program, vs, fs;
const GLfloat data[][2][3] = {
{{-1.0, -0.6, 0.0}, {1, 0, 0}},
{{-0.2, -0.6, 0.0}, {0, 1, 0}},
{{-0.6, 0.6, 0.0}, {0, 0, 1}},
{{0.2, -0.6, 0.0}, {1, 0, 0}},
{{1.0, -0.6, 0.0}, {0, 1, 0}},
{{0.6, 0.6, -500.0}, {0, 0, 1}}
};
const GLushort indices[] = {
0, 1, 2, 3, 4, 5
};
GLuint program, vs, fs, data_vbo, index_vbo;
char * loadFile(const char *fname)
{
@ -98,6 +109,15 @@ out:
return 0;
}
GLuint makeBuffer(GLenum target, const void *ptr, size_t sz)
{
GLuint id;
glGenBuffers(1, &id);
glBindBuffer(target, id);
glBufferData(target, sz, ptr, GL_STATIC_DRAW);
return id;
}
bool init(int width, int height)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
@ -106,7 +126,7 @@ bool init(int width, int height)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho((float)-width/(float)height, (float)width/(float)height,
-1, 1, -1, 1);
-1, 1, -1000, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@ -135,6 +155,9 @@ bool init(int width, int height)
return false;
}
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
return true;
}