C++ Maya Viewport 2.0 Shader -- getting the texture to work

64 views
Skip to first unread message

cron...@gmail.com

unread,
Dec 28, 2015, 10:21:52 AM12/28/15
to Python Programming for Autodesk Maya
Hey guys i couldnt exactly find a solution and the maya docs on this arent clear at all.
I currently have the implementation working for the old viewport working and i cant find anything on the getting the 2.0 to work.

so far heres the code i have.

in my maya scene i have a file node with a file plugged in so i can have image data existing without it being plugged in.

now it does set the overall color when the texture doesnt exist(which is what i have it set up to do) but i think im missing a step in setting it up or setting to the gl or something



MHWRender::MTextureManager *textureManager = renderer->getTextureManager();
if(textureManager){
MImage image;
MSelectionList selection;
selection.add("file1");
MObject obj;
selection.getDependNode(0, obj);

image.readFromTextureNode(obj);

image.resize(1024, 1024, false);
unsigned int width, height;
image.getSize(width, height);



MHWRender::MTextureDescription textureDesc;
textureDesc.setToDefault2DTexture();

textureDesc.fWidth = width;
textureDesc.fHeight = height;
textureDesc.fDepth = 1;
textureDesc.fBytesPerRow = 4*width;
textureDesc.fBytesPerSlice = textureDesc.fBytesPerRow*height;
textureDesc.fTextureType = MHWRender::kImage2D;

// textureDesc.fEnvMapType = MHWRender::kEnvNone;

// Construct the texture with the screen pixels
mColorTexture.texture = textureManager->acquireTexture("", textureDesc, image.pixels());



if(mColorTexture.texture){
mColorTexture.texture->textureDescription( textureDesc );
fColorShaderInstance->setParameter("diffuseColor", mColorTexture);
// textureManager->releaseTexture(texture);
cout << "got texture" << endl;
}else{
cout << "no texture" << endl;
fColorShaderInstance->setParameter("diffuseColor", &fDiffuse[0]);
}
}
}
Reply all
Reply to author
Forward
0 new messages