| @@ -52,29 +52,31 @@ public: | |||
| m_angle += deltams * 0.0005f; | |||
| cmplx r0(cosf(m_angle), sinf(m_angle)); | |||
| cmplx r0(cosf(m_angle), 0.8f * sinf(m_angle)); | |||
| for (int j = 0; j < m_size.y; j++) | |||
| for (int i = 0; i < m_size.x; i++) | |||
| { | |||
| float const maxlen = 128.0f; | |||
| int const maxiter = 20; | |||
| float const maxlen = 32.0f; | |||
| int const colors = 16; | |||
| int const maxiter = 30; | |||
| cmplx x0(4.0f / m_size.x * i - 2.5f, 3.0f / m_size.y * j - 1.5f); | |||
| cmplx r = x0; | |||
| cmplx x0(4.0f / m_size.x * i - 2.0f, 3.0f / m_size.y * j - 1.5f); | |||
| cmplx r = x0 * r0; | |||
| cmplx z; | |||
| int iter = maxiter; | |||
| for (z = r; iter && z.sqlen() < maxlen * maxlen; z = z * z + r) | |||
| --iter; | |||
| float f = iter; | |||
| float f = iter % colors; | |||
| float n = z.len(); | |||
| f += logf(logf(n) / logf(maxlen)) / logf(2.0f); | |||
| if (iter) | |||
| { | |||
| uint8_t red = 255 - f * 11; | |||
| uint8_t green = 255 - f * 11; | |||
| uint8_t blue = (f * 23 > 255) ? 511 - f * 23 : 255; | |||
| uint8_t red = 255 - f * (255.0f / (colors + 1)); | |||
| uint8_t green = 255 - f * (255.0f / (colors + 1)); | |||
| uint8_t blue = (f * 512.0f / (colors + 1) > 255) | |||
| ? 511 - (f * 512.0f / (colors + 1)) : 255; | |||
| m_pixels[j * m_size.x + i] = u8vec4(red, green, blue, 0); | |||
| } | |||
| else | |||
| @@ -114,10 +116,11 @@ public: | |||
| glBindTexture(GL_TEXTURE_2D, m_texid); | |||
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.x, m_size.y, 0, | |||
| GL_RGBA, GL_UNSIGNED_BYTE, m_pixels); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |||
| m_shader = Shader::Create( | |||
| #if !defined __CELLOS_LV2__ | |||
| "#version 120\n" | |||
| "attribute vec2 in_TexCoord;\n" | |||
| "attribute vec2 in_Vertex;" | |||
| @@ -130,7 +133,25 @@ public: | |||
| "uniform sampler2D in_Texture;\n" | |||
| "void main(void) {" | |||
| " gl_FragColor = texture2D(in_Texture, gl_TexCoord[0].xy);" | |||
| "}"); | |||
| "}" | |||
| #else | |||
| "void main(float4 in_Position : POSITION," | |||
| " float2 in_TexCoord : TEXCOORD0," | |||
| " out float4 out_Position : POSITION," | |||
| " out float2 out_TexCoord : TEXCOORD0)" | |||
| "{" | |||
| " out_TexCoord = in_TexCoord;" | |||
| " out_Position = in_Position;" | |||
| "}", | |||
| "void main(float2 in_TexCoord : TEXCOORD0," | |||
| " uniform sampler2D tex," | |||
| " out float4 out_FragColor : COLOR)" | |||
| "{" | |||
| " out_FragColor = tex2D(tex, in_TexCoord);" | |||
| "}" | |||
| #endif | |||
| ); | |||
| m_vertexattrib = m_shader->GetAttribLocation("in_Vertex"); | |||
| m_texattrib = m_shader->GetAttribLocation("in_TexCoord"); | |||
| m_ready = true; | |||
| @@ -156,7 +177,13 @@ public: | |||
| glEnable(GL_TEXTURE_2D); | |||
| glBindTexture(GL_TEXTURE_2D, m_texid); | |||
| glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_size.x, m_size.y, | |||
| GL_RGBA, GL_UNSIGNED_BYTE, m_pixels); | |||
| #if !defined __CELLOS_LV2__ | |||
| GL_RGBA, GL_UNSIGNED_BYTE, | |||
| #else | |||
| /* The PS3 is big-endian */ | |||
| GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, | |||
| #endif | |||
| m_pixels); | |||
| m_shader->Bind(); | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| @@ -172,10 +199,10 @@ public: | |||
| //glEnableVertexAttribArray(m_vertexattrib); | |||
| //glVertexAttribPointer(m_vertexattrib, 2, GL_FLOAT, GL_FALSE, 0, vertices); | |||
| #else | |||
| //glEnableClientState(GL_VERTEX_ARRAY); | |||
| //glVertexPointer(2, GL_FLOAT, 0, vertices); | |||
| //glEnableClientState(GL_VERTEX_ARRAY); | |||
| //glTexCoordPointer(2, GL_FLOAT, 0, texcoords); | |||
| glEnableClientState(GL_VERTEX_ARRAY); | |||
| glVertexPointer(2, GL_FLOAT, 0, vertices); | |||
| glEnableClientState(GL_TEXTURE_COORD_ARRAY); | |||
| glTexCoordPointer(2, GL_FLOAT, 0, texcoords); | |||
| #endif | |||
| glDrawArrays(GL_TRIANGLES, 0, 6); | |||
| @@ -189,8 +216,8 @@ public: | |||
| //glDisableVertexAttribArray(m_vertexattrib); | |||
| //glDisableVertexAttribArray(m_texattrib); | |||
| #else | |||
| //glDisableClientState(GL_VERTEX_ARRAY); | |||
| //glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||
| glDisableClientState(GL_VERTEX_ARRAY); | |||
| glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||
| #endif | |||
| } | |||