Can you create a TextureMap in code?

SighmanSighman Posts: 55

I am trying to create a TextureMap shader in code, I can create the shader easily enough but the 'TMap' parameter is NULL by default. I've searched all the headers and there are no methods that I can find to create a IShTextureMap, at least not directly. Maybe there is another way to do it that I missed.

Any help would be appreciated.


  • Eric WinemillerEric Winemiller Posts: 84
    edited December 1969

    Use gShell3DUtilities->CreateTextureMapShader for building your shader

      MapParams inMapParams;
      inMapParams.fBrightness = 1;
      inMapParams.fFlipHoriz = false;
      inMapParams.fFlipVert = true;
      inMapParams.fNinetyDegreeCount = 0;
      gShell3DUtilities->CreateTextureMapShader(texture, inMapParams, &colorShader;);
          colorShader, highlightShader, shininessShader, bumpShader, reflectionShader,
          transparencyShader, NULL, NULL, &multiShader;);
     gShell3DUtilities->CreateMasterShader(multiShader, scene, &masterShader;);
     instance->SetShader (masterShader);

    and how to build the actual texture

    void DEM::TextureFromBuffers(
      TMCArray& r,  TMCArray& g, TMCArray& b)
     TMCCountedPtr channel;
     IShChannelTileIterator* channeliter = NULL;
     const TChannelDataBucket *bucket;
     TMCRect bounds, chunk;
     int32 x, y, height, width,chunkx,chunky, CHUNK_SIZE, sizeH, sizeV;
     MapParams mapparams;
     mapparams.fFlipVert = true;
     mapparams.fFlipHoriz = false;
     mapparams.fBrightness = 1;
     mapparams.fNinetyDegreeCount = 0;
     int32 ColorBinIndex;
     gComponentUtilities->CoCreateInstance(CLSID_TextureMap, NULL, MC_CLSCTX_INPROC_SERVER, IID_IShTextureMap, (void**) &texture;);
     gShell3DUtilities->CreateChannel(&channel;, maxX , maxY, 32);
     TChannelID newChannelID(TChannelID::eARGB_CHANNEL, 1);
     TextureMappingInfo tminfo;
     sizeH = bounds.GetWidth();
     sizeV = bounds.GetHeight();
     tminfo.fIsInternal = true;
     tminfo.fFlip[0] = true;
     tminfo.fFlip[1] = false;
     texture->SetTextureMappingInfo(tminfo); //use the iter to fill the channel
     channel->GetChannelTileIterator(&channeliter;, bounds);
     channeliter->GetTile(&bucket;, eTileRead);
     CHUNK_SIZE = bucket->Width();
     for (chunkx = 0; chunkx < (sizeH + CHUNK_SIZE - 1) / CHUNK_SIZE; chunkx++) {
      for (chunky = 0; chunky < (sizeV + CHUNK_SIZE - 1) / CHUNK_SIZE; chunky++) {
       //set the boundaries for this chunk
       SetChunkSize(chunk,chunkx, chunky, bounds, CHUNK_SIZE);
       channel->GetTile(chunk, &bucket;, eTileReadWrite);
       for (y=0;yRowPtr32(y);
        for (x=0;xSetChannel(channel);


  • SighmanSighman Posts: 55
    edited December 1969

    Thanks again Eric, you are a wonder.

    The secret line I was looking for was

    gComponentUtilities->CoCreateInstance(CLSID_TextureMap, NULL, MC_CLSCTX_INPROC_SERVER, IID_IShTextureMap, (void**) &texture;);

    The rest or your example is an extra + bonus.

    I might actually get this project finished one day ;)


Sign In or Register to comment.