Multitexturing (Image Included)

BlitzMax Forums/BlitzMax Programming/Multitexturing (Image Included)

I posted this a longtime ago, but now Im doing it in Minib3d, but I'm not getting any replies back from that forum so if anyone here could help please..

Sorry image not here anymore :(

http://www.blitzmax.com/Community/posts.php?topic=76409 original post...

Sorry for the double post...

I'm just trying to get some help so if anyone could help please I have been trying to get this figured out for weeks??

I'm trying to get make the texture change with the slops (like rocks on the slops and grass on the flatter areas of the terrain, but someone just please help???

:(

I have no idea about minib3d but here is a post with some good multitexturing links and this contains some BlitzMax code to do it.
They're DX examples and, I think, miniB3D is OGL.

I'm not looking for links, I'm looking for more like a explained way of doing it.. can someone post some more readable code..

DX nor the OGL version will be very readable.

If you missed it.
Function Splat(r_image1:TImage , r_image2:TImage)
  Local frame1:TD3D7ImageFrame=TD3D7ImageFrame(r_image1.frame(0))
  Local frame2:TD3D7ImageFrame=TD3D7ImageFrame(r_image2.frame(0))
	
	D3D7GraphicsDriver().Direct3DDevice7().SetTexture 0,frame1.surface
	gDriver.device.SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	gDriver.device.SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
	gDriver.device.SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
	
	D3D7GraphicsDriver().Direct3DDevice7().SetTexture 1,frame2.surface
	gDriver.device.SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	gDriver.device.SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_MODULATE );
	gDriver.device.SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
	gDriver.device.SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
	
End Function


...and, in D3D7Max2d and GLMax2d, these are the same statements used when the command setblend lightblend/alphablend/shadeblend/maskblend is used.

Okay I don't really understand what you ment by the "these are the same statements used when the command setblend lightblend/alphablend/shadeblend/maskblend is used. " which statements are the same..?

In D3D7Max2D module the setblend method uses the SetTextureStageState commands to change the way textures are drawn. For setblend the commands are used on a single texture : Single texturing. For multitexturing the same commands are used but it takes the result of one texture blend and then applies it to the next texture blend.

In short, for multitexturing, you
a) Take an image
b) Apply a blend type using the colour and alpha arguments you require.
c) Use the result as input to the next stage
d) Apply a blend type using the colour and alpha
arguments you require.
e) Result is a 'blended' texture resulting from multiple textures.
I have commented the following code :
Function Splat(r_image1:TImage , r_image2:TImage)
	' Declare frame1 and frame2 to hold the frame for the images to be used in the multitexture.
	  Local frame1:TD3D7ImageFrame=TD3D7ImageFrame(r_image1.frame(0))
        Local frame2:TD3D7ImageFrame=TD3D7ImageFrame(r_image2.frame(0))
		' We start with the first stage (STAGE 0) of our multitexture operation.
		' Set the texture to be applied to the surface of frame1
 		gDriver.device.SetTexture 0,frame1.surface
		' Input ARG1 for the colour is the texture used in the settexture command,
   		gDriver.device.SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		' For the colour operation use ARG1 (e.g. our texture)
   		gDriver.device.SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
		' Input ARG1 for the alpha is the texture
   		gDriver.device.SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
		' For the alpha operation use ARG1 (e.g. our texture)
  		gDriver.device.SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
		' So far we have done nothing except input our texture without changing it.
		' BUT we have now have it available to be used in our second stage of the multitexture
		' STAGE 1
		' Set the texture to be applied tp the surface of frame2
 		gDriver.device.SetTexture 1 , frame2.surface
		' The *new* texture set in the command above is now set to ARG1 for the colour operation.
   		gDriver.device.SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		' However, we are taking the colour from ARG2
   		gDriver.device.SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_SELECTARG2);
		' ARG2 is set to 'Current' which is the texture resulting from the previous stage.
   		gDriver.device.SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
		' The alpha is taken from ARG1
  		gDriver.device.SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
		' Alpha ARG1 is taken from our texture
 		gDriver.device.SetTextureStageState( 1 , D3DTSS_ALPHAARG1 , D3DTA_TEXTURE ) ; 
		'The result is a single texture blended from 2 images input and saved in the second image.
End Function

Hope it helps but I can't explain it any better than the links I gave.
I found 'Special Effects Game programming with DirectX' and 'Beginning openGL' useful for this sort of thing,.
The MFCTEX, D3DMultex and OGLMulTex are useful to see the results of blend operations and provide the code that just needs a little changing for Bmax use.