Esempio n. 1
0
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{

	/*

	**********************************************************
	
	  table of who gets what in JetPack Jack
	  this just maps out which objects are viewed first, etc.

	  CHARACTER			8
	  AMMO METER		7
	  FOREGROUND		6
	  MIDDLEGROUND		4
	  BACKGROUND		2
	  SUN				1

	**********************************************************

	*/

	//		SUN

	glBindTexture(GL_TEXTURE_2D, textures[SUN].texID);

	glLoadIdentity();
		
	glTranslated(900,128,1);

	glRotatef(sunrot,0.0f,0.0f,1.0f);

	sunrot+=0.2f;
		
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,1.0f); glVertex3d(-64,-64, 0);
		glTexCoord2f(1.0f,1.0f); glVertex3d( 64,-64, 0);
		glTexCoord2f(1.0f,0.0f); glVertex3d( 64, 64, 0);
		glTexCoord2f(0.0f,0.0f); glVertex3d(-64, 64, 0);
	glEnd();

	//		END SUN


	//		ALL GROUNDS START

	//		BACKGROUND

	glBindTexture(GL_TEXTURE_2D, textures[SKY].texID);

	for(int a=(int)xpos3-2048;a<xpos3+2048;a+=1024)
	{
		
		glLoadIdentity();
		
		glTranslated(a,128,2);
		
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(-512,-128, 0);
			glTexCoord2f(1.0f,1.0f); glVertex3d( 512,-128, 0);
			glTexCoord2f(1.0f,0.0f); glVertex3d( 512, 128, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-512, 128, 0);
		glEnd();
		
	}


	//		MIDDLEGROUND

	glBindTexture(GL_TEXTURE_2D, textures[MOUNTAINS].texID);

	for(int a=(int)xpos2-2048;a<xpos2+2048;a+=1024)
	{
		
		glLoadIdentity();
		
		glTranslated(a,475,4);
		
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(-512,-200, 0);
			glTexCoord2f(1.0f,1.0f); glVertex3d( 512,-200, 0);
			glTexCoord2f(1.0f,0.0f); glVertex3d( 512, 200, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-512, 200, 0);
		glEnd();
		
	}


	//		FOREGROUND

	for(int a=(int)xpos1-2048;a<xpos1+2048;a+=1024)
	{

		glBindTexture(GL_TEXTURE_2D, textures[GROUND].texID);

		glLoadIdentity();
		
		glTranslated(a,704,6);
		
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(-512,-64, 0);
			glTexCoord2f(1.0f,1.0f); glVertex3d( 512,-64, 0);
			glTexCoord2f(1.0f,0.0f); glVertex3d( 512, 64, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(-512, 64, 0);
		glEnd();
		
	}

	//		ALL GROUNDS END


	//		AMMO METER

	glBindTexture(GL_TEXTURE_2D, textures[character.currentgun+7].texID);

	glLoadIdentity();
	
	glTranslated(10,30,7);

	for(int a=0;a<character.currentshots;a++)
	{
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f,1.0f); glVertex3d(0,-15, 0);
			glTexCoord2f((100-(float)weapons.regen[a])/100,1.0f); glVertex3d( ((100-(float)weapons.regen[a])/100)*40,-15, 0);
			glTexCoord2f((100-(float)weapons.regen[a])/100,0.0f); glVertex3d( ((100-(float)weapons.regen[a])/100)*40, 15, 0);
			glTexCoord2f(0.0f,0.0f); glVertex3d(0, 15, 0);
		glEnd();

		glTranslated(40,0,0);
		
	}

	//		END AMMO METER


	//		LIFE METER

	glDisable(GL_TEXTURE_2D);

	glLoadIdentity();
	
	glTranslated(10,60,7);

	glBegin(GL_QUADS);
		glVertex3d( 1,  -15, 0);
		glVertex3d( 101,-15, 0);
		glVertex3d( 101, 15, 0);
		glVertex3d( 1,   15, 0);
	glEnd();

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, textures[BAR].texID);

	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,1.0f); glVertex3d( 1,					-15, 1);
		glTexCoord2f(1.0f,1.0f); glVertex3d( character.life+1,	-15, 1);
		glTexCoord2f(1.0f,0.0f); glVertex3d( character.life+1,	 15, 1);
		glTexCoord2f(0.0f,0.0f); glVertex3d( 1,					 15, 1);
	glEnd();

	glPolygonMode(GL_BACK,GL_LINE);
	glPolygonMode(GL_FRONT,GL_LINE);

	glBegin(GL_QUADS);
		glColor3f(0.0f,0.0f,0.0f);
		glVertex3d( 0,  -16, 0);
		glVertex3d( 102,-16, 0);
		glVertex3d( 102, 16, 0);
		glVertex3d( 0,   16, 0);
	glEnd();

	glPolygonMode(GL_BACK,GL_FILL);
	glPolygonMode(GL_FRONT,GL_FILL);

	glColor3f(1.0f,1.0f,1.0f);

