Ejemplo n.º 1
0
// a function to draw a smiley face
void draw_smiley (void){

	int num = 0;
	while(checkNoBtns()) 
	{
		TMRSRVC_delay(100);
		LCD_clear();

		if (num % 2==0)
		{
			draw_face();
			draw_smile();
			TMRSRVC_delay(2000);
		}
		else
		{
			draw_face();
			draw_frown();
			TMRSRVC_delay(2000);
		}

		num++;

		for(unsigned char row = 0; row < LCD_PIX_HEIGHT; row++)
		{
			for( unsigned char col = 0; col < LCD_PIX_WIDTH; col++ )
			{
				LCD_set_pixel(row, col, 0);
			}
		}
	}
}
Ejemplo n.º 2
0
int BC_Toggle::initialize()
{
// Get the image
	set_images(data);
	calculate_extents(this,
		data,
		bottom_justify,
		&text_line,
		&w,
		&h,
		&toggle_x,
		&toggle_y,
		&text_x, 
		&text_y,
		&text_w,
		&text_h, 
		has_caption() ? caption : 0);

// Create the subwindow
	BC_SubWindow::initialize();
	set_cursor(UPRIGHT_ARROW_CURSOR);
// Display the bitmap
	draw_face();
	return 0;
}
Ejemplo n.º 3
0
void Walls::draw()
{
    glPushMatrix();
    this->ctm_multiply();
	glScalef(s, s, s);
	glColor3f(color[0], color[1], color[2]);
    for (int i = 0; i < 6; i++) {
    	//if (i == 6)
    	//	glColor3f(1,1,1);
        draw_face(i);
    }
    glPopMatrix();
}
Ejemplo n.º 4
0
static void
draw_faces (ModeInfo *mi)
{
  glPushMatrix();
  draw_face (mi);
  glRotatef (90,  0, 1, 0); draw_face (mi);
  glRotatef (90,  0, 1, 0); draw_face (mi);
  glRotatef (90,  0, 1, 0); draw_face (mi);
  glRotatef (90,  1, 0, 0); draw_face (mi);
  glRotatef (180, 1, 0, 0); draw_face (mi);
  glPopMatrix();
}
static void
draw_cube(int x, int y, int level, int cube_layer)
{
	glTexParameteri(target, GL_TEXTURE_MIN_LOD, level);
	glTexParameteri(target, GL_TEXTURE_MAX_LOD, level);

	draw_face(FACE(POSITIVE_X), cube_layer, x,		y+DRAW_SIZE);
	draw_face(FACE(POSITIVE_Y), cube_layer, x+DRAW_SIZE,	y+DRAW_SIZE);
	draw_face(FACE(NEGATIVE_X), cube_layer, x+DRAW_SIZE*2,	y+DRAW_SIZE);
	draw_face(FACE(NEGATIVE_Y), cube_layer, x+DRAW_SIZE*3,	y+DRAW_SIZE);
	draw_face(FACE(POSITIVE_Z), cube_layer, x+DRAW_SIZE,	y+DRAW_SIZE*2);
	draw_face(FACE(NEGATIVE_Z), cube_layer, x+DRAW_SIZE,	y);
}
Ejemplo n.º 6
0
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	int face, dim;
	GLuint tex;

	glClearColor(0.5, 0.5, 0.5, 0.5);
	glClear(GL_COLOR_BUFFER_BIT);

	tex = create_cube_fbo();

	for (face = 0; face < 6; face++) {
		int x = 1 + face * (BUF_WIDTH + 1);
		int y = 1;

		for (dim = BUF_WIDTH; dim > 0; dim /= 2) {
			draw_face(x, y, dim, face);
			y += dim + 1;
		}
	}

	for (face = 0; face < 6; face++) {
		int x = 1 + face * (BUF_WIDTH + 1);
		int y = 1;
		int level = 0;

		for (dim = BUF_WIDTH; dim > 2; dim >>= 1) {
			pass &= test_face_drawing(x, y, dim,
						  get_face_color(face, level));
			y += dim + 1;
			level++;
		}
	}

	glDeleteTextures(1, &tex);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Ejemplo n.º 7
