-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.cpp
More file actions
49 lines (44 loc) · 1.02 KB
/
Texture.cpp
File metadata and controls
49 lines (44 loc) · 1.02 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
//
// Created by Ben Dickson on 5/4/17.
//
#include <cstdlib>
#include "Texture.h"
/**
* Basic Constructor
* @param textureData
* @param textureDataSize
* @param textureWidth
* @param textureHeight
*/
Texture::Texture(unsigned char* textureData , unsigned int textureDataSize ,
unsigned int textureWidth , unsigned int textureHeight)
{
width = textureWidth;
height = textureHeight;
byteCount = width*height*bytesPerPixel;
dataSize = textureDataSize;
data = textureData;
frames = dataSize / byteCount;
}
/**
* generates a texture frame as unique image data
* @param frameNumber
* @return
*/
unsigned char* Texture::renderFrame(unsigned int frameNumber)
{
unsigned char* r;
r = (unsigned char*) malloc (byteCount);
int i = -1;
int startByte = byteCount * frameNumber;
if(startByte+byteCount>dataSize)
{
// error state -> return first frame
startByte = 0;
}
while(++i<byteCount)
{
r[i] = data[startByte+i];
}
return r;
}