@@ -35,8 +35,10 @@ int main(void)
35
35
{
36
36
// Initialization
37
37
//--------------------------------------------------------------------------------------
38
- const int screenWidth = 800 ;
39
- const int screenHeight = 450 ;
38
+ int screenWidth = 800 ;
39
+ int screenHeight = 450 ;
40
+ float swirlSize [2 ] = { (float )screenWidth , (float )screenHeight };
41
+ float swirlCenter [2 ] = { (float )screenWidth /2 , (float )screenHeight /2 };
40
42
41
43
SetConfigFlags (FLAG_MSAA_4X_HINT ); // Enable Multi Sampling Anti Aliasing 4x (if available)
42
44
@@ -62,28 +64,36 @@ int main(void)
62
64
63
65
// Get variable (uniform) location on the shader to connect with the program
64
66
// NOTE: If uniform variable could not be found in the shader, function returns -1
67
+ int swirlSizeLoc = GetShaderLocation (shader , "size" );
65
68
int swirlCenterLoc = GetShaderLocation (shader , "center" );
66
69
67
- float swirlCenter [2 ] = { (float )screenWidth /2 , (float )screenHeight /2 };
68
-
69
70
// Create a RenderTexture2D to be used for render to texture
70
- RenderTexture2D target = LoadRenderTexture ( screenWidth , screenHeight ) ;
71
+ RenderTexture2D target ;
71
72
72
73
SetTargetFPS (60 ); // Set our game to run at 60 frames-per-second
73
74
//--------------------------------------------------------------------------------------
74
75
75
76
// Main game loop
76
77
while (!WindowShouldClose ()) // Detect window close button or ESC key
77
78
{
79
+ screenWidth = GetScreenWidth ();
80
+ screenHeight = GetScreenHeight ();
81
+ // Create a RenderTexture2D to be used for render to texture
82
+ UnloadRenderTexture (target );
83
+ target = LoadRenderTexture (screenWidth , screenHeight );
84
+
78
85
// Update
79
86
//----------------------------------------------------------------------------------
80
87
UpdateCamera (& camera , CAMERA_ORBITAL );
81
88
82
89
Vector2 mousePosition = GetMousePosition ();
83
90
91
+ swirlSize [0 ] = screenWidth ;
92
+ swirlSize [1 ] = screenHeight ;
93
+ SetShaderValue (shader , swirlSizeLoc , swirlSize , SHADER_UNIFORM_VEC2 );
94
+
84
95
swirlCenter [0 ] = mousePosition .x ;
85
96
swirlCenter [1 ] = screenHeight - mousePosition .y ;
86
-
87
97
// Send new value to the shader to be used on drawing
88
98
SetShaderValue (shader , swirlCenterLoc , swirlCenter , SHADER_UNIFORM_VEC2 );
89
99
//----------------------------------------------------------------------------------
@@ -98,7 +108,7 @@ int main(void)
98
108
DrawGrid (10 , 1.0f ); // Draw a grid
99
109
EndMode3D (); // End 3d mode drawing, returns to orthographic 2d mode
100
110
101
- DrawText ("TEXT DRAWN IN RENDER TEXTURE" , 200 , 10 , 30 , RED );
111
+ DrawText ("TEXT DRAWN IN RENDER TEXTURE" , screenWidth - 600 , 10 , 30 , RED );
102
112
EndTextureMode (); // End drawing to texture (now we have a texture available for next passes)
103
113
104
114
BeginDrawing ();
@@ -107,7 +117,7 @@ int main(void)
107
117
// Enable shader using the custom uniform
108
118
BeginShaderMode (shader );
109
119
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
110
- DrawTextureRec (target .texture , (Rectangle ){ 0 , 0 , (float )target . texture . width , (float )- target . texture . height }, (Vector2 ){ 0 , 0 }, WHITE );
120
+ DrawTextureRec (target .texture , (Rectangle ){ 0 , 0 , (float )screenWidth , (float )- screenHeight }, (Vector2 ){ 0 , 0 }, WHITE );
111
121
EndShaderMode ();
112
122
113
123
// Draw some 2d text over drawn texture
@@ -128,4 +138,4 @@ int main(void)
128
138
//--------------------------------------------------------------------------------------
129
139
130
140
return 0 ;
131
- }
141
+ }
0 commit comments