OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Sprite.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "Camera.h"
10 #include "Render.h"
11 #include "TextureManager.h"
12 #include "World.h"
13 #include "Sprite.h"
14 
15 const static float scale = 4.0f;
16 const static float texelScale = 256.0f;
17 const static int texelOffset = 2;
18 
19 Sprite::Sprite(int tile, int x, int y, int width, int height) : texture(tile) {
20  width >>= 8;
21  height >>= 8;
22 
23  int width2 = (int)(width * scale);
24  int height2 = (int)(height * scale);
25 
26  std::vector<glm::vec2> uv;
27  uv.emplace_back(float(x + texelOffset) / texelScale, float(y + height) / texelScale);
28  uv.emplace_back(float(x + texelOffset) / texelScale, float(y + texelOffset) / texelScale);
29  uv.emplace_back(float(x + width) / texelScale, float(y + texelOffset) / texelScale);
30  uv.emplace_back(float(x + width) / texelScale, float(y + height) / texelScale);
31  uv.emplace_back(uv.at(0));
32  uv.emplace_back(uv.at(2));
33 
34  std::vector<glm::vec3> vert;
35  vert.emplace_back(float(-width2) / 2.0f, 0.0f, 0.0f);
36  vert.emplace_back(float(-width2) / 2.0f, float(-height2), 0.0f);
37  vert.emplace_back(float(width2) / 2.0f, float(-height2), 0.0f);
38  vert.emplace_back(float(width2) / 2.0f, 0.0f, 0.0f);
39  vert.emplace_back(vert.at(0));
40  vert.emplace_back(vert.at(2));
41 
42  vertices.bufferData(vert);
43  uvs.bufferData(uv);
44 
45  uv2D = glm::vec4(uv.at(0), uv.at(2));
46 }
47 
48 void Sprite::display(glm::mat4 MVP) {
50 }
51 
52 // ----------------------------------------------------------------------------
53 
54 void SpriteSequence::display(glm::mat4 MVP, int index) {
55  assertGreaterThanEqual(index, 0);
56  assertLessThan(index, length);
57  getWorld().getSprite(start + index).display(MVP);
58 }
59 
glm::vec4 uv2D
Definition: Sprite.h:24
void bufferData(int elem, int size, void *data)
Definition: Shader.cpp:18
2D Billboard Collection
int length
Definition: Sprite.h:40
static const int texelOffset
Definition: Sprite.cpp:17
World Model.
World & getWorld()
Definition: main.cpp:32
Included everywhere.
Sprite(int tile, int x, int y, int width, int height)
Definition: Sprite.cpp:19
int texture
Definition: Sprite.h:22
ShaderBuffer uvs
Definition: Sprite.h:23
static void drawGL(ShaderBuffer &vertices, ShaderBuffer &uvs, glm::vec4 color, unsigned int texture, TextureStorage store=TextureStorage::SYSTEM, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=textShader)
Definition: Shader.cpp:278
World Renderer.
void display(glm::mat4 MVP)
Definition: Sprite.cpp:48
Sprite & getSprite(unsigned long index)
Definition: World.cpp:46
#define assertGreaterThanEqual(x, y)
Definition: global.h:170
Texture Registry.
static const float texelScale
Definition: Sprite.cpp:16
static const float scale
Definition: Sprite.cpp:15
Camera, View Frustum.
#define assertLessThan(x, y)
Definition: global.h:146
ShaderBuffer vertices
Definition: Sprite.h:23
void display(glm::mat4 MVP, int index)
Definition: Sprite.cpp:54