From 5d42f27259fb1a497f26eecadb00d3fd7bea28bb Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 15 Nov 2011 12:52:42 +0000 Subject: [PATCH] tutorial: port the Mandelbrot dithering shader to Cg. --- src/platform/sdl/sdlapp.cpp | 2 ++ test/math/remez.cpp | 9 +++++++-- test/tutorial/tut03.cpp | 22 +++++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 02a6867b..9e40cf34 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -75,7 +75,9 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : void SdlApp::ShowPointer(bool show) { +#if defined USE_SDL SDL_ShowCursor(show ? 1 : 0); +#endif } void SdlApp::Run() diff --git a/test/math/remez.cpp b/test/math/remez.cpp index f582245d..c45d2aee 100644 --- a/test/math/remez.cpp +++ b/test/math/remez.cpp @@ -30,20 +30,25 @@ using namespace std; /* The function we want to approximate */ real myfun(real const &y) { +real k1024 = 1024; +real klog32 = log((real)32); +return (y - k1024) / log2(log(sqrt(y))/klog32); real x = sqrt(y); return (sin(x) - x) / (x * y); } real myerr(real const &y) { +return myfun(y); +return real::R_1; real x = sqrt(y); return sin(x) / (x * y); } int main(int argc, char **argv) { - RemezSolver<6> solver; - solver.Run(real::R_1 >> 400, real::R_PI_2 * real::R_PI_2, myfun, myerr, 40); + RemezSolver<3> solver; + solver.Run((real)(1024.001), (real)(1024 * 1024), myfun, myerr, 40); return EXIT_SUCCESS; } diff --git a/test/tutorial/tut03.cpp b/test/tutorial/tut03.cpp index 7049ad7f..5d21eae2 100644 --- a/test/tutorial/tut03.cpp +++ b/test/tutorial/tut03.cpp @@ -110,10 +110,18 @@ public: f64cmplx worldmouse = m_center + ScreenToWorldOffset(mousepos); ivec3 buttons = Input::GetMouseButtons(); +#ifdef __CELLOS_LV2__ + if (true) +#else if ((buttons[0] || buttons[2]) && mousepos.x != -1) +#endif { f64cmplx oldcenter = m_center; double oldradius = m_radius; +#ifdef __CELLOS_LV2__ + m_radius *= pow(2.0, -deltams * 0.00015); + m_center = f64cmplx(0.001643721971153, 0.822467633298876); +#else double zoom = pow(2.0, (buttons[0] ? -deltams : deltams) * 0.0025); if (m_radius * zoom > 8.0) zoom = 8.0 / m_radius; @@ -122,6 +130,7 @@ public: m_radius *= zoom; m_center = (m_center - worldmouse) * zoom + worldmouse; worldmouse = m_center + ScreenToWorldOffset(mousepos); +#endif /* Store the transformation properties to go from m_frame-1 * to m_frame. */ @@ -264,11 +273,18 @@ public: " out_Position = in_Position;" "}", - "void main(float2 in_TexCoord : TEXCOORD0," - " uniform sampler2D tex," + "void main(float4 in_FragCoord : WPOS," + " float2 in_TexCoord : TEXCOORD0," + " uniform sampler2D in_Texture," " out float4 out_FragColor : COLOR)" "{" - " out_FragColor = tex2D(tex, in_TexCoord);" + " float2 coord = in_TexCoord.xy;" + " float i = frac((in_FragCoord.x - 0.5) * 0.5) * 2.0;" + " float j = frac((in_FragCoord.y - 0.5 + i) * 0.5) * 2.0;" + " coord.y += i + j * 2;" + " coord.y *= 0.25;" + " float4 p = tex2D(in_Texture, coord);" + " out_FragColor = p;" "}" #endif );