Browse Source

tutorial: port the Mandelbrot dithering shader to Cg.

legacy
Sam Hocevar gary 13 years ago
parent
commit
5d42f27259
3 changed files with 28 additions and 5 deletions
  1. +2
    -0
      src/platform/sdl/sdlapp.cpp
  2. +7
    -2
      test/math/remez.cpp
  3. +19
    -3
      test/tutorial/tut03.cpp

+ 2
- 0
src/platform/sdl/sdlapp.cpp View File

@@ -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()


+ 7
- 2
test/math/remez.cpp View File

@@ -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;
}


+ 19
- 3
test/tutorial/tut03.cpp View File

@@ -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
);


Loading…
Cancel
Save