-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasicSprite.cpp
More file actions
70 lines (52 loc) · 2.04 KB
/
Copy pathBasicSprite.cpp
File metadata and controls
70 lines (52 loc) · 2.04 KB
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
65
66
67
68
69
70
#include "BasicSprite.h"
BasicSprite::BasicSprite(float x, float y, char* texture, int width, int height, int bpp)
{
init = true;
QV.Initialize(x, y, texture, width, height, bpp);
}
BasicSprite::BasicSprite()
{
}
void BasicSprite::Initialize(float x, float y, char* texture, int width, int height, int bpp)
{
init = true;
QV.Initialize(x, y, texture, width, height, bpp);
}
void BasicSprite::Initialize(float x, float y, char* texture, int width, int height, int bpp, fUVs UV[4])
{
}
BasicSprite::~BasicSprite()
{
}
void BasicSprite::Draw()
{
//bind Texture
glBindTexture(GL_TEXTURE_2D, QV.uiTextureId);
glBindBuffer(GL_ARRAY_BUFFER, QV.uiVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, QV.uiIBO);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(float)* 4));
//now we have UVs to worry about, we need to send that info to the graphics card too
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(float)* 8));
//enable shaders
glUseProgram(QV.uiProgramTextured);
glBindBuffer(GL_ARRAY_BUFFER, QV.uiVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, QV.uiIBO);
glUniformMatrix4fv(QV.MatrixIDFlat, 1, GL_FALSE, QV.orthographicProjection);
//enable the vertex array states
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
/*Since the data is in the same array, we need to specify the gap between
vertices (A whole Vertex structure instance) and the offset of the data
from the beginning of the structure instance. The positions are at the
start, so their offset is 0. But the colours are after the positions, so
they are offset by the size of the position data */
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(float)* 4));
//draw to the screen
glDrawArrays(GL_QUADS, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}