Add API to load texture file.

This commit is contained in:
yunfeibai
2016-10-20 22:11:38 -07:00
parent 1c04da23db
commit 05be92d006
3 changed files with 24 additions and 33 deletions

View File

@@ -70,7 +70,9 @@ struct TinyRendererVisualShapeConverterInternalData
int m_swWidth;
int m_swHeight;
TGAImage m_rgbColorBuffer;
TGAImage m_texture;
unsigned char* m_texture;
int m_textureWidth;
int m_textureHeight;
b3AlignedObjectArray<float> m_depthBuffer;
b3AlignedObjectArray<int> m_segmentationMaskBuffer;
@@ -80,8 +82,7 @@ struct TinyRendererVisualShapeConverterInternalData
:m_upAxis(2),
m_swWidth(START_WIDTH),
m_swHeight(START_HEIGHT),
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB),
m_texture(START_WIDTH,START_HEIGHT,TGAImage::RGB)
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB)
{
m_depthBuffer.resize(m_swWidth*m_swHeight);
m_segmentationMaskBuffer.resize(m_swWidth*m_swHeight,-1);
@@ -834,12 +835,6 @@ void TinyRendererVisualShapeConverter::resetAll()
// Get shapeUniqueId from getVisualShapesData?
void TinyRendererVisualShapeConverter::activateShapeTexture(int shapeUniqueId, int textureUniqueId)
{
int width,height,n;
const char filename[] = "/Users/yunfeibai/Documents/dev/bullet-change-texture/bullet3/data/checker_huge.gif";
unsigned char* image=0;
image = stbi_load(filename, &width, &height, &n, 3);
// Use shapeUniqueId?
int objectArrayIndex = 8;
int objectIndex = 0;
@@ -848,29 +843,22 @@ void TinyRendererVisualShapeConverter::activateShapeTexture(int shapeUniqueId, i
if (ptrptr && *ptrptr)
{
TinyRendererObjectArray* ptr = *ptrptr;
unsigned char textureImage[3] = {255, 0, 0};
int textureWidth = 1;
int textureHeight = 1;
//ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(textureImage,textureWidth,textureHeight);
ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(image,width,height);
ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(m_data->m_texture,m_data->m_textureWidth,m_data->m_textureHeight);
}
/*
int objectArrayIndex = 0;
int objectIndex = 0;
printf("num m_swRenderInstances = %d\n", m_data->m_swRenderInstances.size());
for (int i=0;i<m_data->m_swRenderInstances.size();i++)
{
TinyRendererObjectArray** ptrptr = m_data->m_swRenderInstances.getAtIndex(i);
if (ptrptr && *ptrptr)
{
TinyRendererObjectArray* ptr = *ptrptr;
unsigned char textureImage[3] = {255, 10, 10};
int textureWidth = 1;
int textureHeight = 1;
ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(textureImage,textureWidth,textureHeight);
}
}
*/
}
int TinyRendererVisualShapeConverter::registerTexture(unsigned char* texels, int width, int height)
{
m_data->m_texture = texels;
m_data->m_textureWidth = width;
m_data->m_textureHeight = height;
return 0;
}
void TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
{
int width,height,n;
unsigned char* image=0;
image = stbi_load(filename, &width, &height, &n, 3);
registerTexture(image, width, height);
}