Unheavly _GLBuffer and create new fanction initVertexArray
This commit is contained in:
parent
5460918bcc
commit
b6ae3369a1
2 changed files with 24 additions and 9 deletions
30
opengl.c
30
opengl.c
|
@ -91,6 +91,24 @@ void createProgram ( GLuint *shaders, int len )
|
|||
}
|
||||
}
|
||||
|
||||
void initVertexArray ( void )
|
||||
{
|
||||
glGenVertexArrays(1, &sp.vao);
|
||||
glBindVertexArray(sp.vao);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, sp.vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sp.ibo);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void *) (4*4*sizeof(float)));
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sp.ibo);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void createBuffer ( void )
|
||||
{
|
||||
GLushort indices[] = {
|
||||
|
@ -128,6 +146,7 @@ void setUniformLocation ( void )
|
|||
void startShaderProg ( void )
|
||||
{
|
||||
createBuffer();
|
||||
initVertexArray();
|
||||
|
||||
GLuint shaders[] = {
|
||||
createShader("vertex.glsl", GL_VERTEX_SHADER),
|
||||
|
@ -152,16 +171,11 @@ void _GLBuffer( void )
|
|||
glClearDepth(1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glUseProgram(sp.program);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, sp.vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sp.ibo);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void *) (4*4*sizeof(float)));
|
||||
glBindVertexArray(sp.vao);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
|
3
opengl.h
3
opengl.h
|
@ -5,9 +5,10 @@ typedef struct {
|
|||
SDL_Window* window;
|
||||
SDL_GLContext glcontext;
|
||||
} _glWindows_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
GLuint program;
|
||||
GLuint vao;
|
||||
GLuint vbo;
|
||||
GLuint ibo;
|
||||
GLuint projMatrLoc;
|
||||
|
|
Loading…
Add table
Reference in a new issue