Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Marc aka Foddex

Clamping textures?

This topic is 5130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[I use DirectX7] Hi all, For the skybox in my engine, I need to clamp certain textures (in stead of repeating them). In OpenGL (once again my reference) this is very easy: - enable clamping - load texture
glBindTexture(GL_TEXTURE_2D, s->id);
if (options.clamp) {
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
} else {
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
if (s->mipmapped) {
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	gluBuild2DMipmaps(GL_TEXTURE_2D, count, s->width, s->height, type, GL_UNSIGNED_BYTE, data);
} else {
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, count, s->width, s->height, 0, type, GL_UNSIGNED_BYTE, data);
}
OpenGL remembers for a specific texture that it needs clamping or not. But with Direct3D, I can't get it to work. I tried this:
/** set clamping options */
m_d3ddevice->SetRenderState(D3DRENDERSTATE_WRAP0, options.clamp ? D3DWRAPCOORD_0 | D3DWRAPCOORD_1 : 0);

/** create texture in Direct3D */
HRESULT hr;
if (hr = D3DXCreateTexture(m_d3ddevice, &flags, &w, &h, &f, NULL, &tex, options.mipmapped ? &mipmapcount : NULL)<S_OK) {
	ENGINE_LOG(("createtexture: D3DXCreateTexture failed with error code: %d", hr));
	return 0;
}
But this doesn't work. It doesn't remember that the created texture needs clamping or not. Now I *guess* that I would have to enable and disable clamping at runtime, in stead of at loadtime (as is possible with OpenGL), right? Or is it possible to set this option for a texture somehow? Thanks a lot! Marc [edited by - Marc aka Foddex on May 10, 2004 7:32:47 AM]

Share this post


Link to post
Share on other sites
Advertisement
Hi, yes you need to set it just before rendering your skbox and set it back to a default afterward. SetRenderState changes the state the d3d renderer is in there is no way to link it to a texture.

Share this post


Link to post
Share on other sites
As mentioned, it''s not stored per texture, and must be set, if wanted, before any draw call that expects to use clamped coordinates. You must turn it back to wrap mode when you want wrapping coordinates.

D3DRS_WRAP0, if I remember correctly, just enable/disable a secondary form a wrapping, taking the shortest path (ie: 0.2, 1.1 will wrap backwards by 0.1 instead of forwards by 0.9).

I think what you really want are the texture addressing modes, which in DX8 are part of the TextureStageStates, and in DX9 are part of the sampler states.

pDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP)
pDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP)

or

pDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP)
pDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP)

Share this post


Link to post
Share on other sites
Do not confuse mapping warping and address wraping.

To clamp a texture, what you need to do is use the D3DTSS_ADDRESSU and D3DTSS_ADDRESSV. Set them to D3DTADDRESS_CLAMP or D3DTADDRESS_WRAP.

The stuff you made is to change mapping warping, which may resolve another nasty issue in your skybox, but not the same.

While you may need both for your skybox to work correctly, the two are totally different things.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!