12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "TextureMesh.h"
- #include <cstring>
- #include <iostream>
- using namespace std;
- TextureMesh::TextureMesh()
- {
- data = new float[dataSize * 5];
- }
- TextureMesh::TextureMesh(const TextureMesh& orig)
- {
- }
- TextureMesh::~TextureMesh()
- {
- delete[] data;
- glDeleteVertexArrays(1, &vba);
- glDeleteBuffers(1, &vbo);
- }
- void TextureMesh::init()
- {
- glGenVertexArrays(1, &vba);
- glBindVertexArray(vba);
-
- glGenBuffers(1, &vbo);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glVertexAttribPointer(0, 3, GL_FLOAT, 0, 20, (GLvoid*) 0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(2, 2, GL_FLOAT, 0, 20, (GLvoid*) 12);
- glEnableVertexAttribArray(2);
- }
- void TextureMesh::addPoint(float x, float y, float z, float tx, float ty)
- {
- if(vertices >= dataSize)
- {
- float* newData = new float[dataSize * 2 * 5];
- memcpy(newData, data, sizeof(float) * dataSize * 5);
- delete[] data;
- data = newData;
- dataSize *= 2;
- }
- unsigned int index = vertices * 5;
- data[index] = x;
- data[index + 1] = y;
- data[index + 2] = z;
- data[index + 3] = tx;
- data[index + 4] = ty;
-
- vertices++;
- }
- void TextureMesh::build()
- {
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
-
- /*for(int i = 0; i < vertices; i++)
- {
- int index = i * 7;
- cout << data[index] << " " << data[index + 1] << " " << data[index + 2]
- << " " << data[index + 3] << " " << data[index + 4] << " "
- << data[index + 5] << " " << data[index + 6] << endl;
- }*/
-
- glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 5 * vertices, data, GL_STATIC_DRAW);
- }
- void TextureMesh::draw()
- {
- glBindVertexArray(vba);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glDrawArrays(GL_TRIANGLES, 0, vertices);
- }
|