Changes

Jump to: navigation, search

GAM670/DPS905 Weekly Schedule 20121

3,704 bytes added, 20:28, 20 March 2012
This Week
== Week 10 - Mar 18 ==
=== This Week ===
* Texturing - Identification
: connection between Design.cpp and effects.fx
** iTexture.h
:: add texture and texture state identifier
<syntaxhighlight lang="cpp">
iTexture* CreateTexture(const wchar_t* file, const char* str,
const char* isOn);
</syntaxhighlight>
** Texture.h
:
<syntaxhighlight lang="cpp">
Texture(const wchar_t*, const char*, const char*);
</syntaxhighlight>
** Texture.cpp
:
<syntaxhighlight lang="cpp">
// constructor initializes the texture identifier
//
Texture::Texture(const wchar_t* file, const char* str,
const char* isOn) : filter(0u) {
 
if (file) {
int len = strlen(file);
this->file = new wchar_t[len + 1];
strcpy(this->file, file, len);
}
else
this->file = nullptr;
 
tex = nullptr;
#if PIPELINE == FIXED_FUNCTION
#elif PIPELINE == PROGRAMMABLE
#elif PIPELINE == PROGRAMMABLE_EFFECT
textureHandle = effect->GetParameterByName(0, str);
textureonHandle = effect->GetParameterByName(0, isOn);
#endif
}
</syntaxhighlight>
:
<syntaxhighlight lang="cpp">
effect->SetTexture(textureHandle, tex);
effect->SetBool(textureonHandle, true);
</syntaxhighlight>
** iAPITexture.h
:: add texture and texture state identifier
<syntaxhighlight lang="cpp">
iAPITexture* CreateAPITexture(const wchar_t* file, const char* str,
const char* isOn);
</syntaxhighlight>
** APITexture.h
:
<syntaxhighlight lang="cpp">
D3DXHANDLE textureHandle; // points to texture
D3DXHANDLE textureonHandle; // points to texture on status
public:
APITexture(const wchar_t*, const char*, const char*);
</syntaxhighlight>
** APITexture.cpp
:
<syntaxhighlight lang="cpp">
// constructor initializes the texture identifier
//
APITexture::APITexture(const wchar_t* file, const char* str,
const char* isOn, AddressMode m) : filter(0u), mode(m) {
 
if (file) {
int len = strlen(file);
this->file = new wchar_t[len + 1];
strcpy(this->file, file, len);
}
else
this->file = nullptr;
 
tex = nullptr;
target = nullptr;
#if PIPELINE == FIXED_FUNCTION
#elif PIPELINE == PROGRAMMABLE
#elif PIPELINE == PROGRAMMABLE_EFFECT
textureHandle = effect->GetParameterByName(0, str);
textureonHandle = effect->GetParameterByName(0, isOn);
#endif
}
</syntaxhighlight>
:
<syntaxhighlight lang="cpp">
effect->SetTexture(textureHandle, tex);
effect->SetBool(textureonHandle, true);
</syntaxhighlight>
* Texturing - Tiling
:
</syntaxhighlight>
* Texturing - Address Modes
** APITexture.h
:
<syntaxhighlight lang="cpp">
D3DXHANDLE textureMode; // points to texture mode
</syntaxhighlight>
** APITexture.cpp
:
<syntaxhighlight lang="cpp">
effect->SetInt(textureMode, (int)mode);
</syntaxhighlight>
** effects.fx - uniform variables
::
<syntaxhighlight lang="cpp">
// Addressing Modes
#define TEX_WRAP 0
#define TEX_CLAMP 1
#define TEX_MIRROR 2
 
//...
 
bool tex_1_On; // texture switch
int tex_mode; // addressing mode
};
</syntaxhighlight>
** effects.fx - fragment shader
:
<syntaxhighlight lang="cpp">
// sample the texture
//
if (tex_1_On) {
if (tex_mode == TEX_CLAMP)
output *= tex2D(tex_1_cc, input.texCoord);
else if (tex_mode == TEX_WRAP)
output *= tex2D(tex_1_ww, input.texCoord);
else if (tex_mode == TEX_MIRROR)
output *= tex2D(tex_1_mm, input.texCoord);
}
</syntaxhighlight>
* Texturing - Multi-Texturing
** effects.fx - uniform variables
:
<syntaxhighlight lang="cpp">
};
</syntaxhighlight>
** effects.fx - fragment shader
:
<syntaxhighlight lang="cpp">
if (tex_2_On) {
if (tex_mode == TEX_CLAMP)
output *= tex2D(tex_2_cc, input.texCoord);
else if (tex_mode == TEX_WRAP)
output *= tex2D(tex_2_ww, input.texCoord);
else if (tex_mode == TEX_MIRROR)
output *= tex2D(tex_2_mm, input.texCoord);
}
</syntaxhighlight>

Navigation menu