Changeset 1058
- Timestamp:
- Nov 9, 2011, 9:42:53 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/tutorial/tut03.cpp
r1056 r1058 53 53 m_angle += deltams * 0.0005f; 54 54 55 cmplx r0(cosf(m_angle), sinf(m_angle));55 cmplx r0(cosf(m_angle), 0.8f * sinf(m_angle)); 56 56 for (int j = 0; j < m_size.y; j++) 57 57 for (int i = 0; i < m_size.x; i++) 58 58 { 59 float const maxlen = 128.0f; 60 int const maxiter = 20; 61 62 cmplx x0(4.0f / m_size.x * i - 2.5f, 3.0f / m_size.y * j - 1.5f); 63 cmplx r = x0; 59 float const maxlen = 32.0f; 60 int const colors = 16; 61 int const maxiter = 30; 62 63 cmplx x0(4.0f / m_size.x * i - 2.0f, 3.0f / m_size.y * j - 1.5f); 64 cmplx r = x0 * r0; 64 65 cmplx z; 65 66 int iter = maxiter; … … 67 68 --iter; 68 69 69 float f = iter ;70 float f = iter % colors; 70 71 float n = z.len(); 71 72 f += logf(logf(n) / logf(maxlen)) / logf(2.0f); … … 73 74 if (iter) 74 75 { 75 uint8_t red = 255 - f * 11; 76 uint8_t green = 255 - f * 11; 77 uint8_t blue = (f * 23 > 255) ? 511 - f * 23 : 255; 76 uint8_t red = 255 - f * (255.0f / (colors + 1)); 77 uint8_t green = 255 - f * (255.0f / (colors + 1)); 78 uint8_t blue = (f * 512.0f / (colors + 1) > 255) 79 ? 511 - (f * 512.0f / (colors + 1)) : 255; 78 80 m_pixels[j * m_size.x + i] = u8vec4(red, green, blue, 0); 79 81 } … … 115 117 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.x, m_size.y, 0, 116 118 GL_RGBA, GL_UNSIGNED_BYTE, m_pixels); 117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_ NEAREST);118 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_ NEAREST);119 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 119 121 120 122 m_shader = Shader::Create( 123 #if !defined __CELLOS_LV2__ 121 124 "#version 120\n" 122 125 "attribute vec2 in_TexCoord;\n" … … 131 134 "void main(void) {" 132 135 " gl_FragColor = texture2D(in_Texture, gl_TexCoord[0].xy);" 133 "}"); 136 "}" 137 #else 138 "void main(float4 in_Position : POSITION," 139 " float2 in_TexCoord : TEXCOORD0," 140 " out float4 out_Position : POSITION," 141 " out float2 out_TexCoord : TEXCOORD0)" 142 "{" 143 " out_TexCoord = in_TexCoord;" 144 " out_Position = in_Position;" 145 "}", 146 147 "void main(float2 in_TexCoord : TEXCOORD0," 148 " uniform sampler2D tex," 149 " out float4 out_FragColor : COLOR)" 150 "{" 151 " out_FragColor = tex2D(tex, in_TexCoord);" 152 "}" 153 #endif 154 ); 134 155 m_vertexattrib = m_shader->GetAttribLocation("in_Vertex"); 135 156 m_texattrib = m_shader->GetAttribLocation("in_TexCoord"); … … 157 178 glBindTexture(GL_TEXTURE_2D, m_texid); 158 179 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_size.x, m_size.y, 159 GL_RGBA, GL_UNSIGNED_BYTE, m_pixels); 180 #if !defined __CELLOS_LV2__ 181 GL_RGBA, GL_UNSIGNED_BYTE, 182 #else 183 /* The PS3 is big-endian */ 184 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 185 #endif 186 m_pixels); 160 187 161 188 m_shader->Bind(); … … 173 200 //glVertexAttribPointer(m_vertexattrib, 2, GL_FLOAT, GL_FALSE, 0, vertices); 174 201 #else 175 //glEnableClientState(GL_VERTEX_ARRAY);176 //glVertexPointer(2, GL_FLOAT, 0, vertices);177 //glEnableClientState(GL_VERTEX_ARRAY);178 //glTexCoordPointer(2, GL_FLOAT, 0, texcoords);202 glEnableClientState(GL_VERTEX_ARRAY); 203 glVertexPointer(2, GL_FLOAT, 0, vertices); 204 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 205 glTexCoordPointer(2, GL_FLOAT, 0, texcoords); 179 206 #endif 180 207 … … 190 217 //glDisableVertexAttribArray(m_texattrib); 191 218 #else 192 //glDisableClientState(GL_VERTEX_ARRAY);193 //glDisableClientState(GL_TEXTURE_COORD_ARRAY);219 glDisableClientState(GL_VERTEX_ARRAY); 220 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 194 221 #endif 195 222 }
Note: See TracChangeset
for help on using the changeset viewer.