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.
|
|
#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(v * 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); }
TextureSolidColor::TextureSolidColor(const Vector3 & color) { mSolidColor = color; }
Vector3 TextureSolidColor::Sample(float u, float v) { return mSolidColor; }
|