/*
	glDisable(GL_TEXTURE_2D);

	glLoadIdentity();
	glTranslated(0,0,8);
	glColor3f(1.0,0.0f,0.0f);
	glRasterPos2d(0,30);
	b1.glPrint("rightpress %d",rightpress);
	glColor3f(1.0,1.0f,1.0f);

	glEnable(GL_TEXTURE_2D);
*/
	return TRUE;										// Keep Going
}
Esempio n. 2
0
void VectorView::on_display()
{
  set_ortho_projection();
  glDisable(GL_LIGHTING);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_TEXTURE_1D);
  glPolygonMode(GL_FRONT_AND_BACK, pmode ? GL_LINE : GL_FILL);

  // initial grid point and grid step
  double gt = gs;
  if (hexa) gt *= sqrt(3.0)/2.0;

  double max_length = 0.0;

  // transform all vertices
  vec.lock_data();
  int i;
  int nv = vec.get_num_vertices();
  double4* vert = vec.get_vertices();
  double2* tvert = new double2[nv];

  for (i = 0; i < nv; i++)
  {
    tvert[i][0] = transform_x(vert[i][0]);
    tvert[i][1] = transform_y(vert[i][1]);

    // find max length of vectors
    double length = sqr(vert[i][2]) + sqr(vert[i][3]);
    if (length > max_length) max_length = length;
  }
  max_length = sqrt(max_length);

  // value range
  double min = range_min, max = range_max;
  if (range_auto) { min = vec.get_min_value(); max = vec.get_max_value(); }
  double irange = 1.0 / (max - min);
  // special case: constant solution
  if (fabs(min - max) < 1e-8) { irange = 1.0; min -= 0.5; }

  // draw all triangles
  int3* xtris = vec.get_triangles();

  if (mode != 1) glEnable(GL_TEXTURE_1D);
  glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id);
  glBegin(GL_TRIANGLES);
  glColor3f(0.95f, 0.95f, 0.95f);
  for (i = 0; i < vec.get_num_triangles(); i++)
  {
    double mag = sqrt(sqr(vert[xtris[i][0]][2]) + sqr(vert[xtris[i][0]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][0]][0], tvert[xtris[i][0]][1]);

    mag = sqrt(sqr(vert[xtris[i][1]][2]) + sqr(vert[xtris[i][1]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][1]][0], tvert[xtris[i][1]][1]);

    mag = sqrt(sqr(vert[xtris[i][2]][2]) + sqr(vert[xtris[i][2]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][2]][0], tvert[xtris[i][2]][1]);
  }
  glEnd();
  glDisable(GL_TEXTURE_1D);

  // draw all edges
  /*if (mode == 0) glColor3f(0.3, 0.3, 0.3);
  else*/ glColor3f(0.5, 0.5, 0.5);
  glBegin(GL_LINES);
  int3* edges = vec.get_edges();
  for (i = 0; i < vec.get_num_edges(); i++)
  {
    if (lines || edges[i][2] != 0)
    {
      glVertex2d(tvert[edges[i][0]][0], tvert[edges[i][0]][1]);
      glVertex2d(tvert[edges[i][1]][0], tvert[edges[i][1]][1]);
    }
  }
  glEnd();

  // draw dashed edges
  if (lines)
  {
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1, 0xCCCC);
    glBegin(GL_LINES);
    int2* dashes = vec.get_dashes();
    for (i = 0; i < vec.get_num_dashes(); i++)
    {
      glVertex2d(tvert[dashes[i][0]][0], tvert[dashes[i][0]][1]);
      glVertex2d(tvert[dashes[i][1]][0], tvert[dashes[i][1]][1]);
    }
    glEnd();
    glDisable(GL_LINE_STIPPLE);
  }

  // draw arrows
  if (mode != 2)
  {
    for (i = 0; i < vec.get_num_triangles(); i++)
    {
      double miny = 1e100;
      int idx, k, l1, l2, r2, r1, s;
      double lry, x;
      double mr, ml, lx, rx, xval, yval;

      double wh = output_height + gt, ww = output_width + gs;
      if ((tvert[xtris[i][0]][0] < -gs) && (tvert[xtris[i][1]][0] < -gs) && (tvert[xtris[i][2]][0] < -gs)) continue;
      if ((tvert[xtris[i][0]][0] >  ww) && (tvert[xtris[i][1]][0] >  ww) && (tvert[xtris[i][2]][0] >  ww)) continue;
      if ((tvert[xtris[i][0]][1] < -gt) && (tvert[xtris[i][1]][1] < -gt) && (tvert[xtris[i][2]][1] < -gt)) continue;
      if ((tvert[xtris[i][0]][1] >  wh) && (tvert[xtris[i][1]][1] >  wh) && (tvert[xtris[i][2]][1] >  wh)) continue;

      // find vertex with min y-coordinate
      for (k = 0; k < 3; k++)
        if (tvert[xtris[i][k]][1] < miny)
          miny = tvert[xtris[i][idx = k]][1];
      l1 = r1 = xtris[i][idx];
      l2 = xtris[i][n_vert(idx)];
      r2 = xtris[i][p_vert(idx)];

      // plane of x and y values on triangle
      double a[2], b[2], c[2], d[2];
      for (int n = 0; n < 2; n++)
      {
        a[n] = (tvert[l1][1] - tvert[l2][1])*(vert[r1][2 +n] - vert[r2][2+n]) - (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][1] - tvert[r2][1]);
        b[n] = (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][0] - tvert[r2][0]) - (tvert[l1][0] - tvert[l2][0])*(vert[r1][2+n] - vert[r2][2+n]);
        c[n] = (tvert[l1][0] - tvert[l2][0])*(tvert[r1][1] - tvert[r2][1]) - (tvert[l1][1] - tvert[l2][1])*(tvert[r1][0] - tvert[r2][0]);
        d[n] = -a[n] * tvert[l1][0] - b[n] * tvert[l1][1] - c[n] * vert[l1][2+n];
        a[n] /= c[n]; b[n] /= c[n]; d[n] /= c[n];
      }

      s = (int) ceil((tvert[l1][1] - gy)/gt);  // first step
      lry = gy + s*gt;
      bool shift = hexa && (s & 1);

      // if there are two points with min y-coordinate, switch to the next segment
      if ((tvert[l1][1] == tvert[l2][1]) || (tvert[r1][1] == tvert[r2][1]))
        if (tvert[l1][1] == tvert[l2][1])
          {l1 = l2; l2 = r2;}
        else if (tvert[r1][1] == tvert[r2][1])
          {r1 = r2; r2 = l2;}

      // slope of the left and right segment
      ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]);
      mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]);
      // x-coordinates of the endpoints of the first line
      lx = tvert[l1][0] + ml * (lry - (tvert[l1][1]));
      rx = tvert[r1][0] + mr * (lry - (tvert[r1][1]));

      if (lry < -gt)
      {
        k = (int) floor(-lry/gt);
        lry += gt * k;
        lx += k * ml * gt;
        rx += k * mr * gt;
      }

      // while we are in triangle
      while (((lry < tvert[l2][1]) || (lry < tvert[r2][1])) && (lry < wh))
      {
        // while we are in the segment
        while (((lry <= tvert[l2][1]) && (lry <= tvert[r2][1])) && (lry < wh))
        {
          double gz = gx;
          if (shift) gz -= 0.5*gs;
          s = (int) ceil((lx - gz)/gs);
          x = gz + s*gs;
          if (hexa) shift = !shift;

          if (x < -gs)
          {
            k = (int) floor(-x/gs);
            x += gs * k;
          }
          // go along the line
          while ((x < rx) && (x < ww))
          {
            // plot the arrow
            xval = -a[0]*x - b[0]*lry - d[0];
            yval = -a[1]*x - b[1]*lry - d[1];
            plot_arrow(x, lry, xval, yval, max, min, gs);
            x += gs;
          }
          // move to the next line
          lx += ml*gt;
          rx += mr*gt;
          lry += gt;
        }
        // change segment
        if (lry >= tvert[l2][1]) {
          l1 = l2; l2 = r2;
          ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]);
          lx = tvert[l1][0] + ml * (lry - (tvert[l1][1]));
        }
        else {
          r1 = r2; r2 = l2;
          mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]);
          rx = tvert[r1][0] + mr * (lry - (tvert[r1][1]));
        }
      }
    }
  }

  delete [] tvert;
  vec.unlock_data();
}
Esempio n. 3
0
// GLUI control callback
void MeshGui::control_cb( int control )
{
	float v[4];
	switch (control)
	{
	case LIGHT0_ENABLE:
		if ( light0_enabled )
		{
			glEnable( GL_LIGHT0 );
			light0_spinner->enable();
		}
		else
		{
			glDisable( GL_LIGHT0 ); 
			light0_spinner->disable();
		}
		break;
	case LIGHT1_ENABLE:
		if ( light1_enabled )
		{
			glEnable( GL_LIGHT1 );
			light1_spinner->enable();
		}
		else
		{
			glDisable( GL_LIGHT1 ); 
			light1_spinner->disable();
		}
		break;
	case LIGHT0_INTENSITY:
		v[0] = light0_diffuse[0] * light0_intensity;
		v[1] = light0_diffuse[1] * light0_intensity;
		v[2] = light0_diffuse[2] * light0_intensity;
		v[3] = light0_diffuse[3];
		glLightfv(GL_LIGHT0, GL_DIFFUSE, v );
		break;
	case LIGHT1_INTENSITY:
		v[0] = light1_diffuse[0] * light1_intensity;
		v[1] = light1_diffuse[1] * light1_intensity;
		v[2] = light1_diffuse[2] * light1_intensity;
		v[3] = light1_diffuse[3];
		glLightfv(GL_LIGHT1, GL_DIFFUSE, v );
		break;
	case SHADING_MODE:
		switch (radiogroup_item_id)
		{
		case 1: // smoothShaded
			glShadeModel(GL_SMOOTH);
			glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
			break;
		case 2: // wireframe
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
			break;
		case 3: // shadedEdges
			glShadeModel(GL_FLAT);
			glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
			break;
		case 4: // point
			glPolygonMode( GL_FRONT_AND_BACK, GL_POINT );
			break;
		case 0: // flatShaded
		default:
			glShadeModel(GL_FLAT);
			glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
			break;
		}
		break;
	case INPUT_FILE:
		strcpy(filename, "smf/");
		strcat(filename, filetext);
		strcat(filename, ".smf");
		break;
	case OPEN_MESH:
		smf_model.loadFile(filename);
		glutPostRedisplay();
		break;
	case SAVE_MESH:
		smf_model.save(filename);
		break;
	case EDGE_NUMBER:
		break;
	case COLLAPSE_NUMBER:
		break;
	case DECIMATE:
		std::cout << "decimate amongst " << edge_number << " edges, collapse " << collapse_percentage << " % edges" << std::endl;
		smf_model.decimate(edge_number, collapse_percentage);
		glutPostRedisplay();
		break;
	default:
		break;
	}
}
Esempio n. 4
0
bool glWindow::ResetGL () {

    if (m_resetGLMode == RGM_RECREATEWINDOW) {
        RecreateWindow (m_fullScreen, m_border, m_width, m_height, m_bpp, m_stencil, m_title, m_allowResizing, m_fitToWorkArea);
        return true;
    }
    else if (m_resetGLMode == RGM_RECREATECONTEXT) {
        RecreateGLContext ();
        return true;
    }

    // Setup OpenGL defaults.
    // This should reset as much as possible back to the initial state of OpenGL.

    // Exceptions:
    //      * Projection matrix is initialised to a perspective transform

    // End current gl block
    try { glEnd ();                                                             } catch (...) { ; }    
    m_dontPaint = false;

    // Intialise matrices
    try { glMatrixMode (GL_PROJECTION);   ClearGLMatrix ();                     } catch (...) { ; }
    try { glMatrixMode (GL_TEXTURE);      ClearGLMatrix ();                     } catch (...) { ; }
    try { glMatrixMode (GL_MODELVIEW);    ClearGLMatrix ();                     } catch (...) { ; }

    // Initialise state
    int i;
    try { glColor4f (1, 1, 1, 1);                                               } catch (...) { ; }
    try { glIndexi (1);                                                         } catch (...) { ; }
    try { glTexCoord4f (0, 0, 0, 1);                                            } catch (...) { ; }
    try { glNormal3f (0, 0, 1);                                                 } catch (...) { ; }
//    try { glRasterPos4f (0, 0, 0, 1);                                           } catch (...) { ; }
    try { glEdgeFlag (GL_TRUE);                                                 } catch (...) { ; }
    try { glDisable (GL_VERTEX_ARRAY);                                          } catch (...) { ; }
    try { glDisable (GL_NORMAL_ARRAY);                                          } catch (...) { ; }
    try { glDisable (GL_COLOR_ARRAY);                                           } catch (...) { ; }
    try { glDisable (GL_INDEX_ARRAY);                                           } catch (...) { ; }
    try { glDisable (GL_TEXTURE_COORD_ARRAY);                                   } catch (...) { ; }
    try { glDisable (GL_EDGE_FLAG_ARRAY);                                       } catch (...) { ; }
    try { glDepthRange (0, 1);                                                  } catch (...) { ; }
    try { glDisable (GL_NORMALIZE);                                             } catch (...) { ; }
    for (i = 0; i < GL_MAX_CLIP_PLANES; i++)
        try { glDisable (GL_CLIP_PLANE0 + i);                                   } catch (...) { ; }
    GLfloat fog[] = {0, 0, 0, 0};
    try { glFogfv (GL_FOG_COLOR, fog);                                          } catch (...) { ; }
    try { glFogi (GL_FOG_INDEX, 0);                                             } catch (...) { ; }
    try { glFogf (GL_FOG_DENSITY, 1.0);                                         } catch (...) { ; }
    try { glFogf (GL_FOG_START, 0.0);                                           } catch (...) { ; }
    try { glFogf (GL_FOG_END, 1.0);                                             } catch (...) { ; }
    try { glFogi (GL_FOG_MODE, GL_EXP);                                         } catch (...) { ; }
    try { glDisable (GL_FOG);                                                   } catch (...) { ; }
    try { glShadeModel (GL_SMOOTH);                                             } catch (...) { ; }
    try { glDisable (GL_LIGHTING);                                              } catch (...) { ; }
    try { glDisable (GL_COLOR_MATERIAL);                                        } catch (...) { ; }
    try { glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);          } catch (...) { ; }

    GLfloat ambient[]   = { 0.2, 0.2, 0.2, 1.0 },
            diffuse[]   = { 0.8, 0.8, 0.8, 1.0 },
            specular[]  = { 0.0, 0.0, 0.0, 1.0 },
            emission[]  = { 0.0, 0.0, 0.0, 1.0 },
            shininess[] = { 0.0 };
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,    ambient);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,    diffuse);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,  specular);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION,   emission);            } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS,  shininess);           } catch (...) { ; }
    try { glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient);                     } catch (...) { ; }
    try { glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);                } catch (...) { ; }
    try { glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);                    } catch (...) { ; }
    GLfloat lambient[]      = { 0.0, 0.0, 0.0, 1.0 },
            ldiffuse0[]     = { 1.0, 1.0, 1.0, 1.0 },
            ldiffuse1[]     = { 0.0, 0.0, 0.0, 1.0 },
            lspecular0[]    = { 1.0, 1.0, 1.0, 1.0 },
            lspecular1[]    = { 0.0, 0.0, 0.0, 1.0 },
            lposition[]     = { 0.0, 0.0, 1.0, 0.0 };
    for (i = 0; i < 8; i++) {
        try { glLightfv (GL_LIGHT0 + i, GL_AMBIENT, lambient);                              } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_DIFFUSE, i == 0 ? ldiffuse0 : ldiffuse1);        } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_SPECULAR, i == 0 ? lspecular0 : lspecular1);     } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_POSITION, lposition);                            } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_SPOT_EXPONENT, 0.0);                              } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 1.0);                       } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 0.0);                         } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 0.0);                      } catch (...) { ; }
        try { glDisable (GL_LIGHT0 + i);                                                    } catch (...) { ; }
    }

    try { glPointSize (1.0);                                                    } catch (...) { ; }
    try { glDisable (GL_POINT_SMOOTH);                                          } catch (...) { ; }
    try { glLineWidth (1.0);                                                    } catch (...) { ; }
    try { glDisable (GL_LINE_SMOOTH);                                           } catch (...) { ; }
    try { glLineStipple (1, 0xffff);                                            } catch (...) { ; }
    try { glDisable (GL_LINE_STIPPLE);                                          } catch (...) { ; }
    try { glDisable (GL_CULL_FACE);                                             } catch (...) { ; }
    try { glCullFace (GL_BACK);                                                 } catch (...) { ; }
    try { glFrontFace (GL_CCW);                                                 } catch (...) { ; }
    try { glDisable (GL_POLYGON_SMOOTH);                                        } catch (...) { ; }
    try { glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);                           } catch (...) { ; }
    try { glDisable (GL_TEXTURE_1D);                                            } catch (...) { ; }
    try { glDisable (GL_TEXTURE_2D);                                            } catch (...) { ; }

    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);                } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);                    } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);                    } catch (...) { ; }
    GLfloat texBorder[] = {0, 0, 0, 0};
    try { glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, texBorder);             } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_T);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_S);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_R);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_Q);                                                     } catch (...) { ; }
    for (i = 0; i < 4; i++) {
        GLenum coord;
        switch (i) {
        case 0: coord = GL_T; break;
        case 1: coord = GL_S; break;
        case 2: coord = GL_R; break;
        case 3: coord = GL_Q; break;
        }
        try { glTexGeni (coord, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);            } catch (...) { ; }
    }

    try { glDisable (GL_SCISSOR_TEST);                                          } catch (...) { ; }
    try { glDisable (GL_ALPHA_TEST);                                            } catch (...) { ; }
    try { glAlphaFunc (GL_ALWAYS, 0);                                           } catch (...) { ; }
    try { glDisable (GL_STENCIL_TEST);                                          } catch (...) { ; }
    try { glStencilFunc (GL_ALWAYS, 0, 0xffffffff);                             } catch (...) { ; }
    try { glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);                              } catch (...) { ; }
    try { glDisable (GL_DEPTH_TEST);                                            } catch (...) { ; }
    try { glDepthFunc (GL_LESS);                                                } catch (...) { ; }
    try { glDisable (GL_BLEND);                                                 } catch (...) { ; }
    try { glBlendFunc (GL_ONE, GL_ZERO);                                        } catch (...) { ; }
    try { glDrawBuffer (GL_BACK);                                               } catch (...) { ; }
    try { glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);                     } catch (...) { ; }
    try { glDepthMask (GL_TRUE);                                                } catch (...) { ; }
    try { glClearAccum (0, 0, 0, 0);                                            } catch (...) { ; }
    try { glClearColor (0, 0, 0, 0);                                            } catch (...) { ; }
    try { glClearDepth (1);                                                     } catch (...) { ; }
    try { glClearIndex (0);                                                     } catch (...) { ; }
    try { glClearStencil (0);                                                   } catch (...) { ; }

    try { glPixelStorei (GL_PACK_SWAP_BYTES, GL_FALSE);                         } catch (...) { ; }
    try { glPixelStorei (GL_PACK_LSB_FIRST, GL_FALSE);                          } catch (...) { ; }
    try { glPixelStoref (GL_PACK_ROW_LENGTH, 0);                                } catch (...) { ; }
    try { glPixelStoref (GL_PACK_SKIP_PIXELS, 0);                               } catch (...) { ; }
    try { glPixelStorei (GL_PACK_ALIGNMENT, 4);                                 } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);                       } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);                        } catch (...) { ; }
    try { glPixelStoref (GL_UNPACK_ROW_LENGTH, 0);                              } catch (...) { ; }
    try { glPixelStoref (GL_UNPACK_SKIP_PIXELS, 0);                             } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_ALIGNMENT, 4);                               } catch (...) { ; }
    try { glPixelTransferi (GL_MAP_COLOR, GL_FALSE);                            } catch (...) { ; }
    try { glPixelTransferi (GL_MAP_STENCIL, GL_FALSE);                          } catch (...) { ; }
    try { glPixelTransferi (GL_INDEX_SHIFT, 0);                                 } catch (...) { ; }
    try { glPixelTransferi (GL_INDEX_OFFSET, 0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_RED_SCALE, 1.0);                                 } catch (...) { ; }
    try { glPixelTransferf (GL_GREEN_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_BLUE_SCALE, 1.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_ALPHA_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_DEPTH_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_RED_BIAS, 0.0);                                  } catch (...) { ; }
    try { glPixelTransferf (GL_GREEN_BIAS, 0.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_BLUE_BIAS, 0.0);                                 } catch (...) { ; }
    try { glPixelTransferf (GL_ALPHA_BIAS, 0.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_DEPTH_BIAS, 0.0);                                } catch (...) { ; }

    try { glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);                } catch (...) { ; }
    try { glHint (GL_POINT_SMOOTH_HINT, GL_DONT_CARE);                          } catch (...) { ; }
    try { glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);                           } catch (...) { ; }
    try { glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);                        } catch (...) { ; }
    try { glHint (GL_FOG_HINT, GL_DONT_CARE);                                   } catch (...) { ; }

    // Multitexturing
    if (ExtensionSupported ("GL_ARB_multitexture")) {

        // Disable texturing for all texture units
        int units;
        try { glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &units);                 } catch (...) { ; }
        for (int i = 0; i < units; i++) {
            if (glActiveTexture != NULL)
                glActiveTexture (GL_TEXTURE0_ARB + i);
            try { glDisable (GL_TEXTURE_2D);                                    } catch (...) { ; }
            try { glDisable (GL_TEXTURE_1D);                                    } catch (...) { ; }
            if (i == 0) try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } catch (...) { ; }
            else        try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);    } catch (...) { ; }
        }

        if (glActiveTexture != NULL)
            try { glActiveTexture (GL_TEXTURE0_ARB);                            } catch (...) { ; }
    }

    // Setup OpenGL defaults
    OpenGLDefaults ();

	return TRUE;									// Initialization Went OK
}
Esempio n. 5
0
void DemoApplication::renderme()
{
	myinit();

	updateCamera();

	if (m_dynamicsWorld)
	{			
		if(m_enableshadows)
		{
			glClear(GL_STENCIL_BUFFER_BIT);
			glEnable(GL_CULL_FACE);
			renderscene(0);

			glDisable(GL_LIGHTING);
			glDepthMask(GL_FALSE);
			glDepthFunc(GL_LEQUAL);
			glEnable(GL_STENCIL_TEST);
			glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
			glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL);
			glFrontFace(GL_CCW);
			glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
			renderscene(1);
			glFrontFace(GL_CW);
			glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
			renderscene(1);
			glFrontFace(GL_CCW);

			glPolygonMode(GL_FRONT,GL_FILL);
			glPolygonMode(GL_BACK,GL_FILL);
			glShadeModel(GL_SMOOTH);
			glEnable(GL_DEPTH_TEST);
			glDepthFunc(GL_LESS);
			glEnable(GL_LIGHTING);
			glDepthMask(GL_TRUE);
			glCullFace(GL_BACK);
			glFrontFace(GL_CCW);
			glEnable(GL_CULL_FACE);
			glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);

			glDepthFunc(GL_LEQUAL);
			glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL );
			glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
			glDisable(GL_LIGHTING);
			renderscene(2);
			glEnable(GL_LIGHTING);
			glDepthFunc(GL_LESS);
			glDisable(GL_STENCIL_TEST);
			glDisable(GL_CULL_FACE);
		}
		else
		{
			glDisable(GL_CULL_FACE);
			renderscene(0);
		}

		int	xOffset = 10;
		int yStart = 20;
		int yIncr = 20;


		glDisable(GL_LIGHTING);
		glColor3f(0, 0, 0);

		if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0)
		{
			setOrthographicProjection();

			showProfileInfo(xOffset,yStart,yIncr);

#ifdef USE_QUICKPROF

		
			if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings)
			{
				static int counter = 0;
				counter++;
				std::map<std::string, hidden::ProfileBlock*>::iterator iter;
				for (iter = btProfiler::mProfileBlocks.begin(); iter != btProfiler::mProfileBlocks.end(); ++iter)
				{
					char blockTime[128];
					sprintf(blockTime, "%s: %lf",&((*iter).first[0]),btProfiler::getBlockTime((*iter).first, btProfiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT));
					glRasterPos3f(xOffset,yStart,0);
					GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),blockTime);
					yStart += yIncr;

				}

			}
