Question about mat_effect

Posted By: Steempipe

Question about mat_effect - 01/18/16 02:35

Hi,

If I use this code, I get the anticipated results, a texture tiled 2x:

Code:
function mtlEffect_init()

{

      
   float rotation_matrix[16] =
		{ 1.0, 0.0, 0.0, 0.0,
		  0.0, 1.0,	0.0, 0.0,
		  0.0, 0.0, 1.0, 0.0,
		  0.0, 0.0, 0.0, 1.0 };
		  
	
	float temp_matrix[16] =
		{ 1.0, 0.0, 0.0, 0.0,
		  0.0, 1.0,	0.0, 0.0,
		  0.0, 0.0, 1.0, 0.0,
		  0.0, 0.0, 0.0, 1.0 };	  
		  
			
	// scale the texture
	rotation_matrix[0] = 2;
	rotation_matrix[5] = 2;
	
	mat_set(temp_matrix, rotation_matrix);
	
	mat_effect1 = temp_matrix; 
	 
}





But if I use this code I don't. Am I misinterpreting the usage from the manual?

Code:
function mtlEffect_init()

{

      
   float rotation_matrix[16] =
		{ 1.0, 0.0, 0.0, 0.0,
		  0.0, 1.0,	0.0, 0.0,
		  0.0, 0.0, 1.0, 0.0,
		  0.0, 0.0, 0.0, 1.0 };
		  
	
	float temp_matrix[16];	  
		  
			
	// scale the texture
	rotation_matrix[0] = 2;
	rotation_matrix[5] = 2;
	
	mat_set(temp_matrix, rotation_matrix);
	
	mat_effect1 = temp_matrix; 
	 
}





And even if I do this I get the results like the second image:

Code:
function mtlEffect_init()

{

      
   float rotation_matrix[16];
		  
	mat_identity(rotation_matrix);
			
	// scale the texture
	rotation_matrix[0] = 2;
	rotation_matrix[5] = 2;
	
	mat_effect1 = rotation_matrix; 
	 
}



I'm wondering why, but its not clear in the manual.

Thanks for any clarification.
Posted By: jcl

Re: Question about mat_effect - 01/18/16 11:10

An effect matrix, just as any other variable or object, can only work as long as it is not deleted or overwritten. Your matrices are fine inside your functions, but just garbage outside. When you want a variable to survive the return of the function, you must declare it global or static.
Posted By: Steempipe

Re: Question about mat_effect - 01/19/16 12:30

Thanks for the lesson. It works great.
© 2024 lite-C Forums