-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphic.cpp
64 lines (55 loc) · 1.18 KB
/
Graphic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Graphic.cpp
// GLFWosxTEST1
//
// Created by 王宇鑫 on 2017/9/7.
// Copyright © 2017年 王宇鑫. All rights reserved.
//
#include "Graphic.hpp"
#include <string>
using namespace std;
//for test
GLfloat testBuffer[] = {
/*
-0.5, -0.5, 0,
0.5, -0.5, 0,
0, 0.5, 0,
*/
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f
};
GLuint testIndices[] = {
0, 1, 3,
1, 2, 3
};
Graphic::Graphic() : number(sizeof(testBuffer) / sizeof(GLfloat))
{
vertexBuffer = new GLfloat[number];
indices = new GLuint[sizeof(testIndices) / sizeof(GLuint)];
memcpy(vertexBuffer, testBuffer, sizeof(GLfloat) * number);
memcpy(indices, testIndices, sizeof(testIndices));
}
GLfloat& Graphic::operator[](int index)
{
if (!(index >= 0 && index < number))
throw string("out of range");
return vertexBuffer[index];
}
int Graphic::size()
{
return number * sizeof(GLfloat);
}
GLfloat* Graphic::pointer()
{
return vertexBuffer;
}
int Graphic::indicesSize()
{
return sizeof(testIndices);
}
GLuint* Graphic::getIndices()
{
return indices;
}