#endif //USE_QUICKPROF


			

			resetPerspectiveProjection();
		}

		glEnable(GL_LIGHTING);


	}

	updateCamera();

}
Esempio n. 6
0
// Test a particular primitive mode
static bool
testPrim(GLenum mode, const GLfloat *verts, GLuint count)
{
	GLfloat x, y;
	GLuint facing, fill;
	int drawMode;
	bool pass = true;

	// Loop over polygon mode: filled vs. outline
	for (fill = 0; fill < 2; fill++) {

		glPolygonMode(GL_FRONT_AND_BACK, fill ? GL_LINE : GL_FILL);

		// Loop over drawing mode: glBegin/End vs glDrawArrays vs glDrawElements
		for (drawMode = 0; drawMode < NUM_DRAW_MODES; drawMode++) {

			// Loop over CW vs. CCW winding (should make no difference)
			for (facing = 0; facing < 2; facing++) {

				if (facing == 0) {
					glFrontFace(GL_CCW);
					glCullFace(GL_BACK);
				}
				else {
					glFrontFace(GL_CW);
					glCullFace(GL_FRONT);
				}

				// Position the geometry at 9 different locations to test
				// clipping against the left, right, bottom and top edges of
				// the window.
				// Only the center location will be unclipped.
				for (y = -1.0; y <= 1.0; y += 1.0) {
					for (x = -1.0; x <= 1.0; x += 1.0) {
						bool quad_pass;
						GLfloat badColor[3];

						glPushMatrix();
						glTranslatef(x, y, 0.0);

						glClear(GL_COLOR_BUFFER_BIT);

						switch (drawMode) {
						case BEGIN_END:
							drawBeginEnd(mode, verts, count);
							break;
						case DRAW_ARRAYS:
							drawArrays(mode, verts, count);
							break;
						case DRAW_ELEMENTS:
							drawElements(mode, verts, count);
							break;
						default:
							assert(0);
						}

						glPopMatrix();

						quad_pass = checkResult(badColor);
						pass = pass && quad_pass;
						reportSubtest(mode, drawMode, facing, fill,
							      badColor, x, y, quad_pass);
					}
				}
			}
		}
	}
	return pass;
}
Esempio n. 7
0
void CUnit::Draw()
{
	glPushMatrix();

	const float3 interPos = pos + (speed * gu->timeOffset);

	if (usingScriptMoveType ||
	    (physicalState == Flying && unitDef->canmove)) {
		// aircraft, skidding ground unit, or active ScriptMoveType
		CMatrix44f transMatrix(interPos, -rightdir, updir, frontdir);
		glMultMatrixf(&transMatrix[0]);
	}
	else if (transporter && transporter->unitDef->holdSteady){

		float3 frontDir=GetVectorFromHeading(heading);		//making local copies of vectors
		float3 upDir=updir;
		float3 rightDir=frontDir.cross(upDir);
		rightDir.Normalize();
		frontDir=upDir.cross(rightDir);

		CMatrix44f transMatrix(interPos,-rightDir,upDir,frontDir);

		glMultMatrixf(&transMatrix[0]);
	}
	else if(upright || !unitDef->canmove){
		glTranslatef3(interPos);
		if(heading!=0)
			glRotatef(heading*(180.0f/32768.0f),0,1,0);
	}
	else {
		float3 frontDir=GetVectorFromHeading(heading);		//making local copies of vectors
		float3 upDir=ground->GetSmoothNormal(pos.x,pos.z);
		float3 rightDir=frontDir.cross(upDir);
		rightDir.Normalize();
		frontDir=upDir.cross(rightDir);

		CMatrix44f transMatrix(interPos,-rightDir,upDir,frontDir);

		glMultMatrixf(&transMatrix[0]);
	}

	if (beingBuilt && unitDef->showNanoFrame) {
		if (shadowHandler->inShadowPass) {
			if (buildProgress>0.66f) {
				localmodel->Draw();
			}
		} else {
			float height=model->height;
			float start=model->miny;
			glEnable(GL_CLIP_PLANE0);
			glEnable(GL_CLIP_PLANE1);
			float col=fabs(128.0f-((gs->frameNum*4)&255))/255.0f+0.5f;
			float3 fc;// fc frame color
			if(gu->teamNanospray){
				unsigned char* tcol=gs->Team(team)->color;
				fc = float3(tcol[0]*(1.f/255.f),tcol[1]*(1.f/255.f),tcol[2]*(1.f/255.f));
			}else{
				fc = unitDef->nanoColor;
			}
			glColorf3(fc*col);

			unitDrawer->UnitDrawingTexturesOff(model);

			double plane[4]={0,-1,0,start+height*buildProgress*3};
			glClipPlane(GL_CLIP_PLANE0 ,plane);
			double plane2[4]={0,1,0,-start-height*(buildProgress*10-9)};
			glClipPlane(GL_CLIP_PLANE1 ,plane2);
			glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
			localmodel->Draw();
			glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

			if(buildProgress>0.33f){
				glColorf3(fc*(1.5f-col));
				double plane[4]={0,-1,0,start+height*(buildProgress*3-1)};
				glClipPlane(GL_CLIP_PLANE0 ,plane);
				double plane2[4]={0,1,0,-start-height*(buildProgress*3-2)};
				glClipPlane(GL_CLIP_PLANE1 ,plane2);

				localmodel->Draw();
			}
			glDisable(GL_CLIP_PLANE1);
			unitDrawer->UnitDrawingTexturesOn(model);

			if(buildProgress>0.66f){
				double plane[4]={0,-1,0,start+height*(buildProgress*3-2)};
				glClipPlane(GL_CLIP_PLANE0 ,plane);
				if(shadowHandler->drawShadows && !water->drawReflection){
					glPolygonOffset(1,1);
					glEnable(GL_POLYGON_OFFSET_FILL);
				}
				localmodel->Draw();
				if(shadowHandler->drawShadows && !water->drawReflection){
					glDisable(GL_POLYGON_OFFSET_FILL);
				}
			}
			glDisable(GL_CLIP_PLANE0);
		}
	} else {
		localmodel->Draw();
	}

	if(gu->drawdebug){
		glPushMatrix();
		glTranslatef3(frontdir*relMidPos.z + updir*relMidPos.y + rightdir*relMidPos.x);
		GLUquadricObj* q=gluNewQuadric();
		gluQuadricDrawStyle(q,GLU_LINE);
		gluSphere(q,radius,10,10);
		gluDeleteQuadric(q);
		glPopMatrix();
	}/**/
	glPopMatrix();
}
void GLES_GPU::EndDebugDraw() {
#ifndef USING_GLES2
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
}
Esempio n. 9
0
/* Функция построения объекта анимации.
* АРГУМЕНТЫ:
*   - указатель на "себя" - сам объект анимации:
*       as3UNIT_MODEL *Uni;
*   - указатель на контекст анимации:
*       as3ANIM *Ani;
* ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет.
*/
static VOID AS3_AnimUnitRender(as3UNIT_MODEL *Uni, as3ANIM *Ani)
{
    static INT i = 0, j = 0, k = 0;
    if (Ani->JR > 0)
        k += 105;
    if (Ani->JR < -0.0002)
        k -= 105;
    if (Ani->JZ > 0)
        i += 105;
    if (Ani->JZ < -0.0002)
        i -= 105;
    if (Ani->JY > 0)
        j += 1000;
    AS3_RndMatrView = MatrView(VecSet(600 + k, 600 + k, 600 + k), VecSet(i, 0, i), VecSet(0, 1, 0));


    if (Ani->KeysClick['W'])
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    if (Ani->KeysClick['Q'])
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    if (Ani->KeysClick['S'])
        j = 1;
    glEnable(GL_DEPTH_TEST);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(0.00001141552511 * 365 * j * Ani->Time, 0, 1, 0),  //Земля
                                    MatrScale(100, 100, 100)),
                                MatrTranslate(0, -50, 1200)),
                    MatrRotateY(0.00001141552511 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId);
    AS3_GeomDraw(&Uni->Geom[0]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(0, 0, 1, 0),  //Солнце
                                    MatrScale(800, 800, 800)),
                                MatrTranslate(0, 0, 0)),
                    MatrRotateY(0));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId1);
    AS3_GeomDraw(&Uni->Geom[1]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(0.6 * 0.0004 * j *  Ani->Time, 0, 1, 0),  //Меркурий
                                    MatrScale(30, 30, 30)),
                                MatrTranslate(0, 0, 800)),
                    MatrRotateY(0.0004 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId2);
    AS3_GeomDraw(&Uni->Geom[2]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(-1.1 * 0.0001 * j * Ani->Time, 0, 1, 0),  //Венера
                                    MatrScale(100, 100, 100)),
                                MatrTranslate(0, 0, 1000)),
                    MatrRotateY(0.0001 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId3);
    AS3_GeomDraw(&Uni->Geom[3]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(669 * 0.000006 * j * Ani->Time, 0, 1, 0),  //Марс
                                    MatrScale(90, 90, 90)),
                                MatrTranslate(0, 0, 1500)),
                    MatrRotateY(0.000006 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId4);
    AS3_GeomDraw(&Uni->Geom[4]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(10683 * 0.0000009 * j * Ani->Time, 0, 1, 0),  //Юпитер
                                    MatrScale(500, 500, 500)),
                                MatrTranslate(0, 0, 1800)),
                    MatrRotateY(0.0000009 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId5);
    AS3_GeomDraw(&Uni->Geom[5]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(21170 * 0.0000004 * j * Ani->Time, 0, 1, 0),  //Сатурн
                                    MatrScale(400, 400, 400)),
                                MatrTranslate(0, 0, 2500)),
                    MatrRotateY(0.0000004 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId6);
    AS3_GeomDraw(&Uni->Geom[6]);
    /*
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
        MatrRotate(100 * Ani->Time, 0, 1, 0),  //0.004050925925925926
        MatrScale(10, 8, 10)),
        MatrTranslate(0, 0, 2500)),
        MatrRotateX(-90));
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, Uni->TextId61);
      AS3_GeomDraw(&Uni->Geom[7]);
    */
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(43800 * 0.0000001 * j * Ani->Time, 0, 1, 0),  //Уран
                                    MatrScale(350, 350, 350)),
                                MatrTranslate(0, 0, 3000)),
                    MatrRotateY(0.0000001 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId7);
    AS3_GeomDraw(&Uni->Geom[8]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(86036 * 0.00000007 * j * Ani->Time, 0, 1, 0),  //Нептун
                                    MatrScale(350, 350, 350)),
                                MatrTranslate(0, 0, 3500)),
                    MatrRotateY(0.00000007 * j * Ani->Time));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId8);
    AS3_GeomDraw(&Uni->Geom[9]);
    AS3_RndMatrWorld =
        MatrMulMatr(MatrMulMatr(MatrMulMatr(
                                    MatrRotate(0, 0, 1, 0),  // nebo
                                    MatrScale(20000, 20000, 20000)),
                                MatrTranslate(0, 0, 0)),
                    MatrRotateY(0));
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Uni->TextId9);
    AS3_GeomDraw(&Uni->Geom[10]);

} /* End of 'AS3_AnimUnitRender' function */
Esempio n. 10
0
bool COLLADA_Viewer::onUpdate()
{
	float tolerrance = 0.15;
	static float buttonTime = 0;
	static float cameraTime = 0;
	bool result = FWGLApplication::onUpdate();

	if (mRunning==false)
	   return result;

	FWTimeVal curTime = FWTime::getCurrentTime();

	if ((float)curTime - buttonTime > 0.15)	// execute these control base on time elapse, not frame rate
	{
		buttonTime = curTime;
		if(mpPad->getRawBool(FWInput::Channel_Button_Select))
		{
		  _CrtRender.SetNextCamera();
		  return result;
		} else if(mpPad->getRawBool(FWInput::Channel_Button_L3))
		{
		   if (Browser.IsVisible())
			   Browser.SetVisible(false);
		   else
			   Browser.SetVisible(true);
		} else if(mpPad->getRawBool(FWInput::Channel_Button_R3))
		{
			if (togglewireframe) {
				togglewireframe = false;
			} else {
				togglewireframe = true;
			}
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Square)) 
		{
			if (togglelighting) {
				togglelighting = false;
			} else {
				togglelighting = true;
			}
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Cross)) 
		{
			mCurrentFile = Browser.GetThumbnail(Browser.GetSelection())->GetDocument();
			load_ok = _CrtRender.Load(mCurrentFile, NULL);
			return result;
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Up))
		{
		   Browser.SelectPrev();
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Down))
		{
		   Browser.SelectNext();
		}
	}

	if ((float)curTime - cameraTime > 0.05)	// execute these control base on time elapse, not frame rate
	{
		cameraTime = curTime;
			   // Get the values from the analog sticks
	   float conditioned_X_0 = mpPad->getRawFloat(FWInput::Channel_XAxis_0);
	   float conditioned_Y_0 = mpPad->getRawFloat(FWInput::Channel_YAxis_0);
	   float conditioned_X_1 = mpPad->getRawFloat(FWInput::Channel_XAxis_1);
	   float conditioned_Y_1 = mpPad->getRawFloat(FWInput::Channel_YAxis_1);

	   if (-tolerrance < conditioned_X_0 && conditioned_X_0 < tolerrance) conditioned_X_0 = 0.0f;
	   if (-tolerrance < conditioned_Y_0 && conditioned_Y_0 < tolerrance) conditioned_Y_0 = 0.0f;
	   if (-tolerrance < conditioned_X_1 && conditioned_X_1 < tolerrance) conditioned_X_1 = 0.0f;
	   if (-tolerrance < conditioned_Y_1 && conditioned_Y_1 < tolerrance) conditioned_Y_1 = 0.0f;

	   conditioned_X_0 = mpInputX0 ? -mpInputX0->getFloatValue() : 0.f;
	   conditioned_Y_0 = mpInputY0 ? -mpInputY0->getFloatValue() : 0.f;
	   conditioned_X_1 = mpInputX1 ? -mpInputX1->getFloatValue() : 0.f;
	   conditioned_Y_1 = mpInputY1 ? -mpInputY1->getFloatValue() : 0.f;

	   float multiplier = 10.0f;
	   if (conditioned_X_0 != 0.0f || conditioned_Y_0 != 0.0f)
	   {
		  _CrtRender.ActiveInstanceCamera->MoveOrbit(conditioned_X_0 * multiplier, conditioned_Y_0 * multiplier);
	   }
	   if (conditioned_X_1 != 0.0f || conditioned_Y_1 != 0.0f)
	   {
		  _CrtRender.ActiveInstanceCamera->SetPanAndTilt(conditioned_X_1 * multiplier, conditioned_Y_1 * multiplier);
	   }
	}
	
	if(mpPad->getRawBool(FWInput::Channel_Button_L2))
	{  // zoom in
	  _CrtRender.ZoomIn(-0.005f);
	} else if(mpPad->getRawBool(FWInput::Channel_Button_L1))
	{  // zoom out
	  _CrtRender.ZoomIn(0.005f);
   	}
	
	if (togglewireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	} else {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}

	if (togglelighting) {
		glEnable(GL_LIGHTING);
	} else {
		glDisable(GL_LIGHTING);
	}


