From d76fb43a3ca814ebdefe0e60a848a4544ed6c429 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 30 Apr 2011 09:08:58 -0400 Subject: [PATCH] add makeBuffer() and triangle data --- template/test.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/template/test.cc b/template/test.cc index 0fad8fb..08afa6e 100644 --- a/template/test.cc +++ b/template/test.cc @@ -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; }