Changeset 1062
- Timestamp:
- Nov 12, 2011, 1:15:41 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/tutorial/tut03.cpp
r1061 r1062 38 38 m_size = size; 39 39 m_pixels = new u8vec4[size.x * size.y]; 40 m_frame = 0;40 m_frame = -1; 41 41 m_center = 0; 42 m_target = f64cmplx(0.001643721971153, 0.822467633298876); 42 //m_target = f64cmplx(0.001643721971153, 0.822467633298876); 43 m_target = f64cmplx(-1.207205434596, 0.315432814901); 44 //m_target = f64cmplx(-0.79192956889854, -0.14632423080102); 45 //m_target = f64cmplx(0.3245046418497685, 0.04855101129280834); 43 46 //m_target = f64cmplx(0.28693186889504513, 0.014286693904085048); 47 m_angle = 0.0; 44 48 m_radius = 8.0; 45 49 m_ready = false; … … 57 61 m_frame = (m_frame + 1) % 4; 58 62 59 double zoom = pow(2.0, -deltams * 0.000 15);63 double zoom = pow(2.0, -deltams * 0.0005); 60 64 m_radius *= zoom; 61 65 m_center = (m_center - m_target) * zoom * zoom + m_target; 62 66 63 67 double step = m_radius / (m_size.x > m_size.y ? m_size.x : m_size.y); 64 65 for (int j = m_frame / 2; j < m_size.y; j += 2) 66 //for (int j = ((m_frame + 1) % 4) / 2; j < m_size.y; j += 2) 68 // m_angle -= deltams * 0.00015; 69 f64cmplx transform = step * f64cmplx(cos(m_angle), sin(m_angle)); 70 71 u8vec4 *m_pixelstart = m_pixels + m_size.x * m_size.y / 4 * m_frame; 72 73 for (int j = ((m_frame + 1) % 4) / 2; j < m_size.y; j += 2) 67 74 for (int i = m_frame % 2; i < m_size.x; i += 2) 68 75 { … … 72 79 f64cmplx delta(i - m_size.x / 2, j - m_size.y / 2); 73 80 74 f64cmplx z0 = m_center + step* delta;81 f64cmplx z0 = m_center + transform * delta; 75 82 f64cmplx r0 = z0; 76 83 //f64cmplx r0(0.28693186889504513, 0.014286693904085048); … … 99 106 uint8_t green = g * 255.0f; 100 107 uint8_t blue = b * 255.0f; 101 m_pixels[j * m_size.x + i]= u8vec4(red, green, blue, 0);108 *m_pixelstart++ = u8vec4(red, green, blue, 0); 102 109 } 103 110 else 104 111 { 105 m_pixels[j * m_size.x + i]= u8vec4(0, 0, 0, 0);112 *m_pixelstart++ = u8vec4(0, 0, 0, 0); 106 113 } 107 114 } … … 134 141 if (!m_ready) 135 142 { 143 /* Create a texture of half the width and twice the height 144 * so that we can upload four different subimages each frame. */ 136 145 glGenTextures(1, &m_texid); 137 146 glBindTexture(GL_TEXTURE_2D, m_texid); 138 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.x , m_size.y, 0,139 GL_RGBA, GL_UNSIGNED_BYTE, m_pixels);147 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.x / 2, m_size.y * 2, 148 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pixels); 140 149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 141 150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); … … 155 164 "void main(void) {" 156 165 " vec2 coord = gl_TexCoord[0].xy;" 157 " gl_FragColor = texture2D(in_Texture, coord);" 166 /* gl_FragCoord is centered inside the pixel, so we remove 167 * 0.5 from gl_FragCoord.x. Also, (0,0) is at the bottom 168 * left whereas our images have (0,0) at the top left, so we 169 * _add_ 0.5 to gl_FragCoord.y. */ 170 " float i = mod(gl_FragCoord.x - 0.5, 2.0);" 171 " float j = mod(gl_FragCoord.y + 0.5 + i, 2.0);" 172 " coord.y += i + j * 2;" 173 " coord.y *= 0.25;" 174 " vec4 p = texture2D(in_Texture, coord);" 175 " gl_FragColor = p;" 158 176 "}" 159 177 #else … … 199 217 glEnable(GL_TEXTURE_2D); 200 218 glBindTexture(GL_TEXTURE_2D, m_texid); 201 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_size.x, m_size.y, 219 glTexSubImage2D(GL_TEXTURE_2D, 0, 220 0, m_frame * m_size.y / 2, m_size.x / 2, m_size.y / 2, 202 221 #if !defined __CELLOS_LV2__ 203 222 GL_RGBA, GL_UNSIGNED_BYTE, … … 206 225 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 207 226 #endif 208 m_pixels );227 m_pixels + m_size.x * m_size.y / 4 * m_frame); 209 228 210 229 m_shader->Bind(); … … 258 277 259 278 f64cmplx m_center, m_target; 260 double m_radius ;279 double m_radius, m_angle; 261 280 }; 262 281 … … 271 290 new DebugFps(5, 5); 272 291 new Fractal(ivec2(640, 480)); 292 //new DebugRecord("fractalol.ogm", 60.0f); 273 293 274 294 app.Run();
Note: See TracChangeset
for help on using the changeset viewer.