#if defined SPU_BULLET || !defined (SN_TARGET_PS3)

   if (mpPad->getRawBool(FWInput::Channel_Button_Triangle))
   {

	   float fl_x, fl_y, fl_z, fl_g;
	   fl_x = mpPad->getRawFloat(FWInput::Channel_XAxis_2);
	   fl_y = mpPad->getRawFloat(FWInput::Channel_YAxis_2);
	   fl_z = mpPad->getRawFloat(FWInput::Channel_ZAxis_2);
	   fl_g = mpPad->getRawFloat(FWInput::Channel_Gyro);

	   SixAxis(fl_x, fl_y, fl_z, fl_g);
   } else {
	    _CrtRender.SetGravity(CrtVec3f(0.0f, -10.0f, 0.0f));
   }
#endif
	static const int CONS_PUTS_INTERVAL = 50;

	if (frames % CONS_PUTS_INTERVAL == 0){
	}

	char title[1024];
	const char * selectedfile = Browser.GetThumbnail(Browser.GetSelection())->GetDocument();
	sprintf(title, "%s %s", "COLLADA Viewer", mCurrentFile);
	cellDbgFontPuts(0.1f, 0.1f, 1.0f, 0xffffffff, title);
	cellDbgFontPuts(0.1f, 0.9f, 1.0f, 0xffffffff, selectedfile);

	Browser.onUpdate();
	return result; 
}
Esempio n. 11
0
// OpenGL2 Render function.
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so. 
void ImGui_ImplSdlGL2_RenderDrawData(ImDrawData* draw_data)
{
    // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
    ImGuiIO& io = ImGui::GetIO();
    int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
    int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
    if (fb_width == 0 || fb_height == 0)
        return;
    draw_data->ScaleClipRects(io.DisplayFramebufferScale);

    // We are using the OpenGL fixed pipeline to make the example code simpler to read!
    // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
    GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
    GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
    GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
    GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); 
    glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_SCISSOR_TEST);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnable(GL_TEXTURE_2D);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound

    // Setup viewport, orthographic projection matrix
    glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0f, io.DisplaySize.x, io.DisplaySize.y, 0.0f, -1.0f, +1.0f);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    // Render command lists
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];
        const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
        const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)));
        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv)));
        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col)));

        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
        {
            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
            if (pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list, pcmd);
            }
            else
            {
                glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
                glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
                glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer);
            }
            idx_buffer += pcmd->ElemCount;
        }
    }

    // Restore modified state
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture);
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glPopAttrib();
    glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]);
    glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
    glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
}
Esempio n. 12
0
////////////////////////////////////////////////////////////////////////
///
/// @fn void Modele3D::appliquerMateriau( const aiMaterial* materiau )
///
/// Cette fonction applique un matériau 'assimp' à l'état OpenGL 
/// courant (puisque certains meshes peuvent en dépendre). Le code est
/// chaotique; rassurons-nous cette fonction ne fait qu'effectuer
/// des appels OpenGL selon l'état de la structure interne du matériau
/// 'assimp' ainsi que quelques calculs.
///
/// @param[in] materiau : matériau 'assimp' à appliquer
///
/// @return Aucune.
///
////////////////////////////////////////////////////////////////////////
void Modele3D::appliquerMateriau(const aiMaterial* materiau)
{
	// Obtenir la texture du matériau
	int indexTexture = 0;
	aiString nomFichier = "";
	
	glMatrixMode(GL_TEXTURE);
	glPushMatrix();

	if (materiau->GetTexture(aiTextureType_DIFFUSE, indexTexture, &nomFichier) == AI_SUCCESS) {
		// Activer le texturage OpenGL et lier la texture appropriée
		glEnable ( GL_TEXTURE_2D);
		GLuint* idTexture = mapTextures_[nomFichier.data];
		glScalef(1.0,-1.0,1.0);
		glBindTexture(GL_TEXTURE_2D, *idTexture);
	}
	else {
		// Désactiver le texturage OpenGL puisque cet objet n'a aucune texture
		glDisable ( GL_TEXTURE_2D);
	}

	glMatrixMode(GL_MODELVIEW);

	// Autres paramètres à appliquer... (couleurs)
	float c[4];
	GLenum fill_mode;
	int ret1, ret2;
	struct aiColor4D diffuse;
	struct aiColor4D specular;
	struct aiColor4D ambient;
	struct aiColor4D emission;
	float shininess, strength;
	int two_sided;
	int wireframe;
	unsigned int max;	// changé pour: unsigned
	assignerFloat4(c, 0.8f, 0.8f, 0.8f, 1.0f);
	//assignerFloat4(c, 1.0f, 1.0f, 1.0f, 1.0f);
	
	
	if (aiGetMaterialColor(materiau, AI_MATKEY_COLOR_DIFFUSE, &diffuse) == AI_SUCCESS)
		couleurVersFloat4(&diffuse, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
	
	assignerFloat4(c, 0.0f, 0.0f, 0.0f, 1.0f);
	if(AI_SUCCESS == aiGetMaterialColor(materiau, AI_MATKEY_COLOR_SPECULAR, &specular))
		couleurVersFloat4(&specular, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);

	assignerFloat4(c, 0.2f, 0.2f, 0.2f, 1.0f);
	if(AI_SUCCESS == aiGetMaterialColor(materiau, AI_MATKEY_COLOR_AMBIENT, &ambient))
		couleurVersFloat4(&ambient, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);

	assignerFloat4(c, 0.0f, 0.0f, 0.0f, 1.0f);
	if(AI_SUCCESS == aiGetMaterialColor(materiau, AI_MATKEY_COLOR_EMISSIVE, &emission))
		couleurVersFloat4(&emission, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c);
	
	max = 1;
	ret1 = aiGetMaterialFloatArray(materiau, AI_MATKEY_SHININESS, &shininess, &max);
	max = 1;
	ret2 = aiGetMaterialFloatArray(materiau, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
	if((ret1 == AI_SUCCESS) && (ret2 == AI_SUCCESS))
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);
	else {
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
		assignerFloat4(c, 0.0f, 0.0f, 0.0f, 0.0f);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
	


	}


	
	
	max = 1;
	if(AI_SUCCESS == aiGetMaterialIntegerArray(materiau, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max))
		fill_mode = wireframe ? GL_LINE : GL_FILL;
	else
		fill_mode = GL_FILL;
	glPolygonMode(GL_FRONT_AND_BACK, fill_mode);

	max = 1;
	if((AI_SUCCESS == aiGetMaterialIntegerArray(materiau, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided)
		glEnable(GL_CULL_FACE);
	else
		glDisable(GL_CULL_FACE);

}
Esempio n. 13
0
	// Tasta apasata
	void notifyKeyPressed(unsigned char key_pressed, int mouse_x, int mouse_y) {
		
		if(key_pressed == 27) lab::glut::close();	// ESC inchide glut.
		if(key_pressed == 32) {
			// SPACE reincarca shaderul si recalculeaza locatiile (offseti/pointeri)
			glDeleteProgram(gl_program_shader);
			gl_program_shader = lab::loadShader("shadere\\shader_vertex.glsl", "shadere\\shader_fragment.glsl");
		}
		if (key_pressed == 'a') {
			if (main_character->atDestination()) {
				// Plasez personaj principal si generez unul nou.
				glm::vec3 pos = main_character->getPosition();
				quad->setOccupied((int)ceil(pos.x - 1), (int)ceil(pos.z - 1));
				main_character->setInactive();
				main_character = new Character(MAIN_ACTIVE, main_slope, obj_build, quad);
				characters.push_back(main_character);
				delete cams[0];
				cams[0] = main_character->getFpsCam();
				delete cams[4];
				cams[4] = main_character->getTpsCam();
			}
		}
		if (key_pressed == 'r') {	// Opreste cutremur.
			x_quake = -1;
		}
		if (key_pressed == 'e') {	// Incepe cutremur.
			if (x_quake <= -1) {
				amplitude = 0.2 + ((double)rand() / RAND_MAX) * 0.8;	// intre 0.2 si 1.
				frequency = rand() % 50;
				x_quake = 0;
			}

		}
		if (key_pressed == 'c') {	// Comuta intre camere.
			cam_index = (cam_index + 1) % 7;
		}
		if (key_pressed == 'w') {	// Desenare wireframe.
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		}
		if (key_pressed == 's') {	// Desenare solid.
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		}
		// Taste pentru deplasarea camerei FPS de sus.
		if (key_pressed == 't') {
			if (cam_index == 6)
				cams[6]->translateForward(1.0f);
		}
		if (key_pressed == 'y') {
			if (cam_index == 6)
				cams[6]->translateForward(-1.0f);
		}
		if (key_pressed == 'u') {
			if (cam_index == 6)
				cams[6]->translateUpword(1.0f);
		}
		if (key_pressed == 'i') {
			if (cam_index == 6)
				cams[6]->translateUpword(-1.0f);
		}
		if (key_pressed == 'o') {
			if (cam_index == 6)
				cams[6]->translateRight(-1.0f);
		}
		if (key_pressed == 'p') {
			if (cam_index == 6)
				cams[6]->translateRight(1.0f);
		}
		if (key_pressed == '1') {
			if (cam_index == 6)
				cams[6]->rotateFPSoX(1.0f);
		}
		if (key_pressed == '2') {
			if (cam_index == 6)
				cams[6]->rotateFPSoX(-1.0f);
		}
		if (key_pressed == '3') {
			if (cam_index == 6)
				cams[6]->rotateFPSoY(1.0f);
		}
		if (key_pressed == '4') {
			if (cam_index == 6)
				cams[6]->rotateFPSoY(-1.0f);
		}
		if (key_pressed == '5') {
			if (cam_index == 6)
				cams[6]->rotateFPSoZ(1.0f);
		}
		if (key_pressed == '6') {
			if (cam_index == 6)
				cams[6]->rotateFPSoZ(-1.0f);
		}
		if (key_pressed == 'q') {			// Schimba modul special cu modul normal si invers.
			special_mode = !special_mode;
			for (int i = 0; i < characters.size(); ++i) {
				delete characters[i];
			}
			for (int i = 0; i < cams.size(); ++i) {
				delete cams[i];
			}
			cams.clear();
			characters.clear();
			init();
		}
	}
Esempio n. 14
0
void
keyboard(unsigned char key, int x, int y)
{
  GLint params[2];
    
  switch (key) {
  case 'h':
    printf("help\n\n");
    printf("w         -  Toggle wireframe/filled\n");
    printf("c         -  Toggle culling\n");
    printf("n         -  Toggle facet/smooth normal\n");
    printf("b         -  Toggle bounding box\n");
    printf("r         -  Reverse polygon winding\n");
    printf("m         -  Toggle color/material/none mode\n");
    printf("p         -  Toggle performance indicator\n");
    printf("s/S       -  Scale model smaller/larger\n");
    printf("t         -  Show model stats\n");
    printf("o         -  Weld vertices in model\n");
    printf("+/-       -  Increase/decrease smoothing angle\n");
    printf("W         -  Write model to file (out.obj)\n");
    printf("q/escape  -  Quit\n\n");
    break;
        
  case 't':
    stats = !stats;
    break;
        
  case 'p':
    performance = !performance;
    break;
        
  case 'm':
    material_mode++;
    if (material_mode > 2)
      material_mode = 0;
    printf("material_mode = %d\n", material_mode);
    lists();
    break;
        
  case 'd':
    glmDelete(model);
    init();
    lists();
    break;
        
  case 'w':
    glGetIntegerv(GL_POLYGON_MODE, params);
    if (params[0] == GL_FILL)
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    else
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);


    break;
        
  case 'c':
    if (glIsEnabled(GL_CULL_FACE))
      glDisable(GL_CULL_FACE);
    else
      glEnable(GL_CULL_FACE);
    break;
        
  case 'b':
    bounding_box = !bounding_box;
    break;
        
  case 'n':
    facet_normal = !facet_normal;
    lists();
    break;
        
  case 'r':
    glmReverseWinding(model);
    lists();
    break;
        
  case 's':
    glmScale(model, 0.8);
    lists();
    break;
        
  case 'S':
    glmScale(model, 1.25);
    lists();
    break;
        
  case 'o':
    //printf("Welded %d\n", glmWeld(model, weld_distance));
    glmVertexNormals(model, smoothing_angle);
    lists();
    break;
        
  case 'O':
    weld_distance += 0.01;
    printf("Weld distance: %.2f\n", weld_distance);
    glmWeld(model, weld_distance);
    glmFacetNormals(model);
    glmVertexNormals(model, smoothing_angle);
    lists();
    break;
        
  case '-':
    smoothing_angle -= 1.0;
    printf("Smoothing angle: %.1f\n", smoothing_angle);
    glmVertexNormals(model, smoothing_angle);
    lists();
    break;
        
  case '+':
    smoothing_angle += 1.0;
    printf("Smoothing angle: %.1f\n", smoothing_angle);
    glmVertexNormals(model, smoothing_angle);
    lists();
    break;
        
  case 'W':
    glmScale(model, 1.0/scale);
    glmWriteOBJ(model, "out.obj", GLM_SMOOTH | GLM_MATERIAL);
    break;
        
  case 'R':
    {
      GLuint i;
      GLfloat swap;
      for (i = 1; i <= model->numvertices; i++) {
	swap = model->vertices[3 * i + 1];
	model->vertices[3 * i + 1] = model->vertices[3 * i + 2];
	model->vertices[3 * i + 2] = -swap;
      }
      glmFacetNormals(model);
      lists();
      break;
    }
        
  case 27:
    exit(0);
    break;
  case 'y' : 

    //           model->numtriangles = 1;

    build_data_structure(); 
    
    //    model->numtriangles =6;
    //if(!start)
    start++;
      
      
  }
    
  glutPostRedisplay();
}
Esempio n. 15
0
void	KeyHandler(unsigned char key, int x, int y)
{
	// Set the speed level of the viewer.
	if (key >= '0' && key <= '9') {
		Speed = 1 << (key - '0');
	}

	// Toggle wireframe on 'w'.
	static bool	Wireframe = false;
	if (key == 'w') {
		Wireframe = !Wireframe;
		if (Wireframe) {
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		} else {
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		}
	}

	// Toggle backface culling on 'c'.
	static bool	BackfaceCulling = false;
	if (key == 'c') {
		BackfaceCulling = !BackfaceCulling;
		if (BackfaceCulling) {
			glCullFace(GL_BACK);
			glEnable(GL_CULL_FACE);
		} else {
			glDisable(GL_CULL_FACE);
		}
	}
	
	// Toggle texturing on 't' input.
	static unsigned int	TextureName = 0;
	if (key == 't') {
		Textured = !Textured;

		if (Textured) {
			if (TextureName == 0) {
				// Load and create texture.
				glGenTextures(1, &TextureName);
				glBindTexture(GL_TEXTURE_2D, TextureName);

				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
				
				char*	data = new char[1024 * 1024 * 3];
				FILE*	fp = fopen("demdata/gctexcolored.raw", "rb");
				fread(data, 1, 1024 * 1024 * 3, fp);
				fclose(fp);
				
				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
				gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 1024, 1024, GL_RGB, GL_UNSIGNED_BYTE, data);

				delete [] data;
				
				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			}

			glBindTexture(GL_TEXTURE_2D, TextureName);
			glEnable(GL_TEXTURE_2D);

			glColor3f(1, 1, 1);
		} else {
			glDisable(GL_TEXTURE_2D);
		}
	}

	// Toggle PinToGround mode on 'p'.
	if (key == 'p') {
		PinToGround = !PinToGround;

		if (PinToGround) {
			ViewerHeight = ViewerLoc.Y() - root->GetHeight(RootCornerData, ViewerLoc.X(), ViewerLoc.Z());
		}
	}

	// Toggle MoveForward mode on 'm'.
	if (key == 'm') {
		MoveForward = !MoveForward;
	}


	// =/- keys adjust the detail threshold.
	if (key == '-') {
		Detail *= 0.9;
		if (Detail < 10) Detail = 10;
		printf("DetailThreshold = %g\n", Detail);
	}
	if (key == '=') {
		Detail *= 1.11111111;
		if (Detail > 1500) Detail = 1500;
		printf("DetailThreshold = %g\n", Detail);
	}
	

	// On 'd', hijack the app for a second while we run some
	// performance tests.  Because of limitations in GLUT, Idle()
	// only gets called up to 18 times a second, so we can't get
	// good performance numbers that way.
	if (key == 'd') {
		int	StartTicks = glutGet(GLUT_ELAPSED_TIME);
		int	ticks;
		TriangleCounter = 0;
		int	FrameCounter = 0;
		int	TrisPerFrame = 0;

		// For approximately one second, render frames as fast as we can.
		for (;;) {
			Display();
			FrameCounter++;
			if (FrameCounter == 1) TrisPerFrame = TriangleCounter;
			
			ticks = glutGet(GLUT_ELAPSED_TIME);
			if (ticks - StartTicks > 1000) break;
		}

		// Show the fps and tps results.
		float	dt = (ticks - StartTicks) / 1000.0;
		printf("Rendered %0.1f frames/sec, %d tris/frame, %d tris/sec\n", FrameCounter / dt, TrisPerFrame, int(TriangleCounter / dt));
	}
}
Esempio n. 16
0
void Model::renderMesh(bool bWireframe, bool bLight)
{
  // get the renderer of the model
  CalRenderer *pCalRenderer;
  pCalRenderer = m_calModel->getRenderer();

  // begin the rendering loop
  if(!pCalRenderer->beginRendering()) return;

  // set wireframe mode if necessary
  if(bWireframe)
  {
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  }

  // set the global OpenGL states
  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_SMOOTH);

  // set the lighting mode if necessary
  if(bLight)
  {
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
  }

  // we will use vertex arrays, so enable them
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);

  // get the number of meshes
  int meshCount;
  meshCount = pCalRenderer->getMeshCount();

  // render all meshes of the model
  int meshId;
  for(meshId = 0; meshId < meshCount; meshId++)
  {
    // get the number of submeshes
    int submeshCount;
    submeshCount = pCalRenderer->getSubmeshCount(meshId);

    // render all submeshes of the mesh
    int submeshId;
    for(submeshId = 0; submeshId < submeshCount; submeshId++)
    {
      // select mesh and submesh for further data access
      if(pCalRenderer->selectMeshSubmesh(meshId, submeshId))
      {
        unsigned char meshColor[4];
        GLfloat materialColor[4];

        // set the material ambient color
        pCalRenderer->getAmbientColor(&meshColor[0]);
        materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
        glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor);

        // set the material diffuse color
        pCalRenderer->getDiffuseColor(&meshColor[0]);
        materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
        glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColor);

        // set the vertex color if we have no lights
        if(!bLight)
        {
          glColor4fv(materialColor);
        }

        // set the material specular color
        pCalRenderer->getSpecularColor(&meshColor[0]);
        materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
        glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor);

        // set the material shininess factor
        float shininess;
        shininess = 50.0f; //TODO: pCalRenderer->getShininess();
        glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);

        // get the transformed vertices of the submesh
        static float meshVertices[30000][3];
        int vertexCount;
        vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);

        // get the transformed normals of the submesh
        static float meshNormals[30000][3];
        pCalRenderer->getNormals(&meshNormals[0][0]);

        // get the texture coordinates of the submesh
        static float meshTextureCoordinates[30000][2];
        int textureCoordinateCount;
        textureCoordinateCount = pCalRenderer->getTextureCoordinates(0, &meshTextureCoordinates[0][0]);

        // get the faces of the submesh
        static CalIndex meshFaces[50000][3];
        int faceCount;
        faceCount = pCalRenderer->getFaces(&meshFaces[0][0]);

        // set the vertex and normal buffers
        glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
        glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);

        // set the texture coordinate buffer and state if necessary
        if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
        {
          glEnable(GL_TEXTURE_2D);
          glEnableClientState(GL_TEXTURE_COORD_ARRAY);
          glEnable(GL_COLOR_MATERIAL);

          // set the texture id we stored in the map user data
          glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));

          // set the texture coordinate buffer
          glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]);
          glColor3f(1.0f, 1.0f, 1.0f);
        }

        // draw the submesh
        
        if(sizeof(CalIndex)==2)
			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
		  else
			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);

        // disable the texture coordinate state if necessary
        if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
        {
          glDisable(GL_COLOR_MATERIAL);
          glDisableClientState(GL_TEXTURE_COORD_ARRAY);
          glDisable(GL_TEXTURE_2D);
        }
      }
    }
  }

  // clear vertex array state
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);

  // reset the lighting mode
  if(bLight)
  {
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
  }

  // reset the global OpenGL states
  glDisable(GL_DEPTH_TEST);

  // reset wireframe mode if necessary
  if(bWireframe)
  {
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  }

  // end the rendering
  pCalRenderer->endRendering();
}
Esempio n. 17
0
static void
key(unsigned char k, int x, int y)
{
   switch (k) {
   case 27:
      exit(0);
      break;

   case 's':
      lightpos[1] -= 0.1;
      break;
   case 'd':
      lightpos[1] += 0.1;
      break;
   case 'e':
      lightpos[0] -= 0.1;
      break;
   case 'x':
      lightpos[0] += 0.1;
      break;
   case 'w':
      lightpos[2] -= 0.1;
      break;
   case 'r':
      lightpos[2] += 0.1;
      break;

   case 'j':
      objpos[1] -= 0.1;
      break;
   case 'k':
      objpos[1] += 0.1;
      break;
   case 'i':
      objpos[0] -= 0.1;
      break;
   case 'm':
      objpos[0] += 0.1;
      break;
   case 'u':
      objpos[2] -= 0.1;
      break;
   case 'o':
      objpos[2] += 0.1;
      break;

   case 'a':
      v += 0.005;
      break;
   case 'z':
      v -= 0.005;
      break;

   case 'g':
      joyactive = (!joyactive);
      break;
   case 'h':
      help = (!help);
      break;
   case 'f':
      fog = (!fog);
      break;

   case '1':
      showcheckmap = (!showcheckmap);
      break;
   case '2':
      showreflectmap = (!showreflectmap);
      break;

   case 'b':
      if (bfcull) {
	 glDisable(GL_CULL_FACE);
	 bfcull = 0;
      }
      else {
	 glEnable(GL_CULL_FACE);
	 bfcull = 1;
      }
      break;
   case 'p':
      if (poutline) {
	 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	 poutline = 0;
      }
      else {
	 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	 poutline = 1;
      }
      break;
#ifdef XMESA
   case ' ':
      XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW);
      fullscreen = (!fullscreen);
      break;
#endif
   }
}
Esempio n. 18
0
void ARDrawingContext::drawCubeModel()
{
  static const GLfloat LightAmbient[]=  { 0.25f, 0.25f, 0.25f, 1.0f };    // Ambient Light Values
  static const GLfloat LightDiffuse[]=  { 0.1f, 0.1f, 0.1f, 1.0f };    // Diffuse Light Values
  static const GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };    // Light Position
  
  glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT);

  glColor4f(0.2f,0.35f,0.3f,0.75f);         // Full Brightness, 50% Alpha ( NEW )
  glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);       // Blending Function For Translucency Based On Source Alpha 
  glEnable(GL_BLEND); 

  glShadeModel(GL_SMOOTH);

  glEnable(GL_LIGHTING);
  glDisable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
  glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
  glEnable(GL_COLOR_MATERIAL);

  glScalef(0.25,0.25, 0.25);
  glTranslatef(0,0, 1);

  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glBegin(GL_QUADS); 
  // Front Face
  glNormal3f( 0.0f, 0.0f, 1.0f);    // Normal Pointing Towards Viewer
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 1 (Front)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 2 (Front)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Front)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 4 (Front)
  // Back Face
  glNormal3f( 0.0f, 0.0f,-1.0f);    // Normal Pointing Away From Viewer
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Back)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 2 (Back)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 3 (Back)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 4 (Back)
  // Top Face
  glNormal3f( 0.0f, 1.0f, 0.0f);    // Normal Pointing Up
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 1 (Top)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 2 (Top)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Top)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 4 (Top)
  // Bottom Face
  glNormal3f( 0.0f,-1.0f, 0.0f);    // Normal Pointing Down
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Bottom)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 2 (Bottom)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 3 (Bottom)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 4 (Bottom)
  // Right face
  glNormal3f( 1.0f, 0.0f, 0.0f);    // Normal Pointing Right
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 1 (Right)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 2 (Right)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Right)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 4 (Right)
  // Left Face
  glNormal3f(-1.0f, 0.0f, 0.0f);    // Normal Pointing Left
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Left)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 2 (Left)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 3 (Left)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 4 (Left)
  glEnd();
  
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  glColor4f(0.2f,0.65f,0.3f,0.35f); // Full Brightness, 50% Alpha ( NEW )
  glBegin(GL_QUADS); 
  // Front Face
  glNormal3f( 0.0f, 0.0f, 1.0f);    // Normal Pointing Towards Viewer
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 1 (Front)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 2 (Front)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Front)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 4 (Front)
  // Back Face
  glNormal3f( 0.0f, 0.0f,-1.0f);    // Normal Pointing Away From Viewer
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Back)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 2 (Back)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 3 (Back)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 4 (Back)
  // Top Face
  glNormal3f( 0.0f, 1.0f, 0.0f);    // Normal Pointing Up
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 1 (Top)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 2 (Top)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Top)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 4 (Top)
  // Bottom Face
  glNormal3f( 0.0f,-1.0f, 0.0f);    // Normal Pointing Down
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Bottom)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 2 (Bottom)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 3 (Bottom)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 4 (Bottom)
  // Right face
  glNormal3f( 1.0f, 0.0f, 0.0f);    // Normal Pointing Right
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 1 (Right)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 2 (Right)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Right)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 4 (Right)
  // Left Face
  glNormal3f(-1.0f, 0.0f, 0.0f);    // Normal Pointing Left
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Left)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 2 (Left)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 3 (Left)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 4 (Left)
  glEnd();
 
  glPopAttrib();
}
Esempio n. 19
0
void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas)
{
	bool need_depth=false;
	bool need_luminance=false;
	int num_filters = 0;

	int passindex;

	if (!isshadersupported)
		return;

	for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
	{
		if (m_filters[passindex] && m_enabled[passindex]) {
			num_filters ++;
			if (texflag[passindex] & 0x1)
				need_depth = true;
			if (texflag[passindex] & 0x2)
				need_luminance = true;
			if (need_depth && need_luminance)
				break;
		}
	}

	if (num_filters <= 0)
		return;

	const int *viewport = canvas->GetViewPort();
	RAS_Rect rect = canvas->GetWindowArea();
	int rect_width = rect.GetWidth()+1, rect_height = rect.GetHeight()+1;

	if (texturewidth != rect_width || textureheight != rect_height)
	{
		UpdateOffsetMatrix(canvas);
		UpdateCanvasTextureCoord(viewport);
		need_tex_update = true;
	}
	
	if (need_tex_update)
	{
		SetupTextures(need_depth, need_luminance);
		need_tex_update = false;
	}

	if (need_depth) {
		glActiveTextureARB(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, texname[1]);
		glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, rect.GetLeft(), rect.GetBottom(), rect_width, rect_height, 0);
	}
	
	if (need_luminance) {
		glActiveTextureARB(GL_TEXTURE2);
		glBindTexture(GL_TEXTURE_2D, texname[2]);
		glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, rect.GetLeft(), rect.GetBottom(), rect_width, rect_height, 0);
	}

	// reverting to texunit 0, without this we get bug [#28462]
	glActiveTextureARB(GL_TEXTURE0);
	canvas->SetViewPort(0, 0, rect_width-1, rect_height-1);

	// We do this to make side-by-side stereo rendering work correctly with 2D filters. It would probably be nicer to just set the viewport,
	// but it can be easier for writing shaders to have the coordinates for the whole screen instead of just part of the screen. 
	RAS_Rect scissor_rect = canvas->GetDisplayArea();
	glScissor(scissor_rect.GetLeft() + viewport[0],
	          scissor_rect.GetBottom() + viewport[1],
	          scissor_rect.GetWidth() + 1,
	          scissor_rect.GetHeight() + 1);

	glDisable(GL_DEPTH_TEST);
	// in case the previous material was wire
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	// if the last rendered face had alpha add it would messes with the color of the plane we apply 2DFilter to
	glDisable(GL_BLEND); 
	// fix for [#34523] alpha buffer is now available for all OSs
	glDisable(GL_ALPHA_TEST);

	glPushMatrix();		//GL_MODELVIEW
	glLoadIdentity();	// GL_MODELVIEW
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
	{
		if (m_filters[passindex] && m_enabled[passindex])
		{
			StartShaderProgram(passindex);

			glActiveTextureARB(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, texname[0]);
			glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rect.GetLeft(), rect.GetBottom(), rect_width, rect_height, 0); // Don't use texturewidth and textureheight in case we don't have NPOT support
			glClear(GL_COLOR_BUFFER_BIT);

			glBegin(GL_QUADS);
				glColor4f(1.f, 1.f, 1.f, 1.f);
				glTexCoord2f(1.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[1], canvascoord[3]); glVertex2f(1,1);
				glTexCoord2f(0.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[0], canvascoord[3]); glVertex2f(-1,1);
				glTexCoord2f(0.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[0], canvascoord[2]); glVertex2f(-1,-1);
				glTexCoord2f(1.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[1], canvascoord[2]); glVertex2f(1,-1);
			glEnd();
		}
	}

	glEnable(GL_DEPTH_TEST);
	//We can't pass the results of canvas->GetViewPort() directly because canvas->SetViewPort() does some extra math [#34517]
	canvas->SetViewPort(0, 0, viewport[2]-1, viewport[3]-1);
	EndShaderProgram();
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}
Esempio n. 20
0
void View::draw_continuous_scale(char* title, bool righttext)
{
  int i;
  double y0 = scale_y + scale_height;

  set_ortho_projection(true);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
  glDisable(GL_TEXTURE_1D);
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  // background
  const int b = 5;
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glColor4f(1.0f, 1.0f, 1.0f, 0.65f);
  int rt = righttext ? 0 : labels_width + 8;
  glBegin(GL_QUADS);
  glVertex2d(scale_x - b - rt, y0 + 5 + b);
  glVertex2d(scale_x + scale_width + 8 + labels_width + b - rt, y0 + 5 + b);
  glVertex2d(scale_x + scale_width + 8 + labels_width + b - rt, scale_y - 5 - b);
  glVertex2d(scale_x - b - rt, scale_y - 5 - b);
  glEnd();

  // palette
  glDisable(GL_BLEND);
  glColor3f(0.0f, 0.0f, 0.0f);
  glBegin(GL_QUADS);
  glVertex2d(scale_x, scale_y);
  glVertex2d(scale_x, scale_y + scale_height + 1);
  glVertex2d(scale_x + scale_width + 1, scale_y + scale_height + 1);
  glVertex2d(scale_x + scale_width + 1, scale_y);
  glEnd();

  glEnable(GL_TEXTURE_1D);
  glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  glBegin(GL_QUADS);
  glTexCoord1d(tex_scale + tex_shift);
  glVertex2d(scale_x + 1, scale_y + 1);
  glVertex2d(scale_x + scale_width, scale_y + 1);
  glTexCoord1d(tex_shift);
  glVertex2d(scale_x + scale_width, scale_y + scale_height);
  glVertex2d(scale_x + 1, scale_y + scale_height);
  glEnd();

  // focus
  glDisable(GL_TEXTURE_1D);
  if (scale_focused)
  {
    glEnable(GL_BLEND);
    glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
    glBegin(GL_QUADS);
    glVertex2d(scale_x + 1, scale_y + 1);
    glVertex2d(scale_x + scale_width, scale_y + 1);
    glVertex2d(scale_x + scale_width, scale_y + scale_height);
    glVertex2d(scale_x + 1, scale_y + scale_height);
    glEnd();
  }

  // ticks
  glColor3f(0, 0, 0);
  glDisable(GL_BLEND);
  glDisable(GL_LINE_STIPPLE);
  glLineWidth(1.0);
  glBegin(GL_LINES);
  for (i = 0; i < scale_numticks; i++)
  {
    y0 = scale_y + scale_height - (double) (i+1) * scale_height / (scale_numticks+1);
    glVertex2d(scale_x, y0);
    glVertex2d(scale_x + 0.2 * scale_width + 1, y0);
    glVertex2d(scale_x + 0.8 * scale_width, y0);
    glVertex2d(scale_x + scale_width, y0);
  }
  glEnd();

  // labels
  for (i = 0; i <= scale_numticks+1; i++)
  {
    double value = range_min + (double) i * (range_max - range_min) / (scale_numticks+1);
    if (fabs(value) < 1e-8) value = 0.0;
    char text[50];
    sprintf(text, scale_fmt, value);
    y0 = scale_y + scale_height - (double) i * scale_height / (scale_numticks+1);
    if (righttext)
      draw_text(scale_x + scale_width + 8, y0, text);
    else
      draw_text(scale_x - 8, y0, text, 1);
  }
}
Esempio n. 21
0
void OpenGL::InitEnvironment(void)
{
	// ライティングの設定
	m_ambientLight0[0] = 1.0f;		// 環境光
	m_ambientLight0[1] = 1.0f;
	m_ambientLight0[2] = 1.0f;
	m_ambientLight0[3] = 0.5f;

	m_diffuseLight0[0] = 1.0f;		// 拡散光
	m_diffuseLight0[1] = 1.0f;
	m_diffuseLight0[2] = 1.0f;
	m_diffuseLight0[3] = 1.0f;

	m_specularLight0[0] = 1.0f;		// 鏡面光
	m_specularLight0[1] = 1.0f;
	m_specularLight0[2] = 1.0f;
	m_specularLight0[3] = 1.0f;

	m_positionLight0[0] = 0.0f;		// 光源位置
	m_positionLight0[1] = -0.5f;
	m_positionLight0[2] = 1.0f;
	m_positionLight0[3] = 1.0f;

	m_directionLight0[0] = 0.0f;	// スポットライト方向
	m_directionLight0[1] = 0.0f;
	m_directionLight0[2] = -1.0f;

	// マテリアルの色の設定
	materialAmbDiffRed[0] = 1.0f;
	materialAmbDiffRed[1] = 0.0f;
	materialAmbDiffRed[2] = 0.0f;
	materialAmbDiffRed[3] = 1.0f;

	materialAmbDiffGreen[0] = 0.0f;
	materialAmbDiffGreen[1] = 1.0f;
	materialAmbDiffGreen[2] = 0.0f;
	materialAmbDiffGreen[3] = 1.0f;

	materialAmbDiffBlue[0] = 0.0f;
	materialAmbDiffBlue[1] = 0.0f;
	materialAmbDiffBlue[2] = 1.0f;
	materialAmbDiffBlue[3] = 1.0f;

	materialAmbDiffYellow[0] = 1.0f;
	materialAmbDiffYellow[1] = 0.8f;
	materialAmbDiffYellow[2] = 0.0f;
	materialAmbDiffYellow[3] = 1.0f;

	materialAmbDiffBlack[0] = 0.0f;
	materialAmbDiffBlack[1] = 0.0f;
	materialAmbDiffBlack[2] = 0.0f;
	materialAmbDiffBlack[3] = 1.0f;

	materialAmbDiffGray[0] = 0.6f;
	materialAmbDiffGray[1] = 0.6f;
	materialAmbDiffGray[2] = 0.6f;
	materialAmbDiffGray[3] = 0.5f;

	materialAmbDiffWhite[0] = 1.0f;
	materialAmbDiffWhite[1] = 1.0f;
	materialAmbDiffWhite[2] = 1.0f;
	materialAmbDiffWhite[3] = 1.0f;

	materialAmbDiffSky[0] = 0.0f;
	materialAmbDiffSky[1] = 0.7f;
	materialAmbDiffSky[2] = 1.0f;
	materialAmbDiffSky[3] = 1.0f;

	materialAmbDiffOrange[0] = 1.0f;
	materialAmbDiffOrange[1] = 0.5f;
	materialAmbDiffOrange[2] = 0.0f;
	materialAmbDiffOrange[3] = 1.0f;

	materialAmbDiffPurple[0] = 1.0f;
	materialAmbDiffPurple[1] = 0.0f;
	materialAmbDiffPurple[2] = 1.0f;
	materialAmbDiffPurple[3] = 1.0f;

	glPolygonMode(GL_FRONT_AND_BACK, GL_POLYGON);//0608009 doi test
	return;
}
Esempio n. 22
0
void View::draw_discrete_scale(int numboxes, const char* boxnames[], const float boxcolors[][3])
{
  set_ortho_projection(true);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
  glDisable(GL_TEXTURE_1D);
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  // background
  const int b = 5;
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glColor4f(1.0f, 1.0f, 1.0f, 0.65f);
  glBegin(GL_QUADS);
  glVertex2d(scale_x - b, scale_y - b);
  glVertex2d(scale_x - b, scale_y + scale_height + b+1);
  glVertex2d(scale_x + scale_width + b+1, scale_y + scale_height + b+1);
  glVertex2d(scale_x + scale_width + b+1, scale_y - b);
  glEnd();

  // boxes
  glDisable(GL_BLEND);
  int y = scale_y;
  for (int i = 0; i < numboxes; i++)
  {
    glColor3f(0.0, 0.0, 0.0);
    glBegin(GL_QUADS);
    glVertex2d(scale_x, y);
    glVertex2d(scale_x, y + scale_box_height + 1);
    glVertex2d(scale_x + scale_width + 1, y + scale_box_height + 1);
    glVertex2d(scale_x + scale_width + 1, y);
    glEnd();

    const float* color = boxcolors[numboxes-1-i];
    float bcolor[3] = { color[0], color[1], color[2] };
    if (scale_focused) {
      bcolor[0] = color[0]*0.7f + 1.0f*0.3f;
      bcolor[1] = color[1]*0.7f + 1.0f*0.3f;
      bcolor[2] = color[2]*0.7f + 1.0f*0.3f;
    }

    glColor3f(bcolor[0], bcolor[1], bcolor[2]);
    glBegin(GL_QUADS);
    glVertex2d(scale_x+1, y+1);
    glVertex2d(scale_x+1, y + scale_box_height);
    glVertex2d(scale_x + scale_width, y + scale_box_height);
    glVertex2d(scale_x + scale_width, y+1);
    glEnd();

    if ((color[0] + color[1] + color[2]) / 3 > 0.5)
      glColor3f(0, 0, 0);
    else
      glColor3f(1, 1, 1);

    int a = scale_x + scale_width/2;
    int b = y + scale_box_height/2;
    draw_text(a, b, boxnames[numboxes-1-i], 0);
    draw_text(a+1, b, boxnames[numboxes-1-i], 0);

    y += scale_box_height + scale_box_skip;
  }
}
Esempio n. 23
0
void smoke(void) {
	int i, j, k, idx;
	double px, py;
	fftw_real  wn = (fftw_real)winWidth / (fftw_real)(DIM + 1);   // Grid cell width
	fftw_real  hn = (fftw_real)winHeight / (fftw_real)(DIM + 1);  // Grid cell heigh

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	fftw_real values[(DIM- 1) * (DIM - 1)];
	if (draw_rho){
		for (i = 0; i < (DIM- 1) * (DIM - 1); i++){
			values[i] = rho[i];
		}
	} else {
		for (i = 0; i < (DIM- 1) * (DIM - 1); i++){
			values[i] = vx[i]*vx[i] + vy[i]+vy[i];
			values[i] = (values[i] == 0) ? 0 : sqrt(values[i]);
		}		
	}
		
	// Find max(rho)
	fftw_real max = 0.0f;
	for (k = 0; k < (DIM - 1) * (DIM - 1); k++) {
		max = (values[k] > max) ? values[k] : max;
	}
	
	for (j = 0; j < DIM - 1; j += 1)			//draw smoke
	{
		glBegin(GL_QUAD_STRIP);
		i = 0;
		px = wn + (fftw_real)i * wn;
		py = hn + (fftw_real)j * hn;
		idx = (j * DIM) + i;
		if (!color_dir) {
			set_colormap(values[idx], max, scalar_col, inv_scalar, disc_scalar_col);
		} else {
			hue( ( atan2(vy[idx] , vx[idx]) + 3.14) / 6.28 );
		}
		glVertex2f(px, py);

		for (i = 0; i < DIM - 1; i++)
		{
			px = wn + (fftw_real)i * wn;
			py = hn + (fftw_real)(j + 1) * hn;
			idx = ((j + 1) * DIM) + i;
			if (!color_dir) {
				set_colormap(values[idx], max, scalar_col, inv_scalar, disc_scalar_col);
			} else {
				hue( ( atan2(vy[idx] , vx[idx]) + 3.14) / 6.28 );
			}
			glVertex2f(px, py);
			px = wn + (fftw_real)(i + 1) * wn;
			py = hn + (fftw_real)j * hn;
			idx = (j * DIM) + (i + 1);
			if (!color_dir) {
				set_colormap( values[idx] , max, scalar_col, inv_scalar, disc_scalar_col);
			} else {
				hue( ( atan2(vy[idx] , vx[idx]) + 3.14) / 6.28 );
			}
			glVertex2f(px, py);
		}


		px = wn + (fftw_real)(DIM - 1) * wn;
		py = hn + (fftw_real)(j + 1) * hn;
		idx = ((j + 1) * DIM) + (DIM - 1);
		if (!color_dir) {
			set_colormap(values[idx], max, scalar_col, inv_scalar, disc_scalar_col);
		} else {
			hue( ( atan2(vy[idx] , vx[idx]) + 3.14) / 6.28 );
		}
		glVertex2f(px, py);
		glEnd();
	}
}
Esempio n. 24
0
void render()
{
  const SDL_VideoInfo *vidinfo;
  int x,y,w,h;
  int i;
  char buf[1000];
  Uint32 vidfr = (metafr-1);
  Uint32 vidfrmod = vidfr%maxframes;

  Uint32 render_start = SDL_GetTicks();
  static Uint32 total_start = 0;
  Uint32 tmp;

  if( metafr==0 || vidfr<=drawnfr ) //==0 prevent never-draw bug
    return;

  if( soon==1 )
    setvideo(soon_w,soon_h,soon_full,0);
  if( soon>0 )
    soon--;

  vidinfo  = SDL_GetVideoInfo();
  w = v_w  = vidinfo->current_w;
  h = v_h  = vidinfo->current_h;
  pad_left = 0;
  pad_top  = 0;
  if( v_center ) {
    pad_left = (w - NATIVEW*scale)/2;
    pad_top  = (h - NATIVEH*scale)/2;
  }

  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();
  glScalef(1.0f/256.0f, 1.0f/256.0f, 1);

  glColor4f(1.0f,1.0f,1.0f,1.0f);
  glEnable(GL_TEXTURE_2D);
  if( v_usealpha )
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  else
    glBlendFunc(GL_ONE, GL_ZERO);
  glEnable(GL_BLEND);

  glAlphaFunc(GL_GREATER,0.01);
  glEnable(GL_ALPHA_TEST);

  glDepthFunc(GL_LEQUAL);
  glEnable(GL_DEPTH_TEST);

  glClear(GL_DEPTH_BUFFER_BIT);

  // viewport and matrixes for game objects
  glViewport(pad_left,h-NATIVEH*scale-pad_top,NATIVEW*scale,NATIVEH*scale);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0,NATIVEW,NATIVEH,0,-NATIVEH*3-1,NATIVEH*3+1);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  int camx = NATIVEW/2-(int)v_camx, camy = NATIVEH/2-(int)v_camy;
  glTranslatef(camx,camy,0);

  SJGL_SetTex( (GLuint)-1 ); //forget previous texture name
  mod_predraw(vidfr);

  //display objects
  for(i=0;i<maxobjs;i++) {
    OBJ_t *o = fr[vidfrmod].objs+i;
    if( o->flags&OBJF_VIS )
      mod_draw(i,o); // have the mod draw the actual thing
  }

  mod_postdraw(vidfr);

  glDisable(GL_DEPTH_TEST);

  //display hulls and object numbers
  if( v_drawhulls ) {
    glBindTexture( GL_TEXTURE_2D, 0 );
    glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

    if( mycontext ) {
      CONTEXT_t *co = fr[vidfrmod].objs[mycontext].data;
      int x,y,z;
      for( z=0; z<co->z; z++ )
        for( y=0; y<co->y; y++ )
          for( x=0; x<co->x; x++ ) {
            int pos = co->x*co->y*z + co->x*y + x;
            int flags;

            if( co->dmap[ pos ].flags & CBF_NULL )
              flags = co->map[  pos ].flags;
            else
              flags = co->dmap[ pos ].flags;

            if( flags & CBF_SOLID ) {
              glColor4f(1,0,0,1);
              SJGL_Blit( &(SDL_Rect){0,0,16,16}, x*16,   y*16,   z );
              SJGL_Blit( &(SDL_Rect){0,0,12,12}, x*16+2, y*16+2, z );
            } else if( flags & CBF_PLAT ) {
              glColor4f(0,1,0,1);
              SJGL_Blit( &(SDL_Rect){0,0,16, 2}, x*16,   y*16,   z );
            }
          }
    }

    glColor4f(1,1,1,1);
    for(i=0;i<maxobjs;i++) {
      OBJ_t *o = fr[vidfrmod].objs+i;
      V *pos  = flex(o,OBJF_POS);
      V *hull = flex(o,OBJF_HULL);
      if( pos && hull ) {
        SDL_Rect rect = (SDL_Rect){0, 0, hull[1].x-hull[0].x, hull[1].y-hull[0].y};
        SJGL_Blit( &rect, pos->x+hull[0].x, pos->y+hull[0].y, 0 );
      }
    }

    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

    for(i=0;i<maxobjs;i++) {
      OBJ_t *o = fr[vidfrmod].objs+i;
      V *pos  = flex(o,OBJF_POS);
      if( pos ) {
        sprintf(buf,"%d",i);
        SJF_DrawText(pos->x, pos->y, buf);
      }
    }
  }

  // viewport and matrixes for HUD
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0,w,h,0,-1,1);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  //paint black over the border areas, subtractively with v_oob
  {
    int outerl = 0;   int innerl = pad_left;
    int outert = 0;   int innert = pad_top;
    int outerr = w;   int innerr = pad_left + NATIVEW*scale;
    int outerb = h;   int innerb = pad_top  + NATIVEH*scale;
    glDisable(GL_TEXTURE_2D);
    glPushAttrib(GL_COLOR_BUFFER_BIT);
    if( v_oob ) {
      glColor4f(0.02,0.02,0.02,0.02);
      glBlendFunc(GL_ONE,GL_ONE);
      if( GLEW_EXT_blend_equation_separate )
        glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
    }
    else
      glColor4f(0,0,0,1.0f);
    glBegin(GL_QUADS);
    glVertex2i(outerl,outert); glVertex2i(outerr,outert); glVertex2i(outerr,innert); glVertex2i(outerl,innert); //top
    glVertex2i(outerl,innerb); glVertex2i(outerr,innerb); glVertex2i(outerr,outerb); glVertex2i(outerl,outerb); //bottom
    glVertex2i(outerl,innert); glVertex2i(innerl,innert); glVertex2i(innerl,innerb); glVertex2i(outerl,innerb); //left
    glVertex2i(innerr,innert); glVertex2i(outerr,innert); glVertex2i(outerr,innerb); glVertex2i(innerr,innerb); //right
    glEnd();
    glPopAttrib();
    glEnable(GL_TEXTURE_2D);
    glColor4f(1.0f,1.0f,1.0f,1.0f);
  }

  SJGL_SetTex( (GLuint)-1 ); //forget previous texture name
  mod_outerdraw(vidfr,w,h);

  //display console
  if(console_open) {
    int conh = h/2 - 40;
    if(conh<40) conh = 40;
    glColor4f(0.15,0.15,0.15,0.85);
    glDisable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glVertex2i(0,   0); glVertex2i(w,   0);
    glVertex2i(w,conh); glVertex2i(0,conh);
    glEnd();
    glEnable(GL_TEXTURE_2D);
    glColor4f(1.0f,1.0f,1.0f,1.0f);
    x = 10;
    y = conh-20;
    if((ticks/200)%2)
      SJF_DrawChar(x+SJF_TextExtents(SJC.buf[0]), y, '_');
    for(i=0;y>0;i++) {
      if(SJC.buf[i])
        SJF_DrawText(x,y,SJC.buf[i]);
      y -= 10;
    }
    if( SJC.buf[0] && SJC.buf[0][0] ) {
      char s[10];
      sprintf(s,"%d",SJC.buf[0][strlen(SJC.buf[0])-1]);
      SJF_DrawText(w-20,conh-20,s);
    }
  }

  //display stats
  total_time += (tmp = SDL_GetTicks()) - total_start;
  render_time += tmp - render_start;
  total_start = tmp;
  Uint32 unaccounted_time = total_time - (idle_time + render_time + adv_move_time + adv_collide_time + adv_game_time);
  if( v_showstats ) {
    Uint32 denom = vidfrmod+1;
    sprintf(buf,"idle_time %4d"       ,       idle_time/denom);
    SJF_DrawText(w-20-SJF_TextExtents(buf),10,buf);
    sprintf(buf,"render_time %4d"     ,     render_time/denom);
    SJF_DrawText(w-20-SJF_TextExtents(buf),20,buf);
    sprintf(buf,"adv_move_time %4d"   ,   adv_move_time/denom);
    SJF_DrawText(w-20-SJF_TextExtents(buf),30,buf);
    sprintf(buf,"adv_collide_time %4d",adv_collide_time/denom);
    SJF_DrawText(w-20-SJF_TextExtents(buf),40,buf);
    sprintf(buf,"adv_game_time %4d"   ,   adv_game_time/denom);
    SJF_DrawText(w-20-SJF_TextExtents(buf),50,buf);
    sprintf(buf,"unaccounted_time %4d",unaccounted_time/denom);
    SJF_DrawText(w-20-SJF_TextExtents(buf),60,buf);
    sprintf(buf,"adv_frames  %2.2f"   ,(float)adv_frames/(float)denom);
    SJF_DrawText(w-20-SJF_TextExtents(buf),70,buf);
    sprintf(buf,"fr: idx=%d meta=%d vid=%d hot=%d",metafr%maxframes,metafr,vidfr,hotfr);
    SJF_DrawText(w-20-SJF_TextExtents(buf),80,buf);
  }

  SDL_GL_SwapBuffers();
  setdrawnfr(vidfr);

  if( (int)vidfrmod==maxframes-1 ) { // reset time stats
    total_time       = 0;
    idle_time        = 0;
    render_time      = 0;
    adv_move_time    = 0;
    adv_collide_time = 0;
    adv_game_time    = 0;
    adv_frames       = 0;
  }
}
Esempio n. 25
0
void
ClipObject::drawLines(QGLViewer *viewer,
		      bool backToFront)
{
  bool noimage = !m_imagePresent && !m_captionPresent;
  bool quad = noimage && m_active;

  glEnable(GL_BLEND);
//  glEnable(GL_LINE_SMOOTH);
//  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

  Vec voxelScaling = Global::voxelScaling();
  Vec opt = VECPRODUCT(m_position, voxelScaling);
  opt = Matrix::xformVec(m_xform, opt);

  float r = m_size;
  float s1 = m_tscale1;
  float s2 = m_tscale2;

  Vec tang = m_tang;
  Vec xaxis = m_xaxis;
  Vec yaxis = m_yaxis;

  tang = Matrix::rotateVec(m_xform, tang);
  xaxis = Matrix::rotateVec(m_xform, xaxis);
  yaxis = Matrix::rotateVec(m_xform, yaxis);

  if (backToFront)
    {
      if (m_active)
        glLineWidth(3);
      else
        glLineWidth(1);

      glColor3f(m_color.x, m_color.y, m_color.z);

      if (m_thickness > 0 && m_showThickness)
	DRAWTHICKNESS()
      else
	DRAWCLIPWIDGET()
    }


  glLineWidth(1);

  if (!m_solidColor || m_active)
    {
      Vec c0, ca, cb, c1;
      c0 = opt + s1*xaxis;
      ca = opt - 0.2*s2*yaxis;
      c1 = opt - s1*xaxis;
      cb = opt + 0.2*s2*yaxis;
      glColor4f(m_opacity, 0.5*m_opacity, 0, m_opacity);
      if (quad &&
	  m_moveAxis >= MoveX0 &&
	  m_moveAxis <= MoveX1) glBegin(GL_QUADS);
      else glBegin(GL_LINE_STRIP);
      glVertex3fv(c0);
      glVertex3fv(ca);
      glVertex3fv(c1);
      glVertex3fv(cb);
      if (!(quad && m_moveAxis == MoveZ)) glVertex3fv(c0);
      glEnd();

      c0 = opt + s2*yaxis;
      ca = opt - 0.2*s1*xaxis;
      c1 = opt - s2*yaxis;
      cb = opt + 0.2*s1*xaxis;
      glColor4f(0.5*m_opacity, m_opacity, 0, m_opacity);
      if (quad &&
	  m_moveAxis >= MoveY0 &&
	  m_moveAxis <= MoveY1) glBegin(GL_QUADS);
      else glBegin(GL_LINE_STRIP);
      glVertex3fv(c0);
      glVertex3fv(ca);
      glVertex3fv(c1);
      glVertex3fv(cb);
      if (!quad) glVertex3fv(c0);
      glEnd();
      
      c0 = opt + r*tang;
      Vec cax = opt - 0.2*s1*xaxis;
      Vec cbx = opt + 0.2*s1*xaxis;
      Vec cay = opt - 0.2*s2*yaxis;
      Vec cby = opt + 0.2*s2*yaxis;
      glColor4f(0, 0.5*m_opacity, m_opacity, m_opacity);
      if (quad && m_moveAxis == MoveZ) glBegin(GL_TRIANGLES);
      else glBegin(GL_LINE_STRIP);
      glVertex3fv(c0);
      glVertex3fv(cax);
      glVertex3fv(cay);
      glVertex3fv(c0);
      glVertex3fv(cay);
      glVertex3fv(cbx);
      glVertex3fv(c0);
      glVertex3fv(cbx);
      glVertex3fv(cby);
      glVertex3fv(c0);
      glVertex3fv(cby);
      glVertex3fv(cax);
      if (!(quad && m_moveAxis == MoveZ)) glVertex3fv(c0);
      glEnd();
    }

  //  glDisable(GL_LINE_SMOOTH);


  if (!backToFront)
    {
      if (m_active)
        glLineWidth(3);
      else
        glLineWidth(1);

      glColor3f(m_color.x, m_color.y, m_color.z);

      if (m_thickness > 0 && m_showThickness)
	DRAWTHICKNESS()
      else
	DRAWCLIPWIDGET()
    }

  if (!m_solidColor || m_active)
    {
      glEnable(GL_POINT_SPRITE);
      glActiveTexture(GL_TEXTURE0);
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, Global::spriteTexture());
      glTexEnvf( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
      glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
      glEnable(GL_POINT_SMOOTH);

      if (m_active)
	{
	  glColor3f(1,0,0);
	  glPointSize(25);
	}
      else
	{
	  glColor3f(m_color.x, m_color.y, m_color.z);
	  glPointSize(20);
	}	
      glBegin(GL_POINTS);
      glVertex3fv(opt);
      glEnd();

      glPointSize(1);  
      
      glDisable(GL_POINT_SPRITE);
      glActiveTexture(GL_TEXTURE0);
      glDisable(GL_TEXTURE_2D);
  
      glDisable(GL_POINT_SMOOTH);
    }

  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);      
}
Esempio n. 26
0
void TerrainQuadtree::generateTextures() {
	// prepare viewport and projection
	//glDisable(GL_DEPTH_TEST);

	// do not setup the proj more than once
	if (this->parent == NULL) {
		glViewport(0, 0, this->textureSize, this->textureSize);
		glMatrixMode(GL_PROJECTION);
		glPolygonMode(GL_FRONT, GL_FILL);
		glLoadIdentity();
		glOrtho(0.0, (double)this->textureSize, 0.0, (double)this->textureSize, 0.0, 1.0);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glTranslated(0.0, 0.0, -1.0);

		generationScreenList = glGenLists(1);
		glNewList(generationScreenList, GL_COMPILE);
		glBegin(GL_QUADS);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(0.0, 0.0, 0.0);
		glTexCoord2f(1.0, 0.0);
		glVertex3f(this->textureSize, 0.0, 0.0);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(this->textureSize, this->textureSize, 0.0);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(0.0, this->textureSize, 0.0);
		glEnd();
		glEndList();
	}

	// generate topography
	glBindFramebuffer(GL_FRAMEBUFFER, this->framebuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->topoTexture->id, 0);
	this->positionTexture->bind(GL_TEXTURE0);

	this->generatorShader->bind();
	glUniform1i(glGetUniformLocation(this->generatorShader->program, "positionTexture"), 0);
	glCallList(generationScreenList);
	this->generatorShader->unbind();
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// generate normals
	//glBindFramebuffer(GL_FRAMEBUFFER, this->framebuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->normalTexture->id, 0);
	this->topoTexture->bind(GL_TEXTURE1);

	this->generatorShaderN->bind();
	glUniform1f(glGetUniformLocation(this->generatorShaderN->program, "size"), (float)this->textureSize);
	glUniform1f(glGetUniformLocation(this->generatorShaderN->program, "radius"), this->planet->radius);
	glUniform1i(glGetUniformLocation(this->generatorShaderN->program, "topoTexture"), 1);
	glUniform1i(glGetUniformLocation(this->generatorShaderN->program, "positionTexture"), 0);
	glCallList(generationScreenList);
	this->generatorShaderN->unbind();
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// generate colors
	//glBindFramebuffer(GL_FRAMEBUFFER, this->framebuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->colorTexture->id, 0);
	this->generatorShaderC->bind();
	glUniform1i(glGetUniformLocation(this->generatorShaderC->program, "topoTexture"), 1);
	glCallList(generationScreenList);
	this->generatorShaderC->unbind();
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);

	//glEnable(GL_DEPTH_TEST);
	this->ready = true;
}
Esempio n. 27
0
void MeshGui::display(void)
{
	glClearColor( .9f, .9f, .9f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glFrustum( -xy_aspect*.04, xy_aspect*.04, -.04, .04, .1, 15.0 );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	glMultMatrixf( lights_rotation );
	glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
	glLoadIdentity();
	glTranslatef( 0.0, 0.0, -2.6f );
	glTranslatef( obj_pos[0], obj_pos[1], -obj_pos[2] ); 
	glMultMatrixf( view_rotate );
	glScalef( scale, scale, scale );

	switch (radiogroup_item_id)
	{
	case 2:
		// draw the smf model
		glPushMatrix();
		glTranslatef( -.5, 0.0, 0.0 );
		glMultMatrixf( mesh_rotate );
		glColor3f(0.9f, 0.9f, 0.9f);

		smf_model.display();
		//subd.display();

		glPopMatrix();
		break;
	// shade with mesh edges displayed
	case 3:
		// the mesh itself
		glPushMatrix();
		glTranslatef( -.5, 0.0, 0.0 );
		glMultMatrixf( mesh_rotate );
		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
		glColor3f(0.9f, 0.9f, 0.9f);

		smf_model.display();

		glPopMatrix();
		// the edges
		glPushMatrix();
		glTranslatef( -.5, 0.0, 0.0 );
		glMultMatrixf( mesh_rotate );
		glColorMaterial(GL_FRONT, GL_DIFFUSE);
		glEnable(GL_COLOR_MATERIAL);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glColor3f(0.0f, 0.0f, 0.0f);

		smf_model.display();

		glColor3f(0.9f, 0.9f, 0.9f);
		glDisable(GL_COLOR_MATERIAL);
		glPopMatrix();
		break;
	case 1:
	default:
		// draw the smf model
		glPushMatrix();
		glTranslatef( -.5, 0.0, 0.0 );
		glMultMatrixf( mesh_rotate );
		glColor3f(0.9f, 0.9f, 0.9f);

		smf_model.display();
		//subd.display();

		glPopMatrix();
		break;
	}

	/*glPushMatrix();
	glTranslatef( .5, 0.0, 0.0 );
	glMultMatrixf( mesh_rotate );
	glutSolidTorus( .15,.3,16,8 );
	glPopMatrix();*/

	// show text
	if (show_text) 
	{
		// disable lighting while we render text
		glDisable( GL_LIGHTING );
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity();
		gluOrtho2D( 0.0, 100.0, 0.0, 100.0  );
		glMatrixMode( GL_MODELVIEW );
		glLoadIdentity();
		glColor3ub( 0, 0, 0 );
		glRasterPos2i( 10, 10 );
		// render the live character array 'text'
		for(int i=0; i<(int)strlen( string_list[curr_string] ); i++ )
		{
			glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, string_list[curr_string][i] );
		}
	}
	glEnable( GL_LIGHTING );
	glutSwapBuffers(); 
}
Esempio n. 28
0
LRESULT CLX3DViewer::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CPoint point;
	point.x = (short)LOWORD(lParam);
	point.y = (short)HIWORD(lParam);

	if (m_dragging == 1)
	{
		m_slider.OnMouseMove(point);
		UpdateWindow();

		double position = m_slider.GetPos();

		CComQIPtr<ILMediaSeeking> seeking = m_filterGraph;
		seeking->Seek(position);
	}