0
void
draw_scene(void)
{
  if (point_general->changement) {
    recalc_perspective();
    if (point_general->effect > EFFECT_NUMBER - 1) {
      point_general->effect = 0;
      if (gen_gl_texture(knotbg))
        upload_gl_texture(background_image);
      use_gl_texture(knotbg);
    }
    if (point_general->effect == 4) {
      if (gen_gl_texture(tunnel))
        upload_gl_texture(tunnel_image);
      use_gl_texture(tunnel);
    }
    if (point_general->effect == 5) {
      if (gen_gl_texture(tentacle))
        upload_gl_texture(tentacle_image);
      use_gl_texture(tentacle);
    }
    if (point_general->effect == 6) {
      if (gen_gl_texture(twist))
        upload_gl_texture(twist_image);
      if (gen_gl_texture(twistbg))
		upload_gl_texture(background_image);
      use_gl_texture(twist);
    }
    if (point_general->effect == 7) {
      if (gen_gl_texture(texchild))
        upload_gl_texture(child_image);
      if (gen_gl_texture(childbg))
        upload_gl_texture(energy_image);
      use_gl_texture(texchild);
    }
    if (point_general->effect == 8) {
      if (gen_gl_texture(energy))
        upload_gl_texture(energy_image);
      use_gl_texture(energy);
    }
    point_general->changement = FALSE;
  }
  switch (point_general->effect) {
    case 0:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_knot();
      break;
    case 1:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_spectrum();
      break;
    case 2:
      if (!point_general->init)
        init_effect();
      glEnable(GL_LIGHTING);
      draw_face();
      break;
    case 3:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_glthreads();
      break;
    case 4:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_tunnel();
      break;
    case 5:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_tentacles();
      break;
    case 6:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_twist();
      break;
    case 7:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_child();
      break;
    case 8:
      if (!point_general->init)
        init_effect();
      glDisable(GL_LIGHTING);
      draw_energy();
      break;
    default:
      break;
  }
}
Ejemplo n.º 8
0
void game_render(Game* game){
	game->render(game);
	int time_render_begin = SDL_GetTicks();
	
	//RENDER AN INVISIBLE PLANE FOR GROUND DEPTH
	glPushMatrix();
		glTranslated(-game->player->x,-game->player->y,0);
		glTranslated(0,0,-4);
		glRotated(90,0,1,0);
		glColor4d(0,0,0,0);
		draw_face(600,0);
	glPopMatrix();
	GLfloat bkColor[3];
	glGetFloatv(GL_COLOR_CLEAR_VALUE, bkColor);

	//=======================LOOP TEST=========================
	//=======================LOOP TEST=========================
	//=======================LOOP TEST=========================
	// glPushMatrix();
	// 	glTranslated(-game->player->x,-game->player->y,-4);
	// 	glRotated(90,0,1,0);
	// 	glScaled(1,game->world_y_size,game->world_x_size);
	// 	glLineWidth(5);
	// 	glColor4d(0,0,1,1);
	// 	draw_square(.5,0);
	// glPopMatrix();


	Arrow* arrow;
	Mechant* mechant;

	//REFLEXIONS
	glDepthFunc(GL_GREATER);
	glDepthMask(GL_FALSE);
	glPushMatrix();
		//TO THE GROUND
		glTranslated(0,0,-8);


		//=======================ARROWS=======================
		//=======================ARROWS=======================
		//=======================ARROWS=======================
		if(game->sorting){
			game_sort_arrow_distance(game);
		}
		double r_color=.5+.5*bkColor[0];
		double g_color=0+.5*bkColor[1];
		double b_color=0+.5*bkColor[2];
		if(game->stereo){
			r_color=.35+.5*bkColor[0];
			g_color=.1+.5*bkColor[1];
			b_color=.1+.5*bkColor[2];

		}

		glColor4d(r_color,g_color,b_color,1);
		arrow=game->arrows;
		void (*draw_arrow)(Arrow * arrow, Game* game);
		if(game->color_debug){
			draw_arrow=game_render_one_arrow_color;
		}else{
			draw_arrow=game_render_one_arrow;
		}
		int i=0;
		// double last_rendered_total_arrow_copy=last_rendered_total_arrow;
		// last_rendered_total_arrow=0;
		while(arrow!=NULL){
			// glColor4d(r_color,g_color,b_color,1-i/last_rendered_total_arrow_copy);
			// i++;
			
			double xx=arrow->x+game->player->x;
			double yy=arrow->y+game->player->y;
			double zz=arrow->z+game->player->z;
			arrow->dist=xx*xx+yy*yy+zz*zz;

			if(arrow->dist<90000){
				// glDepthFunc(GL_ALWAYS);//debug
				glPushMatrix();
					glTranslated(arrow->x,arrow->y,-arrow->z);
					glScaled(1,1,-1);
					draw_arrow(arrow,game);
				glPopMatrix();
			}
			arrow=arrow->next;
		}
		arrow_high_quality_count=ARROW_MAX_HIGH_QUALITY;
		arrow_low_quality_count=ARROW_MAX_LOW_QUALITY;
		arrow_count=ARROW_MAX;
		//======================MECHANTS======================
		//======================MECHANTS======================
		//======================MECHANTS======================
		mechant=game->mechants;
		while(mechant!=NULL){
			// WORLD LOOP
			while(mechant->x+game->player->x+game->world_x_size/2.>0)
				mechant->x-=game->world_x_size;
			while(mechant->x+game->player->x+game->world_x_size/2.<0)
				mechant->x+=game->world_x_size;
			while(mechant->y+game->player->y+game->world_y_size/2.>0)
				mechant->y-=game->world_y_size;
			while(mechant->y+game->player->y+game->world_y_size/2.<0)
				mechant->y+=game->world_y_size;

			double xx=mechant->x+game->player->x;
			double yy=mechant->y+game->player->y;
			double zz=mechant->z+game->player->z;
			mechant->dist=xx*xx+yy*yy+zz*zz;

			glPushMatrix();
				glScaled(1,1,-1);
				glTranslated(mechant->x,mechant->y,mechant->z+1);
				game_render_one_mechant(mechant,game,r_color,g_color,b_color,1);
			glPopMatrix();

			mechant=mechant->next;
		}

	glPopMatrix();
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LESS);




	//REAL WORLD
	r_color=1;
	g_color=0;
	b_color=0;
	if(game->stereo){
		r_color=.7;
		g_color=.2;
		b_color=.2;
	}
	glColor4d(r_color,g_color,b_color,1);
	arrow=game->arrows;
	// i=0;
	while(arrow!=NULL){
		if(arrow->dist<90000){
			// glColor4d(r_color,g_color,b_color,1-i/last_rendered_total_arrow_copy);
			// i++;
			glPushMatrix();
				glTranslated(arrow->x,arrow->y,arrow->z);
				draw_arrow(arrow,game);
			glPopMatrix();
		}
		arrow=arrow->next;
	}
	arrow_high_quality_count=ARROW_MAX_HIGH_QUALITY;
	arrow_low_quality_count=ARROW_MAX_LOW_QUALITY;
	arrow_count=ARROW_MAX;
	//======================MECHANTS======================
	//======================MECHANTS======================
	//======================MECHANTS======================
	mechant=game->mechants;
	while(mechant!=NULL){
		// WORLD LOOP
		while(mechant->x+game->player->x+game->world_x_size/2.>0)
			mechant->x-=game->world_x_size;
		while(mechant->x+game->player->x+game->world_x_size/2.<0)
			mechant->x+=game->world_x_size;
		while(mechant->y+game->player->y+game->world_y_size/2.>0)
			mechant->y-=game->world_y_size;
		while(mechant->y+game->player->y+game->world_y_size/2.<0)
			mechant->y+=game->world_y_size;

		double xx=mechant->x+game->player->x;
		double yy=mechant->y+game->player->y;
		double zz=mechant->z+game->player->z;
		mechant->dist=xx*xx+yy*yy+zz*zz;

		glPushMatrix();
			// glScaled(1,1,-1);
			glTranslated(mechant->x,mechant->y,mechant->z+1);
			game_render_one_mechant(mechant,game,r_color,g_color,b_color,0);
		glPopMatrix();

		mechant=mechant->next;
	}




	Particle* p=game->particles;
	glDisable(GL_POINT_SMOOTH);
	glPointSize(7);
	if(game->stereo){
		glColor4d(.7,.2,.2,1);
	}else{
		glColor4d(1,0,0,1);
	}
	while(p!=NULL){
		// double xx=p->x+game->player->x;
		// double yy=p->y+game->player->y;
		// double zz=p->z+game->player->z;
		// double dist = sqrt(xx*xx+yy*yy+zz*zz);
		// dist=50-dist;
		// if(dist<7)dist=7;
		// if(dist>30)dist=30;
		// glPointSize(dist);
		glBegin(GL_POINTS);
			glVertex3d(p->x,p->y,p->z);
		glEnd();
		p=p->next;
	}
	glEnable(GL_POINT_SMOOTH);




	//==================================================
	//==================================================
	//==================================================
	int duration=SDL_GetTicks()-time_render_begin;
	if(duration>20){
		// printf("reducing arrow limits\n");
		ARROW_MAX_HIGH_QUALITY-=random(1,10)+ARROW_MAX_HIGH_QUALITY/16.;
		ARROW_MAX_LOW_QUALITY -=random(1,10)+ARROW_MAX_LOW_QUALITY/16.;
		ARROW_MAX             -=random(1,10)+ARROW_MAX/16.;
		if(ARROW_MAX_HIGH_QUALITY<70)ARROW_MAX_HIGH_QUALITY=70;
		if(ARROW_MAX_LOW_QUALITY<70)ARROW_MAX_LOW_QUALITY=70;
		// if(ARROW_MAX<50)ARROW_MAX=50;
		// printf("%i,%i,%i\n",ARROW_MAX_HIGH_QUALITY,ARROW_MAX_LOW_QUALITY,ARROW_MAX);

	}else if(duration<15){
		// printf("unreducing arrow limits\n");
		// ARROW_MAX_HIGH_QUALITY+=log(1+ARROW_MAX_HIGH_QUALITY*.2);
		// ARROW_MAX_LOW_QUALITY+=log(1+ARROW_MAX_LOW_QUALITY*.2);
		// ARROW_MAX+=log(1+ARROW_MAX*.2);
		ARROW_MAX_HIGH_QUALITY+=random(10,10)+ARROW_MAX_HIGH_QUALITY/128.;
		ARROW_MAX_LOW_QUALITY +=random(10,10)+ARROW_MAX_LOW_QUALITY/128.;
		ARROW_MAX             +=random(10,10)+ARROW_MAX/128.;
		if(ARROW_MAX_HIGH_QUALITY>10000)ARROW_MAX_HIGH_QUALITY=10000;
		if(ARROW_MAX_LOW_QUALITY>10000)ARROW_MAX_LOW_QUALITY=10000;
		if(ARROW_MAX>10000)ARROW_MAX=10000;
		// if(ARROW_MAX!=10000)
		// 	printf("%i,%i,%i\n",ARROW_MAX_HIGH_QUALITY,ARROW_MAX_LOW_QUALITY,ARROW_MAX);
	}
}
void warpin_render(object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, int warp_3d)
{
	vec3d center;
	vec3d vecs[5];
	vertex verts[5];
	int saved_gr_zbuffering = gr_zbuffer_get();

	gr_zbuffer_set(GR_ZBUFF_READ);

	vm_vec_scale_add( &center, pos, &orient->vec.fvec, -(max_radius/2.5f)/3.0f );


	if (Warp_glow_bitmap >= 0) {
		float r = radius;
		bool render_it = true;

		#define OUT_PERCENT1 0.80f
		#define OUT_PERCENT2 0.90f

		#define IN_PERCENT1 0.10f
		#define IN_PERCENT2 0.20f

		if (Cmdline_warp_flash)
		{
			if ( (life_percent >= IN_PERCENT1) && (life_percent < IN_PERCENT2) ) {
				r *= (life_percent - IN_PERCENT1) / (IN_PERCENT2 - IN_PERCENT1);
				//render_it = true;
			} else if ( (life_percent >= OUT_PERCENT1) && (life_percent < OUT_PERCENT2) ) {
				r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2 - OUT_PERCENT1);
				//render_it = true;
			}
		}

		if (render_it) {
			// Add in noise 
			int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;

			r *= (0.40f + Noise[noise_frame] * 0.30f);

			// Bobboau's warp thingie, toggled by cmdline
			if (Cmdline_warp_flash) {
				r += powf((2.0f * life_percent) - 1.0f, 24.0f) * max_radius * 1.5f;
			}

			vecs[4] = center;
			verts[4].texture_position.u = 0.5f; verts[4].texture_position.v = 0.5f; 

			if (Cmdline_nohtl) {
				g3_rotate_vertex( &verts[4], &vecs[4] );
			} else {
				g3_transfer_vertex( &verts[4], &vecs[4] );
			}

			float alpha = (The_mission.flags & MISSION_FLAG_FULLNEB) ? (1.0f - neb2_get_fog_intensity(obj)) : 1.0f;
			gr_set_bitmap( Warp_glow_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha );

			g3_draw_bitmap( &verts[4], 0, r, TMAP_FLAG_TEXTURED | TMAP_HTL_3D_UNLIT );
		}
	}

	if ( (Warp_model >= 0) && (warp_3d || Cmdline_3dwarp) ) {
		float scale = radius / 25.0f;
		model_set_warp_globals(scale, scale, scale, texture_bitmap_num, (radius/max_radius) );

		float dist = vm_vec_dist_quick( pos, &Eye_position );
		model_set_detail_level((int)(dist / (radius * 10.0f)));

		model_render( Warp_model, orient, pos, MR_LOCK_DETAIL | MR_NO_LIGHTING | MR_NORMAL | MR_NO_FOGGING | MR_NO_CULL );

		model_set_warp_globals();
	} else {
		float Grid_depth = radius/2.5f;

		gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );	

		vm_vec_scale_add( &vecs[0], &center, &orient->vec.uvec, radius );
		vm_vec_scale_add2( &vecs[0], &orient->vec.rvec, -radius );
		vm_vec_scale_add2( &vecs[0], &orient->vec.fvec, Grid_depth );

		vm_vec_scale_add( &vecs[1], &center, &orient->vec.uvec, radius );
		vm_vec_scale_add2( &vecs[1], &orient->vec.rvec, radius );
		vm_vec_scale_add2( &vecs[1], &orient->vec.fvec, Grid_depth );

		vm_vec_scale_add( &vecs[2], &center, &orient->vec.uvec, -radius );
		vm_vec_scale_add2( &vecs[2], &orient->vec.rvec, radius );
		vm_vec_scale_add2( &vecs[2], &orient->vec.fvec, Grid_depth );

		vm_vec_scale_add( &vecs[3], &center, &orient->vec.uvec, -radius );
		vm_vec_scale_add2( &vecs[3], &orient->vec.rvec, -radius );
		vm_vec_scale_add2( &vecs[3], &orient->vec.fvec, Grid_depth );

	//	vm_vec_scale_add( &vecs[4], ¢er, &orient->vec.fvec, -Grid_depth );
		vecs[4] = center;

		verts[0].texture_position.u = 0.01f;
		verts[0].texture_position.v = 0.01f;
		
		verts[1].texture_position.u = 0.99f;
		verts[1].texture_position.v = 0.01f;

		verts[2].texture_position.u = 0.99f;
		verts[2].texture_position.v = 0.99f;

		verts[3].texture_position.u = 0.01f;
		verts[3].texture_position.v = 0.99f;

		verts[4].texture_position.u = 0.5f;
		verts[4].texture_position.v = 0.5f; 

		if (Cmdline_nohtl) {
			g3_rotate_vertex( &verts[0], &vecs[0] );
			g3_rotate_vertex( &verts[1], &vecs[1] );
			g3_rotate_vertex( &verts[2], &vecs[2] );
			g3_rotate_vertex( &verts[3], &vecs[3] );
			g3_rotate_vertex( &verts[4], &vecs[4] );
		} else {
			g3_transfer_vertex( &verts[0], &vecs[0] );
			g3_transfer_vertex( &verts[1], &vecs[1] );
			g3_transfer_vertex( &verts[2], &vecs[2] );
			g3_transfer_vertex( &verts[3], &vecs[3] );
			g3_transfer_vertex( &verts[4], &vecs[4] );
		}

		int cull = gr_set_cull(0); // fixes rendering problem in D3D - taylor
		draw_face( &verts[0], &verts[4], &verts[1] );
		draw_face( &verts[1], &verts[4], &verts[2] );
		draw_face( &verts[4], &verts[3], &verts[2] );
		draw_face( &verts[0], &verts[3], &verts[4] );
		gr_set_cull(cull);
	}

	if (Warp_ball_bitmap > -1 && Cmdline_warp_flash == 1) {
		flash_ball warp_ball(20, .1f,.25f, &vmd_z_vector, &vmd_zero_vector, 4.0f, 0.5f);
		float adg = (2.0f * life_percent) - 1.0f;
		float pct = (powf(adg, 4.0f) - powf(adg, 128.0f)) * 4.0f;

		if (pct > 0.00001f) {
			g3_start_instance_matrix(pos, orient, true);

			gr_set_bitmap(Warp_ball_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 0.9999f);		

			warp_ball.render(max_radius * pct * 0.5f, adg * adg, adg * adg * 6.0f);

			g3_done_instance(true);
		}
	}

	gr_zbuffer_set( saved_gr_zbuffering );
}
Ejemplo n.º 10
0
static PyObject* cube_draw( PyObject* self, PyObject* args )
{
    PyObject* dict;
    double aspect, alpha;
    double x, theta;

    if ( !PyArg_ParseTuple( args, "Odd", &dict, &aspect, &alpha ) )
	return NULL;

    // "dict" is a dictionary containing the diagram's parameter values.
    // "aspect" is the aspect ratio of the viewport.
    // "alpha" is the alpha value to multiply all of your drawing
    //   colors by, if you want your diagram to respond to Slithy's
    //   normal fade_in() and fade_out() functions. 


    // if you want to use mark_projection() to save the coordinate
    // system for later use with unproject(), do that here. 


    // now we'll get started setting up our projection.  When this
    // function is called, the corners of the viewport will be at
    // (-aspect,-1) and (aspect,1).
    glMatrixMode( GL_PROJECTION );
    // we'll stretch things out so that the viewport corners are at
    // (-1,-1) and (1,1).  this corresponds to the normal OpenGL
    // default projection.  Do this if you want to use the normal
    // projection setup functions like gluPerspective() or
    // glFrustum().
    glScaled( aspect, 1.0, 1.0 );

    // if you want to use depth testing, you MUST call either
    // opengl_clear_blank() or opengl_clear_color() at this point in
    // order to initialize the depth buffer.
    //
    // opengl_clear_color() will clear the viewport to the current
    // OpenGL color; opengl_clear_blank() will have not alter the
    // color buffer.
    glColor4d( 0.2, 0.2, 0.3, alpha );
    opengl_clear_color();

    // now you can set up your normal OpenGL projection, just as with
    // any other OpenGL drawing.  note that you do NOT do a
    // glLoadIdentity first.
    //
    // you should not push or pop the projection matrix stack.  many
    // OpenGL implementations have only 2 entries on this stack, and
    // Slithy uses both of them.
    gluPerspective( 25.0, aspect, 0.1, 30.0 );

    // Slithy will initialize the model-view matrix to the identity
    // before calling your function.  you are free to push and pop
    // this matrix stack normally.
    glMatrixMode( GL_MODELVIEW );
    glTranslated( 0.0, 0.0, -12.0 );

    // note that to use depth testing, you have to explicitly turn it
    // on.  
    glEnable( GL_DEPTH_TEST );
    
    // use the get_*() functions to retrieve parameter
    // values from the dictionary.
    x = get_scalar( dict, "x" );
    theta = get_scalar( dict, "theta" );

    //
    // now we will draw a rotated cube with open faces.
    //

    glRotated( theta, 0.7, 0.4, -0.1 );
    
    glPushMatrix();
    glColor3d( 1.0, 0.0, 0.0 );
    draw_face( x );
    glColor3d( 0.0, 1.0, 1.0 );
    glRotated( 180.0, 1.0, 0.0, 0.0 );
    draw_face( x );
    glPopMatrix();
    
    glPushMatrix();
    glColor3d( 0.0, 1.0, 0.0 );
    glRotated( 90.0, 0.0, 1.0, 0.0 );
    draw_face( x );
    glColor3d( 1.0, 0.0, 1.0 );
    glRotated( 180.0, 1.0, 0.0, 0.0 );
    draw_face( x );
    glPopMatrix();
    
    glPushMatrix();
    glColor3d( 0.0, 0.0, 1.0 );
    glRotated( 90.0, 1.0, 0.0, 0.0 );
    draw_face( x );
    glColor3d( 1.0, 1.0, 0.0 );
    glRotated( 180.0, 0.0, 1.0, 0.0 );
    draw_face( x );
    glPopMatrix();

    //
    // end of the drawing code.
    //


    // the return value is discarded, but we have to return something,
    // so return the "None" object.
    // to raise an exception, use PyErr_SetString() and return NULL.
    Py_INCREF( Py_None );
    return Py_None;
}
Ejemplo n.º 11
0
void sph_model::draw_face(const int *fv, int fc,
                          const int *pv, int pc,
                          double r, double l, double t, double b, int d, int i)
{
    GLuint o = 0;
    int then = time;

    if (status[i] != s_halt)
    {
        for (int fi = 0; fi < fc; ++fi)
        {
            int e = fi * 8 + d;
            
            glActiveTexture(GL_TEXTURE0 + e);

            o = cache.get_page(fv[fi], i, time, then);

            glUniform1f(alpha[e], age(then));
            glBindTexture(GL_TEXTURE_2D, o);
        }
        glUniform2f(tex_a[d], GLfloat(r), GLfloat(t));
        glUniform2f(tex_d[d], GLfloat(l), GLfloat(b));
    }

    if (status[i] == s_pass)
    {
        for (int pi = 0; pi < pc; ++pi)
            cache.get_page(pv[pi], i, time, then);
    }
    
    if (status[i] == s_pass)
    {
        const double x = (r + l) * 0.5;
        const double y = (t + b) * 0.5;

        draw_face(fv, fc, pv, pc, r, x, t, y, d + 1, face_child(i, 0));
        draw_face(fv, fc, pv, pc, x, l, t, y, d + 1, face_child(i, 1));
        draw_face(fv, fc, pv, pc, r, x, y, b, d + 1, face_child(i, 2));
        draw_face(fv, fc, pv, pc, x, l, y, b, d + 1, face_child(i, 3));
    }

    if (status[i] == s_draw)
    {
        int n, s, e, w, j = 0;
        
        face_neighbors(i, n, s, e, w);
        
        if (i > 5) j = (status[face_parent(n)] == s_draw ? 1 : 0)
                     | (status[face_parent(s)] == s_draw ? 2 : 0)
                     | (status[face_parent(e)] == s_draw ? 4 : 0)
                     | (status[face_parent(w)] == s_draw ? 8 : 0);

        glUniform1i(level, d);
        
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elements[j]);
        glDrawElements(GL_QUADS, count, GL_UNSIGNED_SHORT, 0);
    }
    
    if (status[i] != s_halt)
    {
        for (int fi = 0; fi < fc; ++fi)
        {
            glActiveTexture(GL_TEXTURE0 + fi * 8 + d);
            glBindTexture(GL_TEXTURE_2D, cache.get_fill());
        }
    }
}
Ejemplo n.º 12
0
void sph_model::draw(const double *P, const double *V, const int *fv, int fc,
                                                       const int *pv, int pc, float alpha)
{
    double M[16];
    
    mmultiply(M, P, V);

    glMatrixMode(GL_PROJECTION);
    glLoadMatrixd(P);
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd(V);
    
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glBindBuffer(GL_ARRAY_BUFFER, vertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, 0);

    for (int i = 15; i >= 0; --i)
    {
        glActiveTexture(GL_TEXTURE0 + i);
        glBindTexture(GL_TEXTURE_2D, cache.get_fill());
    }

    // This is a hack that ensures that the root pages of all files are touched.

    GLuint o;
    int tock;

    for (int i = 0; i < fc; ++i)
    {
        o = cache.get_page(fv[i], 0, time, tock);
        o = cache.get_page(fv[i], 1, time, tock);
        o = cache.get_page(fv[i], 2, time, tock);
        o = cache.get_page(fv[i], 3, time, tock);
        o = cache.get_page(fv[i], 4, time, tock);
        o = cache.get_page(fv[i], 5, time, tock);
    }
    for (int i = 0; i < pc; ++i)
    {
        o = cache.get_page(pv[i], 0, time, tock);
        o = cache.get_page(pv[i], 1, time, tock);
        o = cache.get_page(pv[i], 2, time, tock);
        o = cache.get_page(pv[i], 3, time, tock);
        o = cache.get_page(pv[i], 4, time, tock);
        o = cache.get_page(pv[i], 5, time, tock);
    }

#if 0
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#endif

    glUseProgram(program);
    {
        glUniform1f(glGetUniformLocation(program, "zoomk"), zoomk);
	glUniform1f(glGetUniformLocation(program, "globalAlpha"), alpha);
        glUniform3f(glGetUniformLocation(program, "zoomv"),
                    zoomv[0], zoomv[1], zoomv[2]);

        for (int i = 0; i < 6; ++i)
        {
            double a[3], b[3], c[3], d[3];
            
            vnormalize(a, cube_v[cube_i[i][0]]);
            vnormalize(b, cube_v[cube_i[i][1]]);
            vnormalize(c, cube_v[cube_i[i][2]]);
            vnormalize(d, cube_v[cube_i[i][3]]);
            
            glUniform3f(pos_a, GLfloat(a[0]), GLfloat(a[1]), GLfloat(a[2]));
            glUniform3f(pos_b, GLfloat(b[0]), GLfloat(b[1]), GLfloat(b[2]));
            glUniform3f(pos_c, GLfloat(c[0]), GLfloat(c[1]), GLfloat(c[2]));
            glUniform3f(pos_d, GLfloat(d[0]), GLfloat(d[1]), GLfloat(d[2]));

            draw_face(fv, fc, pv, pc, 0, 1, 0, 1, 0, i);
        }
    }
    glUseProgram(0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER,         0);
    glDisableClientState(GL_VERTEX_ARRAY);

    glActiveTexture(GL_TEXTURE0);
}