add makeBuffer() and triangle data
This commit is contained in:
parent
9a0ffa8cbe
commit
d76fb43a3c
@ -12,7 +12,18 @@ using namespace std;
|
|||||||
#define WIDTH 800
|
#define WIDTH 800
|
||||||
#define HEIGHT 600
|
#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)
|
char * loadFile(const char *fname)
|
||||||
{
|
{
|
||||||
@ -98,6 +109,15 @@ out:
|
|||||||
return 0;
|
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)
|
bool init(int width, int height)
|
||||||
{
|
{
|
||||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||||
@ -106,7 +126,7 @@ bool init(int width, int height)
|
|||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho((float)-width/(float)height, (float)width/(float)height,
|
glOrtho((float)-width/(float)height, (float)width/(float)height,
|
||||||
-1, 1, -1, 1);
|
-1, 1, -1000, 1);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
@ -135,6 +155,9 @@ bool init(int width, int height)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
||||||
|
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user