#if 0
	if (m_dragging)
	{
		CPoint offset = point - m_startpoint;

		if (m_dragging == 1)	// change XY position
		{
			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			double moveY = (double)-offset.y/20;
			double moveX = (double)offset.x/20;

			gmMatrix4 repos = gmMatrix4::identity();

			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
			repos *= gmMatrix4::translate(moveX, moveY, 0);
			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

			position->m_value = repos.transform(m_initialPosition);

			FireViewChange();
		}
		else if (m_dragging == 2) // change XZ position
		{
			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			double moveX = (double)offset.x/20;
			double moveZ = (double)offset.y/20;

			gmMatrix4 repos = gmMatrix4::identity();

			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
			repos *= gmMatrix4::translate(moveX, 0, moveZ);
			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

			position->m_value = repos.transform(m_initialPosition);

			FireViewChange();
		}
		else if (m_dragging == 3)
		{
			double r = 600;	// 360

			double rotateY = (double)offset.x*360/r;
			double rotateX = (double)offset.y*360/r;

			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			// Orientation
			if (rotateY != 0 || rotateX != 0)
			{
				/*
				float x = m_initialOrientation.m_v[0];
				float y = m_initialOrientation.m_v[1];
				float z = m_initialOrientation.m_v[2];
				float angle = m_initialOrientation.m_a;
				*/

				Quat4d q = m_initialOrientation.AxisAngleToQuaternion(/*x, y, z, angle*/);

				q.CombineQuaternion(/*x, y, z, angle,*/ 0, gmRadians(rotateY), gmRadians(rotateX));

				orientation->m_value = q.QuaternionToAxisAngle();//Quat4d(x, y, z, angle));

				/*
				orientation->m_value.m_v[0] = x;
				orientation->m_value.m_v[1] = y;
				orientation->m_value.m_v[2] = z;
				orientation->m_value.m_a = angle;
				*/

				orientation->m_value.m_v.normalize();
			}

			// Position
			{
				// Rotate position around centerOfRotation
				gmMatrix4 repos = gmMatrix4::identity();

				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
				repos *= gmMatrix4::rotate(rotateY, gmVector3(0,1,0));
				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

				position->m_value = repos.transform(m_initialPosition);
			}

			// Position
			{
				// Rotate position around centerOfRotation
				gmMatrix4 repos = gmMatrix4::identity();

				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
				repos *= gmMatrix4::rotate(rotateX, gmVector3(1,0,0));
				repos *= gmMatrix4::rotate(rotateY, gmVector3(0,1,0));
				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

				position->m_value = repos.transform(m_initialPosition);
			}

			FireViewChange();
		}
	}
	else
	{
		CRect client;
		GetClientRect(&client);
		int w = client.right;
		int h = client.bottom;
	//	wglMakeCurrent(hdc, m_hrc);

		double winx = point.x;
		double winy = client.bottom-point.y-1;

		GLint viewport[4] = { 0, 0, w, h };

		GLuint selectBuf[512];

		glSelectBuffer(512, selectBuf);
		glRenderMode(GL_SELECT);
		glInitNames();
		glPushName(0);

		{
			CLViewpoint* pViewpoint = NULL;

			if (m_viewpointStack.GetSize() > 0)
			{
				pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);
			}
			else
			{
				// hmm...
			}

			//	glViewport(m_viewR[view].left, m_viewR[view].top, w, h);

			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluPickMatrix(winx, winy, 3, 3, viewport);
	//		glLoadMatrixd(projm);
		//
			double fov;
			if (pViewpoint)
			{
				CLSFFloat* fieldOfView = static_cast<CLSFFloat*>(pViewpoint->m_fieldOfView);
				fov = fieldOfView->m_value;
			}
			else
			{
				fov = M_PI/4;
			}

			gluPerspective(gmDegrees(fov), (GLfloat)w / (GLfloat)h, 1.0, 10000.0);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			//glLoadMatrixf((float*)modelm);

			CX3DDrawContext xdc;

#if 0
			// NavigationInfo
			{
				BOOL headlight;

				if (m_navigationinfoStack.GetSize() > 0)
				{
					CLNavigationInfo* pNavigationInfo = static_cast<CLNavigationInfo*>(m_navigationinfoStack[0]);

					headlight = static_cast<CLSFBool*>(pNavigationInfo->m_headlight)->m_v;
				}
				else
				{
					// Default values
					headlight = TRUE;
				}

				glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

				if (TRUE)//TRUE/*bAnyLights*/)
				{
				}

				if (headlight)
				{
					GLfloat light_direction[4] = { 0, 0, 1, 0};	// directional
					GLfloat color[4] = {1, 1, 1, 1};
					GLfloat ambient[4] = {0, 0, 0, 1};

					glEnable(GL_LIGHT0+xdc.m_nLight);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_POSITION, light_direction);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_AMBIENT, ambient);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_DIFFUSE, color);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_SPECULAR , color);

					xdc.m_nLight++;
				}
			}
