Commits

Eric Fredricksen committed 081a371

Render, in at least some sense, both density and velocity

  • Participants
  • Parent commits 15ba982

Comments (0)

Files changed (2)

File Classes/ES1Renderer.m

         glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
         glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
         glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
-    }
+
+		allocate_data(); 
+		clear_data();
+	}
 
     return self;
 }
 {
     // Replace the implementation of this method to do your own custom drawing
 
+	/*
     static const GLfloat squareVertices[] = {
         -0.5f,  -0.33f,
          0.5f,  -0.33f,
         0,     0,   0,   0,
         255,   0, 255, 255,
     };
+	 */
 
     static float transY = 0.0f;
 

File josstam/demo.c

 
 /* global variables */
 
-static int N;
-static float dt, diff, visc;
-static float force, source;
-static int dvel;
+static int N = 64;
+static float dt = 0.1f;
+static float diff = 0.0f;
+static float visc = 0.0f;
+static float force = 5.0f;
+static float source = 100.0f;
+
+static int dvel = 1;
 
 static float * u, * v, * u_prev, * v_prev;
 static float * dens, * dens_prev;
 
 //static int win_id;
-static int win_x, win_y;
+static int win_x = 512;
+static int win_y = 512;
 static int mouse_down[3];
 static int omx, omy, mx, my;
 
 	if ( dens_prev ) free ( dens_prev );
 }
 
-static void clear_data ( void )
+void clear_data()
 {
 	int i, size=(N+2)*(N+2);
 
 {
 	float h = 1.0f / N;
 
-	glColor4f (1.0f, 1.0f, 1.0f, 1.0f );
-	glLineWidth ( 1.0f );
+	glColor4f(1.0f, 0.5f, 1.0f, 1.0f);
+	glLineWidth(1.0f);
 
 	typedef struct Point2d { GLfloat x, y; } Point2d;
-	Point2d vertices[N*N*2];
+	const int VERTICES = N * N * 2;
+	Point2d vertices[VERTICES];
 	Point2d *vertex = vertices;
 
-	for (int i=1; i<=N; i++) {
+	for (int i = 0; i < N; i++) {
 		float x = (i - 0.5f) * h;
-		for (int j=1; j<=N; j++) {
+		for (int j = 0; j < N; j++) {
 			float y = (j - 0.5f) * h;
 			vertex->x = x;
 			vertex->y = y;
 			++vertex;
-			vertex->x = x + u[IX(i,j)];
-			vertex->y = y + v[IX(i,j)];
+			// TODO: remove the h's!!!!!!!!!!!!!!!!
+			vertex->x = x + h + u[IX(i,j)];
+			vertex->y = y + h + v[IX(i,j)];
 			++vertex;
 		}
 	}
 
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glVertexPointer(2, GL_FLOAT, 0, vertices);
-	glDrawArrays(GL_LINES, 0, N*N);
+	
+	glDrawArrays(GL_LINES, 0, VERTICES);
 }
 
 typedef struct Point2dC { 
-	GLfloat r,g,b, x,y;
+	GLfloat r,g,b,a, x,y;
 } Point2dC;
 
 void set(Point2dC* p, GLfloat c, GLfloat x, GLfloat y) {
-	p->r = p->g = p->b = c; p->x = x; p->y = y;
+	p->r = 0.5f; p->g = p->b = c; p->a = 1.0f; p->x = x; p->y = y;
 }
 
 static void draw_density()
 {
 	const float h = 1.0f / N;
+	const int VERTICES = (N+1) * (N+1) * 6;
 	
-	Point2dC vertices[N * N * 6];
+	Point2dC vertices[VERTICES];
 	Point2dC *vertex = vertices;
 	
 	for (int i = 0; i <= N; i++) {
 		float x = (i - 0.5f) * h;
 		for (int j = 0; j <= N; j++) {
-			float y = (j-0.5f)*h;
+			float y = (j - 0.5f) * h;
 
-			float d00 = dens[IX(i,j)];
-			float d01 = dens[IX(i,j+1)];
+			float d00 = dens[IX(i,  j)];
+			float d01 = dens[IX(i,  j+1)];
 			float d10 = dens[IX(i+1,j)];
 			float d11 = dens[IX(i+1,j+1)];
 
 	}
 
 	glEnableClientState(GL_VERTEX_ARRAY);
+	glVertexPointer(2, GL_FLOAT, sizeof(vertices[0]), &vertices->x);
+	
 	glEnableClientState(GL_COLOR_ARRAY);
-	glVertexPointer(2, GL_FLOAT, &vertices[1].x - &vertices[0].x, &vertices->x);
-	glColorPointer(3, GL_FLOAT, &vertices[1].r - &vertices[0].r, vertices);
-	glDrawArrays(GL_TRIANGLES, 0, N * N);
+	glColorPointer(4, GL_FLOAT, sizeof(vertices[0]), &vertices->r);
+	
+	glDrawArrays(GL_TRIANGLES, 0, VERTICES);
+
 }
 
 /*
 	}
 
 	if ( argc == 1 ) {
-		N = 64;
-		dt = 0.1f;
-		diff = 0.0f;
-		visc = 0.0f;
-		force = 5.0f;
-		source = 100.0f;
 		fprintf ( stderr, "Using defaults : N=%d dt=%g diff=%g visc=%g force = %g source=%g\n",
 			N, dt, diff, visc, force, source );
 	} else {
 	printf ( "\t Clear the simulation by pressing the 'c' key\n" );
 	printf ( "\t Quit by pressing the 'q' key\n" );
 
-	dvel = !0;
-
 	if ( !allocate_data () ) exit ( 1 );
 	clear_data ();
 
-	win_x = 512;
-	win_y = 512;
 	open_glut_window ();
 
 	//glutMainLoop ();