You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
970 B
39 lines
970 B
#include "Texture.h"
|
|
#include "util.h"
|
|
|
|
TextureRGB::TextureRGB()
|
|
{
|
|
mImageFileContent = nullptr;
|
|
mRGBPixel = nullptr;
|
|
mWidth = 0;
|
|
mHeight = 0;
|
|
}
|
|
|
|
TextureRGB::~TextureRGB()
|
|
{
|
|
if (mImageFileContent) {
|
|
delete[] mImageFileContent;
|
|
}
|
|
}
|
|
|
|
void TextureRGB::Set(const char * image_path)
|
|
{
|
|
int file_size = 0;
|
|
mImageFileContent = LoadFileContent(image_path, file_size);
|
|
mRGBPixel = DecodeBMP(mImageFileContent, mWidth, mHeight);
|
|
}
|
|
|
|
Vector3 TextureRGB::Sample(float u, float v)
|
|
{
|
|
int x = int(u * mWidth);
|
|
int y = int(u * mHeight);
|
|
x = x < 0 ? 0 : x;
|
|
y = y < 0 ? 0 : y;
|
|
x = x > (mWidth - 1) ? (mWidth - 1) : x;
|
|
y = y > (mHeight - 1) ? (mHeight - 1) : y;
|
|
int pixel_data_start_index = 3 * (x + y * mWidth);
|
|
float r = float(mRGBPixel[pixel_data_start_index]) / 255.0f;
|
|
float g = float(mRGBPixel[pixel_data_start_index + 1]) / 255.0f;
|
|
float b = float(mRGBPixel[pixel_data_start_index + 2]) / 255.0f;
|
|
return Vector3(r, g, b);
|
|
}
|