#endif

			if (pViewpoint)
			{
				CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
				CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);
				gmVector3t<float> norientation = orientation->m_value.m_v;
				norientation.normalize();

				glRotate(gmDegrees(orientation->m_value.m_a), -norientation);
				glTranslate(-position->m_value);
			}
			else
			{
				// TODO
				glTranslatef(0, 0, -180);
			}

			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

			if (m_scene)
			{
				CComQIPtr<CLRenderImplImpl> render = static_cast<CLSAIScene*>(m_scene)->m_root;
				if (render)
				{
					render->Draw(&xdc);
				}
			}

			glFlush();
		}

		GLint hits = glRenderMode(GL_RENDER);

		if (hits > 0)
		{
			MessageBeep(-1);
			GLuint* ptr = selectBuf;

			GLuint names = *ptr++;
			float z1 = *ptr++ / 0x7fffffff;
			float z2 = *ptr++ / 0x7fffffff;

			double winz = z2;

			double modelMatrix[16];
			double projMatrix[16];

			glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
			glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);

			double objx, objy, objz;
			gluUnProject(winx, winy, winz, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

			for (int n = 0; n < names; n++)
			{
			}
		}
	}
#endif

	return 0;
}
Esempio n. 29
0
void
DrawGLScene(void)
{
    float   tx, tz;

    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    // set camera based on previous mouse input
    SetupCamera();

    // Set the light position. We do that after setting up the
    // camera so that the light position will keep its world position
    // and rotate along with the scene.
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    // Draw the different objects

    if (show_polygons_as_lines)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glDisable(GL_TEXTURE_2D);
    }
    else
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

        if (show_textures)
        {
            glEnable(GL_ALPHA_TEST);
            glAlphaFunc(GL_GREATER, 0.5);
            glEnable(GL_TEXTURE_2D);
        }
        else
            glDisable(GL_TEXTURE_2D);
    }

    DrawPolylist(polylistHouse);
    DrawPolylist(polylistGround1);
    DrawPolylist(polylistGround2);
    DrawPolylist(polylistRoad);

    // Draw a number of trees around the house.
    // They are all identical, but differ in location and Y-rotation.

    // Re-seed the random generator, so we always get the same sequence
    // back from rand_float() below, for different runs of the program.
    srand(95497452);

    for (int t = 0; t < 12; t++)
    {
        glPushMatrix();

        tx = 10 * (rand_float()-0.5) + object_positions[0].x;
        tz = 3 * rand_float() + 2.0 + object_positions[0].z;
        glTranslatef(tx, 0, tz);

        glRotatef(rand_float()*360.0, 0, 1, 0);
        glScalef(1, 1 + (rand_float()-0.5)*0.6, 1);

        DrawPolylist(polylistTreeStem);

        // Calculate a random number of leafs, than calculate the turn for every leaf
        int nrleafs = rand() % 6 + 5;
        int turn = 360/nrleafs;

        // Draw every leaf
        for (int i = 0; i < nrleafs; i++) {
            DrawPolylist(polylistTreeLeafs);
            glRotatef(turn, 0, 1, 0);
        }

        glPopMatrix();
    }

    // Draw the skydome with lighting turned off

    glPushAttrib(GL_LIGHTING_BIT);
    glDisable(GL_LIGHTING);
    DrawPolylist(polylistSkydome);
    glPopAttrib();

    glutSwapBuffers();
}
/* ---------------------------------------------------------------------------- */
void apply_material(const struct aiMaterial *mtl)
{
	float c[4];

	GLenum fill_mode;
	int ret1, ret2;
	struct aiColor4D diffuse;
	struct aiColor4D specular;
	struct aiColor4D ambient;
	struct aiColor4D emission;
	float shininess, strength;
	int two_sided;
	int wireframe;
	unsigned int max;

	set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f);
	if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
		color4_to_float4(&diffuse, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);

	set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
	if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular))
		color4_to_float4(&specular, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);

	set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f);
	if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient))
		color4_to_float4(&ambient, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);

	set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
	if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission))
		color4_to_float4(&emission, c);
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c);

	max = 1;
	ret1 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max);
	if(ret1 == AI_SUCCESS) {
    	max = 1;
    	ret2 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
		if(ret2 == AI_SUCCESS)
			glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);
        else
        	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
    }
	else {
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
		set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
	}

	max = 1;
	if(AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max))
		fill_mode = wireframe ? GL_LINE : GL_FILL;
	else
		fill_mode = GL_FILL;
	glPolygonMode(GL_FRONT_AND_BACK, fill_mode);

	max = 1;
	if((AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided)
		glDisable(GL_CULL_FACE);
	else 
		glEnable(GL_CULL_FACE);
}