CG中指定纹理的两种方法

来源:互联网 发布:激光器的软件 编辑:程序博客网 时间:2024/05/18 21:09

方法一:使用Opengl的多重纹理以及CG的semantics


// In C++ File:

   // Identify the textures to use for the pixel shader...
    cgGLSetTextureParameter( g_CGparam_testTexture, g_testTextureID );
    cgGLSetTextureParameter( g_CGparam_checkerTexture, g_checkerTextureID );

    // STAGE 0
    glActiveTextureARB( GL_TEXTURE0_ARB );
    glBindTexture( GL_TEXTURE_2D, g_testTextureID );

    // STAGE 1
    glActiveTextureARB( GL_TEXTURE1_ARB );
    glBindTexture( GL_TEXTURE_2D, g_checkerTextureID );

   cgGLBindProgram( g_CGprogram_pixel );
   cgGLEnableProfile( g_CGprofile_pixel );

   // Draw primitives

   cgGLDisableProfile( g_CGprofile_pixel );

// In Cg File:

   uniform sampler2D testTexture    : TEXUNIT0,
   uniform sampler2D checkerTexture : TEXUNIT1

 

 

方法二:使用CG的纹理函数cgGLSetTextureParameter, cgGLEnableTextureParameter,  cgGLDisableTextureParameter

 


g_CGparam_testTexture    = cgGetNamedParameter(g_CGprogram_pixel, "testTexture");
    g_CGparam_checkerTexture = cgGetNamedParameter(g_CGprogram_pixel, "checkerTexture");

    // Identify the textures to use for the pixel shader...
    cgGLSetTextureParameter( g_CGparam_testTexture, g_testTextureID );
    cgGLSetTextureParameter( g_CGparam_checkerTexture, g_checkerTextureID );

    cgGLBindProgram( g_CGprogram_pixel );
    cgGLEnableProfile( g_CGprofile_pixel );

    cgGLEnableTextureParameter( g_CGparam_testTexture );
    cgGLEnableTextureParameter( g_CGparam_checkerTexture );

    // Draw primitives

    cgGLDisableTextureParameter( g_CGparam_checkerTexture );
    cgGLDisableTextureParameter( g_CGparam_testTexture );

    cgGLDisableProfile( g_CGprofile_pixel );

// In Cg File:

    uniform sampler2D testTexture,

    uniform sampler2D checkerTexture

 


最近在绘制程序中用到了这两种纹理制定方法,由于一直没理清头绪,遇到很多麻烦

在我程序中,两种方法不可以混用,否则会出现纹理混淆的状况,即你指定了纹理1,实际上在cg中得到的是纹理2

方法一似乎更稳定些,但具体这两种方法各有什么优势和限制还不得而知,这方面的资料也实在很少,看来需要更多的积累

 

原文:http://dev.21tx.com/2005/09/22/15665.html


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/rainbowx/archive/2008/10/16/3086192.aspx

原创粉丝点击