MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / OnUserUpdate

Method OnUserUpdate

examples/TEST_Shaders.cpp:153–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151 }
152
153 bool OnUserUpdate(float fElapsedTime) override
154 {
155 // Handle Pan & Zoom
156 if (GetMouse(2).bPressed) tv.StartPan(GetMousePos());
157 if (GetMouse(2).bHeld) tv.UpdatePan(GetMousePos());
158 if (GetMouse(2).bReleased) tv.EndPan(GetMousePos());
159 if (GetMouseWheel() > 0) tv.ZoomAtScreenPos(2.0f, GetMousePos());
160 if (GetMouseWheel() < 0) tv.ZoomAtScreenPos(0.5f, GetMousePos());
161
162
163 // Stage 1) Just draw the bouncers normally into the NormalBouncers decal
164 // This uses the "pass-thru" effect, i.e. nothing
165
166 // Set the target decal
167 shader.SetTargetDecal(gfxNormalBouncers.Decal(), 0);
168 // Tell the shading system to use a shader
169 shader.Start(&fxNormal);
170 // Several PGE-like drawing commands are available. Here we clear the decal
171 shader.Clear();
172
173 // Update Locations & Render "Stock" Bouncers
174 for (auto& bouncer : vBouncers)
175 {
176 bouncer.first += bouncer.second * fElapsedTime * 100.0f;
177
178 if (bouncer.first.x < 0.0f)
179 {
180 bouncer.first.x = 0.0f; bouncer.second.x *= -1.0f;
181 }
182 if (bouncer.first.x + gfxTexture2.Sprite()->width > ScreenWidth())
183 {
184 bouncer.first.x = float(ScreenWidth() - gfxTexture2.Sprite()->width); bouncer.second.x *= -1.0f;
185 }
186
187 if (bouncer.first.y < 0.0f)
188 {
189 bouncer.first.y = 0.0f; bouncer.second.y *= -1.0f;
190 }
191 if (bouncer.first.y + gfxTexture2.Sprite()->height > ScreenHeight())
192 {
193 bouncer.first.y = float(ScreenHeight() - gfxTexture2.Sprite()->height); bouncer.second.y *= -1.0f;
194 }
195
196 // Using the transformed view, draw the bouncer using the pass-thru shader
197 tv.DrawDecal(shader, bouncer.first, gfxTexture2.Decal(), { 1.0f, 1.0f }, olc::WHITE);
198 }
199
200 // Stop shading
201 shader.End();
202
203 // Stage 2) A selection of different effects are demonstrated. For each one, we "cut" out of normal bouncers
204 // a small region, then draw it into its own decal just for that effect. The cut is done with DrawPartialDecal()
205
206 shader.SetTargetDecal(gfxEffect1.Decal(), 0);
207 shader.Start(&fxBoxblur);
208 shader.Clear(olc::WHITE);
209 shader.DrawPartialDecal({ 0.0f, 0.0f }, gfxNormalBouncers.Decal(), { 50.0f, 50.0f }, { 200.0f, 200.0f });
210 shader.End();

Callers

nothing calls this directly

Calls 13

DrawDecalFunction · 0.85
StartPanMethod · 0.80
UpdatePanMethod · 0.80
EndPanMethod · 0.80
ZoomAtScreenPosMethod · 0.80
SetTargetDecalMethod · 0.80
DecalMethod · 0.80
EndMethod · 0.80
StartMethod · 0.45
ClearMethod · 0.45
SpriteMethod · 0.45
DrawDecalMethod · 0.45

Tested by

no test coverage detected