Game Development Reference
In-Depth Information
bool ContainsPoint( vec2 Point, vec4 Rect )
{
return Point.x >= Rect.x && Point.y >= Rect.y &&
Point.x <= Rect.z && Point.y <= Rect.w;
}
Store some hardcoded values corresponding to the rectangles where our control buttons
are located:
void main()
{
const vec4 MoveLeft = vec4( 0.0, 0.863, 0.32, 1.0 );
const vec4 Down = vec4( 0.32, 0.863, 0.67, 1.0 );
const vec4 MoveRight = vec4( 0.67, 0.863, 1.0, 1.0 );
const vec4 TurnLeft = vec4( 0.0, 0.7, 0.4, 0.863);
const vec4 TurnRight = vec4( 0.6, 0.7, 1.0, 0.863);
const vec4 Reset = vec4( 0.0, 0.0, 0.2, 0.1 );
const vec4 Paused = vec4( 0.8, 0.0, 1.0, 0.1 );
Read the background texture and the highlighted parts. Check the iles back.png , back_
high_bottom.png , and back_high_top.png from the accompanying project:
vec4 Color = texture( Texture0,TexCoord );
vec4 ColorHighT = texture( Texture1,TexCoord*vec2(4.0,8.0) );
vec4 ColorHighB = texture( Texture2,TexCoord*vec2(1.0,2.0) );
Check if buttons are pressed and choose the right texture accordingly:
if ( b_MoveLeft>0.5 &&ContainsPoint(TexCoord.xy, MoveLeft))
Color = ColorHighB;
if ( b_Down> 0.5 && ContainsPoint( TexCoord.xy, Down ) )
Color = ColorHighB;
if ( b_MoveRight>0.5 && ContainsPoint(TexCoord.xy,MoveRight) )
Color = ColorHighB;
if ( b_TurnLeft>0.5 && ContainsPoint(TexCoord.xy, TurnLeft) )
Color = ColorHighB;
if ( b_TurnRight>0.5 && ContainsPoint(TexCoord.xy,TurnRight) )
Color = ColorHighB;
if ( b_Reset> 0.5 && ContainsPoint( TexCoord.xy, Reset) )
Color = ColorHighT;
if ( b_Paused> 0.5 && ContainsPoint( TexCoord.xy, Paused ) )
Color = ColorHighT;
VoilĂ ! We have textured the background with all the buttons in one pass:
out_FragColor = Color;
}
 
Search WWH ::




Custom Search