| 86 | } |
| 87 | |
| 88 | GLuint vaoTextCreate(const VertexBasic* verticies, int size){ |
| 89 | //create vertex buffer object |
| 90 | GLuint vao; |
| 91 | glGenVertexArrays(1, &vao); |
| 92 | glBindVertexArray(vao); |
| 93 | |
| 94 | GLuint vbo; |
| 95 | glGenBuffers(1, &vbo); |
| 96 | glBindBuffer(GL_ARRAY_BUFFER, vbo); |
| 97 | //copy the vertex data to VRAM |
| 98 | glBufferData(GL_ARRAY_BUFFER, size, verticies, GL_STATIC_DRAW); //store in VRAM |
| 99 | |
| 100 | //define position attribute location |
| 101 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(VertexBasic), (void*)offsetof(VertexBasic, position)); |
| 102 | glEnableVertexAttribArray(0); |
| 103 | //define texCoord attribute location |
| 104 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexBasic), (void*)offsetof(VertexBasic, texCoord)); |
| 105 | glEnableVertexAttribArray(1); |
| 106 | |
| 107 | //unbind |
| 108 | glBindVertexArray(0); //unbind VAO |
| 109 | |
| 110 | //check for problems: |
| 111 | GLenum err = glGetError(); |
| 112 | if (err != GL_NO_ERROR){ |
| 113 | glDeleteBuffers(1, &vbo); |
| 114 | SDL_Log("Creating VBO failed: %u\n", err); |
| 115 | vbo = 0; |
| 116 | } |
| 117 | return vao; |
| 118 | } |
| 119 | |
| 120 | void vboFree(GLuint vbo){ |
| 121 | glDeleteBuffers(1, &vbo); |