Esempio n. 1
0
void renderCylinder(float x1, float y1, float z1, 
		            float x2, float y2, float z2, 
					float radius, int subdivisions,
					GLUquadricObj *quadric) {
	float vx = x2-x1;
	float vy = y2-y1;
	float vz = z2-z1;

	//handle the degenerate case of z1 == z2 with an approximation
	if(vz == 0)
		vz = .0001;

	float v = sqrt( vx*vx + vy*vy + vz*vz );
	float ax = 57.2957795*acos( vz/v );
	if ( vz < 0.0 )
		ax = -ax;
	float rx = -vy*vz;
	float ry = vx*vz;
	glPushMatrix();

	//draw the cylinder body
	glTranslatef( x1,y1,z1 );
	glRotatef(ax, rx, ry, 0.0);
	gluQuadricOrientation(quadric,GLU_OUTSIDE);
	gluCylinder(quadric, radius, radius, v, subdivisions, 1);

	//draw the first cap
//	gluQuadricOrientation(quadric,GLU_INSIDE);
//	gluDisk( quadric, 0.0, radius, subdivisions, 1);
	glutSolidSphere(radius, subdivisions, subdivisions/2);
	glTranslatef( 0,0,v );

	//draw the second cap
//	gluQuadricOrientation(quadric,GLU_OUTSIDE);
//	gluDisk( quadric, 0.0, radius, subdivisions, 1);
	glutSolidSphere(radius, subdivisions, subdivisions/2);
	glPopMatrix();
}
Esempio n. 2
0
void Trogdor::drawBody(){
	glPushMatrix();
		glTranslatef(0, 0, -3.5);

		//texture set-up
		glBindTexture(GL_TEXTURE_2D, texArr[t1]);
		
		gluQuadricNormals(cyl, GLU_SMOOTH);		// specify one normal per vertex.
		gluQuadricOrientation(cyl, GLU_OUTSIDE);  //points normals outward
		gluQuadricTexture(cyl, GLU_TRUE);		//turns on texture coordinates

		glColor4f(0, 0.25, 0, 1);
			
		gluCylinder(cyl, base_cyl, top_cyl, height_cyl, slice_cyl, stack_cyl);
	glPopMatrix();

	//spikes on body
	glPushMatrix();
		glColor4f(1, 1, 1, 1);
		glBindTexture(GL_TEXTURE_2D, texArr[t3]);
				
		glTranslatef(0.0, 1.0, 0.0);
		glRotatef(270.0, 0.0, 0.0, 0.0);
		gluCylinder(cyl, 0.1, 0.0, 2.0, 15, 15);
		glTranslatef(0.0, 1.0, 0.0);
		gluCylinder(cyl, 0.1, 0.0, 2.0, 15, 15);
		glTranslatef(0.0, 1.0, 0.0);
		gluCylinder(cyl, 0.1, 0.0, 2.0, 15, 15);
		glTranslatef(0.0, 1.0, 0.0);
		gluCylinder(cyl, 0.1, 0.0, 2.0, 15, 15);
		glTranslatef(0.0, -4.0, 0.0);
		gluCylinder(cyl, 0.1, 0.0, 2.0, 15, 15);
		glTranslatef(0.0, -1.0, 0.0);
		gluCylinder(cyl, 0.1, 0.0, 2.0, 15, 15);
		glTranslatef(0.0, -1.0, 0.0);
		gluCylinder(cyl, 0.1, 0.0, 2.0, 15, 15);
	glPopMatrix();
}
Esempio n. 3
0
void render_world(void)
{
	 GLUquadricObj *obj;
	 int mode=GL_FRONT;
	 

	 obj=gluNewQuadric();
	 glMaterialfv(mode,GL_AMBIENT,ambient);
	 glMaterialfv(mode,GL_DIFFUSE,diffuse);
	 glMaterialfv(mode,GL_SPECULAR,specular);
	 glMaterialf(mode,GL_SHININESS,0.0);
	 glMaterialfv(mode,GL_EMISSION,emission);

	 glPushMatrix();
	 glTranslatef(0.0,0.0,0.0);
	 gluQuadricDrawStyle(obj,GLU_SMOOTH);
	 gluQuadricOrientation(obj,GLU_INSIDE);

	 gluSphere(obj,WORLD_SIZE,10,10);
	 glPopMatrix();

	 gluDeleteQuadric(obj);
}
Esempio n. 4
0
int Jenarix::cylinder( jx_ob ob) 
{
    GLdouble bxyz[3], txyz[3], r;
    GLdouble dx, dy, dz, h;

    unsigned int ibxyz = 0;
    unsigned int itxyz = 1;
    unsigned int irad = 2;
    assert (jx_list_check(ob));
    int nval = jx_list_size(ob);
    //printf ("%d cylinder\n", nval);
    for ( int index = 0; index < nval; ++index ) {
      jx_ob base_tip_rad = jx_list_shift(ob);
      //printf ("%d\n", value[index].size());
      get_point(jx_list_get(base_tip_rad,ibxyz), bxyz);
      //printf ("%f %f %f\n", bxyz[0], bxyz[1], bxyz[2]);
      get_point(jx_list_get(base_tip_rad,itxyz), txyz);
      //printf ("%f %f %f\n", txyz[0], txyz[1], txyz[2]);
      dx = txyz[0] - bxyz[0];
      dy = txyz[1] - bxyz[1];
      dz = txyz[2] - bxyz[2];
      h = sqrt(dx*dx + dy*dy + dz*dz);
      glPushMatrix();
      align_from_z(bxyz, txyz);
      GLUquadricObj* quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_OUTSIDE);
      gluQuadricNormals(quadric, GLU_SMOOTH);
      r = get_real(jx_list_get(base_tip_rad, irad));
      //printf ("%f\n", r);
      gluCylinder(quadric, r, r, h, 20, 20);
      gluDeleteQuadric(quadric);
      glPopMatrix();
    }

    return nval;
}
static void Init( int argc, char *argv[] )
{
   GLUquadricObj *q = gluNewQuadric();
   CylinderObj = glGenLists(1);
   glNewList(CylinderObj, GL_COMPILE);

   glTranslatef(0.0, 0.0, -1.0);

   /* cylinder */
   gluQuadricNormals(q, GL_SMOOTH);
   gluQuadricTexture(q, GL_TRUE);
   gluCylinder(q, 0.6, 0.6, 2.0, 24, 1);

   /* end cap */
   glTranslatef(0.0, 0.0, 2.0);
   gluDisk(q, 0.0, 0.6, 24, 1);

   /* other end cap */
   glTranslatef(0.0, 0.0, -2.0);
   gluQuadricOrientation(q, GLU_INSIDE);
   gluDisk(q, 0.0, 0.6, 24, 1);

   glEndList();
   gluDeleteQuadric(q);

   /* lighting */
   glEnable(GL_LIGHTING);
   {
      GLfloat gray[4] = {0.2, 0.2, 0.2, 1.0};
      GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat teal[4] = { 0.0, 1.0, 0.8, 1.0 };
      glMaterialfv(GL_FRONT, GL_DIFFUSE, teal);
      glLightfv(GL_LIGHT0, GL_AMBIENT, gray);
      glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
      glEnable(GL_LIGHT0);
   }

   /* fitering = nearest, initially */
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

   if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
      printf("Error: couldn't load texture image\n");
      exit(1);
   }

   glEnable(GL_CULL_FACE);  /* don't need Z testing for convex objects */

   SetMode(LIT);

   if (argc > 1 && strcmp(argv[1], "-info")==0) {
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
      printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
      printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
   }
}
Esempio n. 6
0
void drawCylinder( double h, double r1, double r2 )
{
    ModelerDrawState *mds = ModelerDrawState::Instance();
    int divisions;

	_setupOpenGl();
    
    switch(mds->m_quality)
    {
    case HIGH: 
        divisions = 32; break;
    case MEDIUM: 
        divisions = 20; break;
    case LOW:
        divisions = 12; break;
    case POOR:
        divisions = 8; break;
    }
    
    if (mds->m_rayFile)
    {
        _dump_current_modelview();
        fprintf(mds->m_rayFile, 
            "cone { height=%f; bottom_radius=%f; top_radius=%f;\n", h, r1, r2 );
        _dump_current_material();
        fprintf(mds->m_rayFile, "})\n" );
    }
    else
    {
        GLUquadricObj* gluq;
        
        /* GLU will again do the work.  draw the sides of the cylinder. */
        gluq = gluNewQuadric();
        gluQuadricDrawStyle( gluq, GLU_FILL );
        gluQuadricTexture( gluq, GL_TRUE );
        gluCylinder( gluq, r1, r2, h, divisions, divisions);
        gluDeleteQuadric( gluq );
        
        if ( r1 > 0.0 )
        {
        /* if the r1 end does not come to a point, draw a flat disk to
            cover it up. */
            
            gluq = gluNewQuadric();
            gluQuadricDrawStyle( gluq, GLU_FILL );
            gluQuadricTexture( gluq, GL_TRUE );
            gluQuadricOrientation( gluq, GLU_INSIDE );
            gluDisk( gluq, 0.0, r1, divisions, divisions);
            gluDeleteQuadric( gluq );
        }
        
        if ( r2 > 0.0 )
        {
        /* if the r2 end does not come to a point, draw a flat disk to
            cover it up. */
            
            /* save the current matrix mode. */	
            int savemode;
            glGetIntegerv( GL_MATRIX_MODE, &savemode );
            
            /* translate the origin to the other end of the cylinder. */
            glMatrixMode( GL_MODELVIEW );
            glPushMatrix();
            glTranslated( 0.0, 0.0, h );
            
            /* draw a disk centered at the new origin. */
            gluq = gluNewQuadric();
            gluQuadricDrawStyle( gluq, GLU_FILL );
            gluQuadricTexture( gluq, GL_TRUE );
            gluQuadricOrientation( gluq, GLU_OUTSIDE );
            gluDisk( gluq, 0.0, r2, divisions, divisions);
            gluDeleteQuadric( gluq );
            
            /* restore the matrix stack and mode. */
            glPopMatrix();
            glMatrixMode( savemode );
        }
    }
    
}
Esempio n. 7
0
  //draw axis
  void GlWidget::drawAxis()

  {
      GLdouble dAxisLength=1.0;
      GLdouble  dAxisRadius=0.05;
      GLdouble  dArrowLength=0.1;
      GLdouble  dArrowRadius=0.1;
      float     fScale=0.1;
      GLint     iSlices=32;
      GLint     iStacks=32;
      GLfloat   fColorX[4]={1.0,0.0,0.0,1.0};
      GLfloat   fColorY[4]={0.0,1.0,0.0,1.0};
      GLfloat   fColorZ[4]={0.0,0.0,1.0,1.0};
      bool      bSolid=true;
      bool      bBlend=true;
      GLdouble dArrowPosn = dAxisLength;// - (dArrowLength/2);
      GLfloat fCurrentColor[4];

      // Get the current color
      glGetFloatv(GL_CURRENT_COLOR, fCurrentColor);

      // Save the current transformation matrix..
      glPushMatrix();

      // Create a quadratic object used to draw our axis
      // cylinders and cones
      GLUquadricObj* pQuadric = gluNewQuadric();
      if(!pQuadric)
          return;

      // Set the quadric state
      gluQuadricNormals(pQuadric, GLU_SMOOTH);
      gluQuadricTexture(pQuadric, GL_FALSE);

      if(bSolid)
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
          gluQuadricDrawStyle(pQuadric, GLU_FILL);
      }
      else
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
          gluQuadricDrawStyle(pQuadric, GLU_LINE);
      }

      // Enable alpha blending?
      if(bBlend)
      {
          glEnable(GL_BLEND);
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      }

      // Display a Sphere at the axis origin
      glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
      gluSphere(pQuadric, dAxisRadius*fScale*2.5f, iSlices, iStacks);

      // Display the Z-Axis and arrow
      // Set the color
      glColor4fv(fColorZ);

      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Display the X-Axis and arrow
      // Set the color
      glColor4fv(fColorX);

      glRotated(90, 0.0, 1.0, 0.0);                   // Rotate for X
      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Display the Y-Axis and arrow
      // Set the color
      glColor4fv(fColorY);

      glRotated(-90, 1.0, 0.0, 0.0);                  // Rotate for Y
      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Delete the quadric
      gluDeleteQuadric(pQuadric);

      // Restore the current transformation matrix..
      glPopMatrix();

      // Restore the current color
      glColor4fv(fCurrentColor);

      // Disable blend function
      glDisable(GL_BLEND);
  }
Esempio n. 8
0
static int ltgl_graphics_primitive(const GRAPHICS_PRIMITIVE *gp, const TRANSSYS_INSTANCE *transsys_instance, TURTLE_STATE **ts, const RENDER_PARAMETERS *rp)
{
  double arg[GRAPHICS_PRIMITIVE_ARGMAX];
  int i;

  for (i = 0; i < gp->num_arguments; i++)
    arg[i] = evaluate_expression(gp->argument[i], &transsys_instance);
  switch (gp->type)
  {
  case GRAPHICS_PUSH:
    *ts = push_turtle_state(*ts);
    break;
  case GRAPHICS_POP:
    *ts = pop_turtle_state(*ts);
    ltgl_setcolor(*ts, rp);
    break;
  case GRAPHICS_MOVE:
    turtle_move(*ts, arg[0]);
    break;
  case GRAPHICS_TURN:
    turtle_turn(*ts, arg[0]);
    break;
  case GRAPHICS_ROLL:
    turtle_roll(*ts, arg[0]);
    break;
  case GRAPHICS_BANK:
    turtle_bank(*ts, arg[0]);
    break;
  case GRAPHICS_SPHERE:
    glPushMatrix();
    glTranslatef((*ts)->position.x, (*ts)->position.y, (*ts)->position.z);
    /* fprintf(stderr, "ltgl_graphics_primitive: sphere at (%f, %f, %f)\n", (*ts)->position.x, (*ts)->position.y, (*ts)->position.z); */
    ltgl_rotate_q(&((*ts)->orientation));
    gluSphere(glu_quadric_object, arg[0], 10, 7);
    glPopMatrix();
    break;
  case GRAPHICS_CYLINDER:
    glPushMatrix();
    glTranslatef((*ts)->position.x, (*ts)->position.y, (*ts)->position.z);
    ltgl_rotate_q(&((*ts)->orientation));
    glTranslatef(0.0, 0.0, -0.5 * arg[1]);
    gluQuadricOrientation(glu_quadric_object, GLU_INSIDE);
    gluDisk(glu_quadric_object, 0.0, arg[0], 10, 1);
    gluQuadricOrientation(glu_quadric_object, GLU_OUTSIDE);
    if (arg[1] > 0.0)
    {
      gluCylinder(glu_quadric_object, arg[0], arg[0], arg[1], 10, 1);
    }
    glTranslatef(0.0, 0.0, arg[1]);
    gluDisk(glu_quadric_object, 0.0, arg[0], 10, 1);
    glPopMatrix();
    break;
  case GRAPHICS_BOX:
    glPushMatrix();
    glTranslatef((*ts)->position.x, (*ts)->position.y, (*ts)->position.z);
    ltgl_rotate_q(&((*ts)->orientation));
    ltgl_box(arg[0], arg[1], arg[2]);
    glPopMatrix();
    break;
  case GRAPHICS_COLOR:
    (*ts)->red = arg[0];
    (*ts)->green = arg[1];
    (*ts)->blue = arg[2];
    ltgl_setcolor(*ts, rp);
    break;
  default:
    fprintf(stderr, "postscript_graphics_primitive: primitive type %d not implemented\n", (int) gp->type);
    return (-1);
  }
  return (0);
}
Esempio n. 9
0
void GLSphere::draw()
{
   if (m_red >= 0) glColor3i(m_red, m_blue, m_green);
   gluQuadricOrientation(s_quadric, GLU_OUTSIDE);
   gluSphere(s_quadric, m_radius, 2*m_segments, m_segments);
}
Esempio n. 10
0
int main(int argc, char* argv[])
{
    // Args
    if(argc > 1)
    {
        if(!strcmp(argv[1], "-r"))
        {
            printf("Record mode, will use default recording device.\n\n");
            record = true;
        }
        else
        {
            record = false;
            printf("Going to play %s\n\n", argv[1]);
            sound_file = argv[1];
        }
        if(argc > 2)
        {
            if(!strcmp(argv[2], "-f"))
            {
                fullscreen = true;
            }
            if(argc > 4)
            {
                WINDOW_WIDTH = atoi(argv[3]);
                WINDOW_HEIGHT = atoi(argv[4]);
            }
        }
    }
    else
    {
        printf("Usage: visualizer -r [-f width height]\n       visualizer <filename> [-f width height]\n\n -r: record from default audio source\n  filename: audio file to play\n\n -f width height: fullscreen at width*height resolution.\n", argv[0]);
        return 0;
    }

    // Intialize SDL, OpenGL context, etc.
    if (init() == false)
    {
        return -1;
    }

    printf("\nInitialization complete. Enjoy!\n");

    shader_init();

    // Uniform locations
    GLint time_loc = glGetUniformLocation(p, "time");
    GLint amplitude_loc = glGetUniformLocation(p, "amplitude");
    GLint high_freq_loc = glGetUniformLocation(p, "high_freq");
    GLint low_freq_loc = glGetUniformLocation(p, "low_freq");
    GLint texture_loc = glGetUniformLocation(p, "texture");
    GLint low_freq_max_loc = glGetUniformLocation(p, "low_freq_max");

    // Scene
    //
    // Sphere
    GLUquadric* quadric = gluNewQuadric();
    gluQuadricNormals(quadric, GLU_SMOOTH);
    gluQuadricTexture(quadric, GL_TRUE);
    gluQuadricOrientation(quadric, GLU_OUTSIDE);

    // Lights
    GLfloat light_0_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
    GLfloat light_0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
    GLfloat light_0_position[] = {0.0f, 0.0f, 1.0f, 0.0f};
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_0_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_0_diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, light_0_position);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_COLOR_MATERIAL);

    // Textures and FBOs
    glGenTextures(1, &fbo_texture_id);
    glBindTexture(GL_TEXTURE_2D, fbo_texture_id);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap generation included in OpenGL v1.4
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, FBO_TEXTURE_WIDTH, FBO_TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindTexture(GL_TEXTURE_2D, 0);

    glGenFramebuffersEXT(1, &fbo_id);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id);
    glGenRenderbuffersEXT(1, &rbo_id);

    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbo_id);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, FBO_TEXTURE_WIDTH, FBO_TEXTURE_HEIGHT);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo_texture_id, 0);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rbo_id);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);


    bool quit = false;

    unsigned int length;
    bool playing = false;
    bool recording  = false;
    bool looping = true;
    unsigned int recordpos = 0;
    unsigned int playpos = 0;

    int i;
    float instant_spectrum[256];
    float instant_spectrum_l[256];
    float instant_spectrum_r[256];

    float rot_angle;

    while (quit == false)
    {
        // Grab spectrums
        result = channel->getSpectrum(instant_spectrum_l, 256, 0, FMOD_DSP_FFT_WINDOW_RECT);
        if(!record)
        {
            result = channel->getSpectrum(instant_spectrum_r, 256, 1, FMOD_DSP_FFT_WINDOW_RECT);
        }
        FMODErrorCheck(result);

        // Merge stereo
        for(i = 0; i < 256; i++)
        {
            if(record)
            {
                instant_spectrum[i] = 10.0f * (float)log10(instant_spectrum_l[i]/2.0f) * 2.0f;
            }
            else
            {
                instant_spectrum[i] = 10.0f * (float)log10((instant_spectrum_l[i] + instant_spectrum_r[i])/2.0f) * 2.0f;
            }
        }
        //instant_spectrum[255] = 0;

        // Rolling spectrum average
        for(i = 7; i >= 1; i = i - 1)
        {
            arrayCopy(256, spectrum[i-1], spectrum[i]);
        }
        arrayCopy(256, instant_spectrum, spectrum[0]);

        int j;
        for(j = 0; j < 256; j++)
        {
            rolling_spectrum[j] = 0;
            for(i = 0; i < 8; i++)
            {
                 rolling_spectrum[j] += spectrum[i][j];
            }
            rolling_spectrum[j] = rolling_spectrum[j] / 8.0f;
        }

        float max = -100.0f;
        int max_index = 0;
        for(i = 0; i < 256; i++)
        {
            if(rolling_spectrum[i] > max)
            {
                    max = rolling_spectrum[i];
                    max_index = i;
            }
        }

         // Normalize
        float low_avg = 0;
        float low_mid_avg = 0;
        float mid_avg = 0;
        float high_avg = 0;

        float low_max = 0;
        float low_mid_max = 0;
        float mid_max = 0;
        float high_max = 0;
        int low_max_index = 0;
        int low_mid_max_index = 0;
        int mid_max_index = 0;
        int high_max_index = 0;

        for(i = 0; i < 256; i++)
        {
            processed_spectrum[i] = (rolling_spectrum[i] + 100)/(100);
            if(i < 64)
            {
                low_avg += processed_spectrum[i];
                if(processed_spectrum[i] > low_max)
                {
                    low_max = processed_spectrum[i];
                    low_max_index = i;
                }
            }
            else if(i < 128 && i >= 64)
            {
                low_mid_avg += processed_spectrum[i];
                if(processed_spectrum[i] > low_mid_max)
                {
                    low_mid_max = processed_spectrum[i];
                    low_mid_max_index = i;
                }
            }
            else if(i < 196 && i >= 128)
            {
                mid_avg += processed_spectrum[i];
                if(processed_spectrum[i] > mid_max)
                {
                    mid_max = processed_spectrum[i];
                    mid_max_index = i;
                }
            }
            else if(i < 256 && i >= 196 )
            {
                high_avg += processed_spectrum[i];
                if(processed_spectrum[i] > high_max)
                {
                    high_max = processed_spectrum[i];
                    high_max_index = i;
                }
            }
        }

        low_avg = low_avg/64.0f;
        low_mid_avg = low_mid_avg/64.0f;
        mid_avg = mid_avg/64.0f;
        high_avg = high_avg/64.0f;

        float high_freq_avg = 0;
        float low_freq_avg  = 0;
        float high_freq_max = spectrum_freq*(low_mid_max_index+1);
        float low_freq_max = spectrum_freq*(low_max_index+1);
        for(i = 63; i >= 1; i = i-1)
        {
            low_freq_samples[i] = low_freq_samples[i-1];
            high_freq_samples[i] = high_freq_samples[i-1];
        }
        high_freq_samples[0] = high_freq_max;
        low_freq_samples[0] = low_freq_max;

        for(i = 0; i < 64; i++)
        {
            high_freq_avg += high_freq_samples[i];
            low_freq_avg += low_freq_samples[i];
        }
        high_freq_avg = high_freq_avg / 64.0f;
        low_freq_avg = low_freq_avg / 64.0f;

        //printf("dominant high freq: %f dominant low freq: %f\n", high_freq_avg, low_freq_avg);

        // OpenGL
        // Uniforms for shaders
        glUniform1f(time_loc, (GLfloat)SDL_GetTicks()*0.001);
        //glUniform1f(amplitude_loc, 8.0f*smoothstep(-1, 1, log(low_mid_max/low_mid_avg)));
        glUniform1f(amplitude_loc, 0.5/normalize(low_avg, low_max));
        glUniform1f(high_freq_loc, high_freq_avg);
        glUniform1f(low_freq_loc, low_freq_avg);
        glUniform1f(low_freq_max_loc, low_freq_max);

        printf("low: %f  high: %f  midmax-mid %f\n", low_freq_avg, high_freq_avg, 1/normalize(low_avg, low_max));

        // Into the FBO
        glViewport(0, 0, FBO_TEXTURE_WIDTH, FBO_TEXTURE_HEIGHT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60.0f, (float)(FBO_TEXTURE_WIDTH)/FBO_TEXTURE_HEIGHT, 1.0f, 100.0f);
        glMatrixMode(GL_MODELVIEW);

        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id);
        glClearColor(1, 1, 1, 1);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glTranslatef(0.0f, 0.0f, -50.0f);
        glColor4f(0.4f, 0.2f, 1.0f, 1.0f);
        gluSphere(quadric, 8.0f, 64, 64);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

        glBindTexture(GL_TEXTURE_2D, fbo_texture_id);
        glGenerateMipmapEXT(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 0);

        // Normal render
        glViewport(0, 0, (GLsizei) WINDOW_WIDTH, (GLsizei) WINDOW_HEIGHT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60.0f, (GLfloat)WINDOW_WIDTH/(GLfloat)WINDOW_HEIGHT, 0.1f, 100.0f);
        glMatrixMode (GL_MODELVIEW);
        glLoadIdentity();

        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity ();

        glBindTexture(GL_TEXTURE_2D, fbo_texture_id);
        glUniform1f(texture_loc, fbo_texture_id);

        rot_angle += 0.9f;

        glTranslatef(0.0f, 0.0f, -40.0f);
        glRotatef(rot_angle,0.0f,1.0f,0.0f);
        glRotatef(20,0.0f,0.0f,1.0f);
        glColor4f(0.4f, 0.2f, 1.0f, 1.0f);
        gluSphere(quadric, 8.0f, 64, 64);



        glFlush();
        glFinish();
        SDL_GL_SwapBuffers();

        // FMOD
        fmod_system->update();

        result = sound->getLength(&length, FMOD_TIMEUNIT_PCM);
        FMODErrorCheck(result);

        result = fmod_system->isRecording(0, &recording);
        FMODErrorCheck(result);

        result = fmod_system->getRecordPosition(0, &recordpos);
        FMODErrorCheck(result);

        if (channel)
        {
            result = channel->isPlaying(&playing);
            FMODErrorCheck(result);

            result = channel->getPosition(&playpos, FMOD_TIMEUNIT_PCM);
            FMODErrorCheck(result);
        }

        //printf("State: %-19s. Record pos = %6d : Play pos = %6d : Loop %-3s\r", recording ? playing ? "Recording / playing" : "Recording" : playing ? "Playing" : "Idle", recordpos, playpos, looping ? "On" : "Off");

        // SDL
        while (SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                quit = true;
            }
            else if(event.type == SDL_KEYDOWN)
            {
                switch(event.key.keysym.sym)
                {
                    case SDLK_ESCAPE:
                        quit = true;
                        break;
                    case SDLK_f:
                        break;
                }
            }
        }

    }

    fmod_system->release();
    SDL_Quit();
    return 0;
}
Esempio n. 11
0
void compoe_computador_dir(void){

  GLUquadricObj *quadric;
  // inicia a composicao do computador
  comp_dir = glGenLists(1);
  glNewList(comp_dir, GL_COMPILE);
  quadric = gluNewQuadric();
  //gluQuadricTexture(quadric, GL_TRUE);

  GLfloat lado, atras;
  //compoe computador do lado da porta, 4 colunas
  for(int i = 0; i<4; i++){
    atras = i * 10.0;
    //3 computadores lado a lado
    for(int j=0; j<3; j++){
      lado = j * 6.0;

      //base tela
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE); 
      glPushMatrix();  
      //tras/frente - direita/esquerda - cima/baixo 
      glRotatef(90,1,0,0);
      glTranslatef (-19-lado, 6.0-atras, 3.9);    
      SOLID_CLOSED_CYLINDER(quadric, 1., 1., 0.15, 30, 1)
      gluDeleteQuadric(quadric);
      glPopMatrix();

      //apoio tela
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      glPushMatrix();   
      glRotatef(90,1,0,0);  
      glTranslatef (-19-lado, 6.8-atras, 2.0);
      //tras/frente - direita/esquerda - cima/baixo 
      SOLID_CLOSED_CYLINDER(quadric, 0.25, 0.25, 2., 30, 1)
      gluDeleteQuadric(quadric);
      glPopMatrix();

      //tela
      glPushMatrix();
      //tras/frente - cima/baixo - direita/esquerda 
      glTranslatef (-19-lado, -1.7, 6.5-atras);
      glScalef (3., 3., 0.2);
      glutSolidCube (1.0);
      glPopMatrix();

      glColor3f(1,1,1);
      draw_wall(-17.7-lado, -0.3, 6.35-atras,
      -20.3-lado, -0.3, 6.35-atras,
      -20.3-lado, -3, 6.35-atras,
      -17.7-lado, -3, 6.35-atras, 5);

      glColor3f(0.2,0.2, 0.2); 

      //cpu
      glPushMatrix();
      //tras/frente - cima/baixo - direita/esquerda 
      glTranslatef (-21.3-lado, -2.8, 6.0-atras);
      glScalef (1., 3., 3.);
      glutSolidCube (1.0);
      glPopMatrix();


      draw_wall(-21.8-lado, -1.3, 4.45-atras,
      -20.8-lado, -1.3, 4.45-atras,
      -20.8-lado, -4, 4.45-atras,
      -21.8-lado, -4, 4.45-atras, 6); 

      //teclado

      glColor3f(0.5,0.5, 0.5);


      glPushMatrix();
      //tras/frente - cima/baixo - direita/esquerda 
      glTranslatef (-18.7-lado, -4.0, 4.0-atras);
      glScalef (2.9, 0.2, 1.2);
      glutSolidCube (1.0);
      glPopMatrix();

      draw_wall(-17.3-lado, -3.89, 4.5-atras,
      -20.1-lado, -3.89, 4.5-atras,
      -20.1-lado, -3.89, 3.4-atras,
       -17.3-lado, -3.89, 3.4-atras, 4); 


      glColor3f(0.15,0.15,0.15);

       

      //mouse
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      glPushMatrix();
      //tras/frente - cima/baixo - direita/esquerda 
      glTranslatef (-21-lado, -4.1, 4.0-atras);
      gluSphere(quadric, 0.25, 30,15);
      gluDeleteQuadric(quadric);
      glPopMatrix();
    }
  }
} 
Esempio n. 12
0
void Trogdor::drawNeckHead(){
		x_trans = 0.0;
		y_trans = 0.0;
		z_trans = 3.0;
		
		glPushMatrix();
		//textures
		glBindTexture(GL_TEXTURE_2D, texArr[t1]);
		gluQuadricTexture(cyl, GLU_TRUE);
		gluQuadricTexture(sph, GLU_TRUE);

		gluQuadricNormals(cyl, GLU_SMOOTH);		// specify one normal per vertex.
		gluQuadricOrientation(cyl, GLU_OUTSIDE);  //points normals outward
		gluQuadricNormals(sph, GLU_SMOOTH);		// specify one normal per vertex.
		gluQuadricOrientation(sph, GLU_OUTSIDE);  //points normals outward

		glColor4f(0, 0.25, 0, 1);

		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		z_trans = 0.75;
		y_trans = 0.35;
		radius_sph = 0.9;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		z_trans = 0.40;
		y_trans = 0.5;
		radius_sph = 0.75;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		z_trans = 0.1;
		y_trans = 0.5;
		radius_sph = 0.6;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		for(int i = 0; i < 5; i++){
			y_trans = 0.5;
			z_trans = 0.05;
			radius_sph -= 0.05;
			glTranslatef(x_trans, y_trans, z_trans);
			gluSphere(sph, radius_sph, slice_sph, stack_sph);
		}

		for(int i = 0; i < 5; i++){
			y_trans = 0.35;
			z_trans = 0.0;
			glTranslatef(x_trans, y_trans, z_trans);
			gluSphere(sph, radius_sph, slice_sph, stack_sph);
		}

		z_trans = 0.2;
		radius_sph = 0.5;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		//head
		y_trans = 0.0;
		z_trans = 0.15;
		glTranslatef(x_trans, y_trans, z_trans);

		glColor4f(0, 0.25, 0, 1);
		gluCylinder(cyl, radius_sph, 0.0, 2.0, slice_sph, stack_sph);

		//eyes
		x_trans = radius_sph/2;
		y_trans = radius_sph/2;
		z_trans = 0.0;

		glColor4f(1, 1, 1, 1);
		glBindTexture(GL_TEXTURE_2D, texArr[t2]);

		glTranslatef(x_trans, y_trans, z_trans);
		glRotatef(105, 0, 0, 1);
		gluSphere(sph, 0.2, slice_sph, stack_sph);
		glRotatef(-105, 0, 0, 1);
		glTranslatef(-x_trans, -y_trans, -z_trans);

		glTranslatef(-x_trans, y_trans, z_trans);
		glRotatef(-105, 0, 0, 1);
		gluSphere(sph, 0.2, slice_sph, stack_sph);
		glRotatef(105, 0, 0, 1);
		glTranslatef(x_trans, -y_trans, -z_trans);

		//horns
		z_trans = -radius_sph;
		glTranslatef(x_trans, y_trans, z_trans);
		glRotatef(225.0, 0, 0, 0);
		glColor3f(1, 0, 0);

		glColor4f(1, 1, 1, 1);
		glBindTexture(GL_TEXTURE_2D, texArr[t3]);
		gluCylinder(cyl, 0.1, 0.0, 2.0, slice_sph, stack_sph); 

		glRotatef(-225.0, 0, 0, 0);
		glTranslatef(-x_trans, -y_trans, -z_trans);

		glTranslatef(-x_trans, y_trans, z_trans);
		glRotatef(225.0, 0, 0, 0);

		gluCylinder(cyl, 0.1, 0.0, 2.0, slice_sph, stack_sph);

		glRotatef(-225.0, 0, 0, 0);
		glTranslatef(x_trans, -y_trans, -z_trans);
	glPopMatrix();
}
Esempio n. 13
0
void Trogdor::drawTail(){
	x_trans = 0.0;
	y_trans = 0.0;
	z_trans = -3.0;
	glPushMatrix();	
		//textures
		glBindTexture(GL_TEXTURE_2D, texArr[t1]);
		gluQuadricTexture(cyl, GLU_TRUE);
		gluQuadricTexture(sph, GLU_TRUE);

		gluQuadricNormals(cyl, GLU_SMOOTH);		// specify one normal per vertex.
		gluQuadricOrientation(cyl, GLU_OUTSIDE);  //points normals outward
		gluQuadricNormals(sph, GLU_SMOOTH);		// specify one normal per vertex.
		gluQuadricOrientation(sph, GLU_OUTSIDE);  //points normals outward

		glColor4f(0, 0.25, 0, 1);

		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		x_trans = 0;
		z_trans = -0.75;
		y_trans = 0.35;
		radius_sph = 0.9;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		x_trans = 0;
		z_trans = -0.40;
		y_trans = 0.5;
		radius_sph = 0.75;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		x_trans = 0;
		z_trans = -0.1;
		y_trans = 0.5;
		radius_sph = 0.6;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		x_trans = 0;
		for(int i = 0; i < 5; i++){
			y_trans = 0.5;
			z_trans = -0.05;
			radius_sph -= 0.05;
			glTranslatef(x_trans, y_trans, z_trans);
			gluSphere(sph, radius_sph, slice_sph, stack_sph);
		}

		x_trans = 0;
		y_trans = 0.25;
		z_trans = -0.1;
		radius_sph -= 0.05;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		x_trans = 0;
		y_trans = 0.15;
		z_trans = -0.15;
		radius_sph -= 0.05;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		x_trans = 0;
		y_trans = 0.05;
		z_trans = -0.2;
		radius_sph -= 0.05;
		glTranslatef(x_trans, y_trans, z_trans);
		gluSphere(sph, radius_sph, slice_sph, stack_sph);

		x_trans = 0;
		y_trans = 0.0;
		z_trans = -0.2;
		glTranslatef(x_trans, y_trans, z_trans+0.2);
		glRotatef(180.0, 0, 0, 0);

		glColor4f(1, 1, 1, 1);
		glBindTexture(GL_TEXTURE_2D, texArr[t3]);
		gluCylinder(cyl, radius_sph, 0.0, 2.0, slice_sph, stack_sph);	
	glPopMatrix();
	
}
Esempio n. 14
0
void
Redraw(void)
    {
    int               i, j;
    static GLUquadric *qobj    = NULL;
    static float      red_light[4]  = {  1.0,  0.0,  0.0,  1.0 };
    static float      red_pos[4]    = {  1.0,  1.0,  1.0,  0.0 };
    static float      blue_light[4] = {  0.0,  0.0,  1.0,  1.0 };
    static float      blue_pos[4]   = { -1.0, -1.0, -1.0,  0.0 };
    static GLfloat    cube_verts[][3] =
        {
	    { -1.0, -1.0,  1.0 }, /* Front bottom left */
	    {  1.0, -1.0,  1.0 }, /* Front bottom right */
	    {  1.0,  1.0,  1.0 }, /* Front top right */
	    { -1.0,  1.0,  1.0 }, /* Front bottom left */
	    { -1.0, -1.0, -1.0 }, /* Back bottom left */
	    {  1.0, -1.0, -1.0 }, /* Back bottom right */
	    {  1.0,  1.0, -1.0 }, /* Back top right */
	    { -1.0,  1.0, -1.0 }  /* Back bottom left */
	};
    static GLfloat    cube_norms[][3] =
        {
	    {  0.0,  0.0,  1.0 }, /* Front */
	    {  0.0,  0.0, -1.0 }, /* Back */
	    { -1.0,  0.0,  0.0 }, /* Left */
	    {  1.0,  0.0,  0.0 }, /* Right */
	    {  0.0, -1.0,  0.0 }, /* Bottom */
	    {  0.0,  1.0,  0.0 }  /* Top */
	};
    static int        cube_points[6][4] =
        {
	    { 0, 1, 2, 3 },       /* Front */
	    { 7, 6, 5, 4 },       /* Back */
	    { 4, 0, 3, 7 },       /* Left */
	    { 1, 5, 6, 2 },       /* Right */
	    { 1, 0, 4, 5 },       /* Bottom */
	    { 3, 2, 6, 7 }        /* Top */
	};

    /* Enable drawing features that we need... */
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);

    glShadeModel(GL_SMOOTH);
    glDepthFunc(DepthFunc); 

    /* Clear the color and depth buffers... */

    if (DepthFunc == GL_LESS)
        glClearDepth(1.0);
    else
        glClearDepth(0.0);

    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /*
     * Draw the cube and sphere in different colors...
     *
     * We have positioned two lights in this scene.  The first is red
     * and located above, to the right, and behind the viewer.  The
     * second is blue and located below, to the left, and in front of
     * the viewer.
     */

    glLightfv(GL_LIGHT0, GL_DIFFUSE, red_light);
    glLightfv(GL_LIGHT0, GL_POSITION, red_pos);

    glLightfv(GL_LIGHT1, GL_DIFFUSE, blue_light);
    glLightfv(GL_LIGHT1, GL_POSITION, blue_pos);

    glPushMatrix();
    glTranslatef(-1.0, 0.0, -20.0);
    if (!qobj)
        {
	qobj = gluNewQuadric();
	gluQuadricOrientation(qobj, GLU_OUTSIDE);
	}
    gluSphere(qobj, 1.0, 36, 18);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(1.0, 0.0, -20.0);
    glRotatef(15.0, 0.0, 1.0, 0.0);
    glRotatef(15.0, 0.0, 0.0, 1.0);
    glBegin(GL_QUADS);
    for (i = 0; i < 6; i ++)
        {
        glNormal3fv(cube_norms[i]);
        for (j = 0; j < 4; j ++)
	    glVertex3fv(cube_verts[cube_points[i][j]]);
	}
    glEnd();
    glPopMatrix();

    glFinish();
    }
Esempio n. 15
0
File: fire.c Progetto: xtmacbook/SGI
void init(void)
{
    static unsigned *image;
    static int width, height, components;
    char fname[sizeof("../Data/Natural/flame/f00") + 1];
    GLUquadric *cylinder;
    int i, j, duration, d;
    GLfloat oscale, nscale, scale, start;

    /* save the flame sequence into a set of texture objects */
    /* linear ramp between brightnesses */
    d = duration = 1 + drand48() * 4;
    start = oscale  = drand48() * 3/4.f + .25f; /* 1/4 to 1 */
    nscale = drand48() * 3/4.f + .25f; /* 1/4 to 1 */
    for(i = 0; i < flameCount; i++)
    {

	(void)sprintf(fname, "../../data/flame/f%.2d",i);
	image = read_texture(fname, &width, &height, &components);

	glBindTexture(GL_TEXTURE_2D, i);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, components, width,
                 height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 image);

	free(image);
	
	
	if(!d)
	{
	    d = duration = 1 + drand48() * 4;
	    if(d >= flameCount - i) /* make wraparound cleaner */
	    {
		d = duration = flameCount - i;
		nscale = start;
	    }
	    oscale = nscale;
	    nscale = drand48() * 3/4.f + .25f; /* 1/4 to 1 */
	}
	scale = d/(GLfloat)duration * oscale
	        + (1 - d/(GLfloat)duration) * nscale;
	d -= 1;

	firelight[i * 4 + R] = firecolor[R] * scale;
	firelight[i * 4 + G] = firecolor[G] * scale;
	firelight[i * 4 + B] = firecolor[B] * scale;
	firelight[i * 4 + A] = 1.f;
    }
    glAlphaFunc(GL_GREATER, .9f);

    glEnable(GL_ALPHA_TEST);
    glEnable(GL_DEPTH_TEST);

    /* turn on lighting, enable light 0, and turn on colormaterial */
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);

    glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 1.f);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, firelight);

    /* shift the flame texture down a little on the flame polygon */
    glMatrixMode(GL_TEXTURE);
    glTranslatef(0.f, .15f, 0.f);

    glMatrixMode(GL_PROJECTION);
    gluPerspective(50., 1., .1, 10.);

    glMatrixMode(GL_MODELVIEW);
    glTranslatef(0., 0., -5.5);

    /* geometry for the base of the flame */
    glNewList(FLAME_BASE, GL_COMPILE);
    glColor3f(.2f, .2f, .2f);
    glPushMatrix();
    glTranslatef(0.f, -.9f, 0.f);
    glRotatef(90.f, 1.f, 0.f, 0.f);
    cylinder = gluNewQuadric();
    gluQuadricOrientation(cylinder, GLU_INSIDE);
    gluCylinder(cylinder, .5, .5, .1, 20, 20);
    gluDisk(cylinder, 0.f, .5, 20, 20);
    gluDeleteQuadric(cylinder);
    glPopMatrix();
    glEndList();


    /* geometry for the ground */
    glNewList(GROUND, GL_COMPILE);
    glColor4f(0.6f, 0.8f, 0.5f, 1.f);
    glBegin(GL_QUADS);
    glNormal3f(0.f, 1.f, 0.f);
    for(j = 0; j < 20; j++) /* z direction */
	for(i = 0; i < 20; i++) /* x direction */
	{
	    glVertex3f(-2.0 + i * 4.f/20, -1.0, -2.0 + j * 4.f/20);
	    glVertex3f(-2.0 + i * 4.f/20, -1.0, -2.0 + (j + 1) * 4.f/20);
	    glVertex3f(-2.0 + (i + 1) * 4.f/20, -1.0, -2.0 + (j + 1) * 4.f/20);
	    glVertex3f(-2.0 + (i + 1) * 4.f/20, -1.0, -2.0 + j * 4.f/20);
	}
    glEnd();
    glEndList();
}
Esempio n. 16
0
void Sphere::draw() 
{
		gluQuadricTexture(quad,GL_TRUE);
		gluQuadricOrientation(quad,GLU_OUTSIDE);
		gluSphere(quad,radius,slices,stacks);
}
Esempio n. 17
0
void Spinner::Draw()
{
	glPushMatrix();
	glTranslatef(m_x, m_y, m_z);
	glRotatef(w*360/TwoPi, 0.0, 0.0, 1.0);
	glCallList(dlSpinner);

	glTranslatef(0,0,5);

	//1----------------------------------
	glPushMatrix();
	glTranslatef(m_baseradius-2+0.707f*(m_baseradius+2),0,0.707f*(m_baseradius+2));
	glRotatef(m_zeta0*360/TwoPi, 0.0, 1.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius, 8, 1);
	glTranslatef(0,0,m_baseradius);
	gluSphere(quadratic, 1.2f, 12, 6);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(m_baseradius-2+0.707f*(m_baseradius+2)+m_baseradius*sin(m_zeta0),0,0.707f*(m_baseradius+2)+m_baseradius*cos(m_zeta0));
	glRotatef(90, 0.0, 1.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius/2, 8, 1);
	//draw the end cap
	glTranslatef( 0,0,m_baseradius/2 );
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, 1.0f, 16, 1);
	glTranslatef( 0,0,-m_baseradius/2 );

	glTranslatef(-1.0f,0,m_baseradius/2-1.0f);
	glRotatef(90, 0.0, 1.0, 0.0);
	gluCylinder(quadratic, m_baseradius/4, m_baseradius/4, 0.5f, 8, 1);
	//draw the first cap
	gluQuadricOrientation(quadratic,GLU_INSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glTranslatef( 0,0,0.5f );
	//draw the second cap
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glPopMatrix();

	//2----------------------------------
	glPushMatrix();
	glTranslatef(-m_baseradius+2-0.707f*(m_baseradius+2),0,0.707f*(m_baseradius+2));
	glRotatef(-m_zeta2*360/TwoPi, 0.0, 1.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius, 8, 1);
	glTranslatef(0,0,m_baseradius);
	gluSphere(quadratic, 1.2f, 12, 6);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(-m_baseradius+2-0.707f*(m_baseradius+2)-m_baseradius*sin(m_zeta2),0,0.707f*(m_baseradius+2)+m_baseradius*cos(m_zeta2));
	glRotatef(-90, 0.0, 1.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius/2, 8, 1);
	//draw the end cap
	glTranslatef( 0,0,m_baseradius/2 );
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, 1.0f, 16, 1);
	glTranslatef( 0,0,-m_baseradius/2 );

	glTranslatef(1.0f,0,m_baseradius/2-1.0f);
	glRotatef(90, 0.0, 1.0, 0.0);
	gluCylinder(quadratic, m_baseradius/4, m_baseradius/4, 0.5f, 8, 1);
	//draw the first cap
	gluQuadricOrientation(quadratic,GLU_INSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glTranslatef( 0,0,0.5f );
	//draw the second cap
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glPopMatrix();

	//3----------------------------------
	glPushMatrix();
	glTranslatef(0,m_baseradius-2+0.707f*(m_baseradius+2),0.707f*(m_baseradius+2));
	glRotatef(-m_zeta1*360/TwoPi, 1.0, 0.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius, 8, 1);
	glTranslatef(0,0,m_baseradius);
	gluSphere(quadratic, 1.2f, 12, 6);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0,m_baseradius-2+0.707f*(m_baseradius+2)+m_baseradius*sin(m_zeta1),0.707f*(m_baseradius+2)+m_baseradius*cos(m_zeta1));
	glRotatef(-90, 1.0, 0.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius/2, 8, 1);
	//draw the end cap
	glTranslatef( 0,0,m_baseradius/2 );
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, 1.0f, 16, 1);
	glTranslatef( 0,0,-m_baseradius/2 );
	
	glTranslatef(-0.65f,-1.0,m_baseradius/2-1.0f);
	glRotatef(90, 1.0, 0.0, 0.0);
	gluCylinder(quadratic, m_baseradius/4, m_baseradius/4, 0.5f, 8, 1);
	//draw the first cap
	gluQuadricOrientation(quadratic,GLU_INSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glTranslatef( 0,0,0.5f );
	//draw the second cap
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glPopMatrix();

	//4----------------------------------
	glPushMatrix();
	glTranslatef(0,-m_baseradius+2-0.707f*(m_baseradius+2),0.707f*(m_baseradius+2));
	glRotatef(m_zeta3*360/TwoPi, 1.0, 0.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius, 8, 1);
	glTranslatef(0,0,m_baseradius);
	gluSphere(quadratic, 1.2f, 12, 6);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0,-m_baseradius+2-0.707f*(m_baseradius+2)-m_baseradius*sin(m_zeta3),0.707f*(m_baseradius+2)+m_baseradius*cos(m_zeta3));
	glRotatef(90, 1.0, 0.0, 0.0);
	gluCylinder(quadratic, 1.0f, 1.0f, m_baseradius/2, 8, 1);
	//draw the end cap
	glTranslatef( 0,0,m_baseradius/2 );
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, 1.0f, 16, 1);
	glTranslatef( 0,0,-m_baseradius/2 );

	glTranslatef(0.65f,1.0,m_baseradius/2-1.0f);
	glRotatef(90, 1.0, 0.0, 0.0);
	gluCylinder(quadratic, m_baseradius/4, m_baseradius/4, 0.5f, 8, 1);
	//draw the first cap
	gluQuadricOrientation(quadratic,GLU_INSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glTranslatef( 0,0,0.5f );
	//draw the second cap
	gluQuadricOrientation(quadratic,GLU_OUTSIDE);
	gluDisk( quadratic, 0.0, m_baseradius/4, 16, 1);
	glPopMatrix();

	glPopMatrix();
}
Esempio n. 18
0
//////////////////////////////////////////////////////////////////////////////
//
//	-	Sets up lights for the scene.
// -	Loads textures.
//	-	Allocates OpenGL quadric for the "node" spheres.
//	-	Originally I was going to read points from a text file, but with the
//		"Coma 2" party less than 2 weeks away, I opted to use this brute force
//		way of entering in the points.  Yes, I know it's hacky.  I should have
//		at least written a macro.
//
//	RETURNS: true,		On success.
//				false,	On failure.
//
//	THROWS:	char *
//
//////////////////////////////////////////////////////////////////////////////
bool CComaLogo::init()
{
	// Setup initial lights and positions
	m_ambientLight[0] = 0.2f;
	m_ambientLight[1] = 0.2f;
	m_ambientLight[2] = 0.2f;
	m_ambientLight[3] = 1.0f;

	m_diffuseLight[0] = 0.7f;
	m_diffuseLight[1] = 0.7f;
	m_diffuseLight[2] = 0.7f;
	m_diffuseLight[3] = 1.0f;
	
	m_lightPos[0] = fSHADOW_RANGE * 8;
	m_lightPos[1] = 60.0f;
	m_lightPos[2] = 10.0f;
	m_lightPos[3] = 1.0f;
	

	// Format: x, y, connecting nodes list...
	// Good luck, I did this on graph paper.

	// "O"
	// [[1 - 5]]
	m_vNodes.push_back(CNode(0,0,2,3));
	m_vNodes.push_back(CNode(0,1,5));
	m_vNodes.push_back(CNode(-1,1,2,4,5));
	m_vNodes.push_back(CNode(-2,2,6,14));
	m_vNodes.push_back(CNode(0,2,6,7));
	// [[6 - 10]]
	m_vNodes.push_back(CNode(-1,2,3));
	m_vNodes.push_back(CNode(1,2,8,19));
	m_vNodes.push_back(CNode(1,3,5,9));
	m_vNodes.push_back(CNode(2,4,10));
	m_vNodes.push_back(CNode(3,3,11,12,13));
	// [[11 - 15]]
	m_vNodes.push_back(CNode(2,3,8,9,12));
	m_vNodes.push_back(CNode(2,2,7,8,19));
	m_vNodes.push_back(CNode(4,4,28,61));	// to "M"
	m_vNodes.push_back(CNode(-3,3,15));
	m_vNodes.push_back(CNode(-4,4,16,37));	// to "C"
	// [[16 - 20]]
	m_vNodes.push_back(CNode(-3,5,17));
	m_vNodes.push_back(CNode(-2,6,18,21));
	m_vNodes.push_back(CNode(-2,5,16,20));
	m_vNodes.push_back(CNode(1,1,1,2,5));
	m_vNodes.push_back(CNode(-1,5,17,21,22));
	// [[21 - 25]]
	m_vNodes.push_back(CNode(-1,6,26,27));
	m_vNodes.push_back(CNode(-2,4,14,24,23,16,18));
	m_vNodes.push_back(CNode(-3,4,14,15,16));
	m_vNodes.push_back(CNode(-2,3,4,14,25));
	m_vNodes.push_back(CNode(-1,3,4,5,6,22));
	// [[26 - 30]]
	m_vNodes.push_back(CNode(-1,7,17));
	m_vNodes.push_back(CNode(0,6,20,26,33));
	m_vNodes.push_back(CNode(3,5,9,29,30));
	m_vNodes.push_back(CNode(3,4,9,10,13));
	m_vNodes.push_back(CNode(2,5,9,31));
	// [[31 - 35]]
	m_vNodes.push_back(CNode(1,5,9,27,33,32));
	m_vNodes.push_back(CNode(2,6,28,30,33));
	m_vNodes.push_back(CNode(1,6,34));
	m_vNodes.push_back(CNode(1,7,27,32,35,36));
	m_vNodes.push_back(CNode(0,8,26,36));
	// [[36 - 40]]
	m_vNodes.push_back(CNode(0,7,26,27));

	// "C"
	m_vNodes.push_back(CNode(LINK, LINK, 38, 59));
	m_vNodes.push_back(CNode(-6,6,39,42,47));
	m_vNodes.push_back(CNode(-5,7,40,41));
	m_vNodes.push_back(CNode(-6,7,38,41,42));

	// [[41 - 45]]
	m_vNodes.push_back(CNode(-6,8,42));
	m_vNodes.push_back(CNode(-7,7,43,44));
	m_vNodes.push_back(CNode(-7,6,38,44));
	m_vNodes.push_back(CNode(-8,6,45,46,47));
	m_vNodes.push_back(CNode(-9,5,46));

	// [[46 - 50]]
	m_vNodes.push_back(CNode(-8,5,50));
	m_vNodes.push_back(CNode(-7,5,46,43));
	m_vNodes.push_back(CNode(-10,4,45));
	m_vNodes.push_back(CNode(-9,4,45,48));
	m_vNodes.push_back(CNode(-8,4,45,47,49,51,52,53));

	// [[51 - 55]]
	m_vNodes.push_back(CNode(-9,3,48,49,52));
	m_vNodes.push_back(CNode(-8,3));
	m_vNodes.push_back(CNode(-7,3,52));
	m_vNodes.push_back(CNode(-8,2,51,52,53));
	m_vNodes.push_back(CNode(-7,2,53,54,56));

	// [[56 - 60]]
	m_vNodes.push_back(CNode(-6,2,53,57,58,59));
	m_vNodes.push_back(CNode(-7,1,54,55));
	m_vNodes.push_back(CNode(-6,1,57));
	m_vNodes.push_back(CNode(-5,1,58,60));
	m_vNodes.push_back(CNode(-6,0,57,58));

	// "M"
	// [[61 - 65]]
	m_vNodes.push_back(CNode(LINK,LINK,62));
	m_vNodes.push_back(CNode(6,6,63,81));
	m_vNodes.push_back(CNode(7,5,64,73));
	m_vNodes.push_back(CNode(6,4,65));
	m_vNodes.push_back(CNode(7,3,66,71,74));
	
	// [[66 - 70]]
	m_vNodes.push_back(CNode(6,2,67));
	m_vNodes.push_back(CNode(7,1,68,70,72,75));
	m_vNodes.push_back(CNode(6,0,69));
	m_vNodes.push_back(CNode(7,0,67));
	m_vNodes.push_back(CNode(8,0,69,76));

	// [[71 - 75]]
	m_vNodes.push_back(CNode(8,4,63,78,80));
	m_vNodes.push_back(CNode(8,2,65,77,79));
	m_vNodes.push_back(CNode(6,5,62,64));
	m_vNodes.push_back(CNode(6,3,64,66));
	m_vNodes.push_back(CNode(6,1,66,68));

	// [[76 - 80]]
	m_vNodes.push_back(CNode(8,1,67,72));
	m_vNodes.push_back(CNode(8,3,65,71));
	m_vNodes.push_back(CNode(8,5,63,83));
	m_vNodes.push_back(CNode(7,2,65,66,67));
	m_vNodes.push_back(CNode(7,4,63,64,65));

	// [[81 - 85]]
	m_vNodes.push_back(CNode(7,7,85,121));			// to "A"
	m_vNodes.push_back(CNode(7,6,62,63,81));
	m_vNodes.push_back(CNode(8,6,63,81,82,84));
	m_vNodes.push_back(CNode(8,7,81,85,86));
	m_vNodes.push_back(CNode(8,8,86));

	// [[86 - 90]]
	m_vNodes.push_back(CNode(9,7,83,91));//m_vNodes.push_back(CNode(9,7,83,92));
	m_vNodes.push_back(CNode(9,6,83,86,88));
	m_vNodes.push_back(CNode(9,5,83,89));
	m_vNodes.push_back(CNode(10,4,90,96));
	m_vNodes.push_back(CNode(10,5,88,91));

	// [[91 - 95]]	// Ack, two nodes not really needed for a good looking M
	m_vNodes.push_back(CNode(10,6,86,87,88,94));
	m_vNodes.push_back(CNode(LINK,LINK));	//	m_vNodes.push_back(CNode(10,7,93,91));
	m_vNodes.push_back(CNode(LINK,LINK));	//	m_vNodes.push_back(CNode(10,8,86,94));
	m_vNodes.push_back(CNode(11,7,92,97,99));
	m_vNodes.push_back(CNode(11,6,91,94,97));

	// [[96 - 100]]
	m_vNodes.push_back(CNode(11,5,90,91,95));
	m_vNodes.push_back(CNode(12,6,96,104));
	m_vNodes.push_back(CNode(12,7,94,97,100));
	m_vNodes.push_back(CNode(12,8,98));
	m_vNodes.push_back(CNode(13,7,97,99,102));
	
	// [[101 - 105]]
	m_vNodes.push_back(CNode(13,6,97,100));
	m_vNodes.push_back(CNode(14,6,101,103));
	m_vNodes.push_back(CNode(14,5,104,108));
	m_vNodes.push_back(CNode(13,5,101,102,106));
	m_vNodes.push_back(CNode(12,5,97,104));

	// [[106 - 110]]
	m_vNodes.push_back(CNode(12,4,105,111));
	m_vNodes.push_back(CNode(13,4,104,106));
	m_vNodes.push_back(CNode(14,4,104,107,109));
	m_vNodes.push_back(CNode(14,3,114));
	m_vNodes.push_back(CNode(13,3,106,107,108,109,111));

	// [[111 - 115]]
	m_vNodes.push_back(CNode(12,3,112));
	m_vNodes.push_back(CNode(12,2,110,116,117));
	m_vNodes.push_back(CNode(13,2,110,112,114));
	m_vNodes.push_back(CNode(14,2,110));
	m_vNodes.push_back(CNode(14,1,114,120));
	
	// [[116 - 120]]
	m_vNodes.push_back(CNode(13,1,113,114,115));
	m_vNodes.push_back(CNode(12,1,116,118));
	m_vNodes.push_back(CNode(12,0,116,119));
	m_vNodes.push_back(CNode(13,0,116,120));
	m_vNodes.push_back(CNode(14,0,116));

	// "A"
	// [[121 - 125]]
	m_vNodes.push_back(CNode(LINK,LINK,122));
	m_vNodes.push_back(CNode(16,1,123,127));
	m_vNodes.push_back(CNode(17,0,125,126));
	m_vNodes.push_back(CNode(19,4,153,154));
	m_vNodes.push_back(CNode(18,1));

	// [[126 - 130]]
	m_vNodes.push_back(CNode(17,1,122,125));
	m_vNodes.push_back(CNode(16,2,132));
	m_vNodes.push_back(CNode(17,2,122,125,126,127,130,131,132));
	m_vNodes.push_back(CNode(18,2,125,128));
	m_vNodes.push_back(CNode(18,3,124,129,135));

	// [[131 - 135]]
	m_vNodes.push_back(CNode(17,3,130,132,134));
	m_vNodes.push_back(CNode(16,3,133));
	m_vNodes.push_back(CNode(16,4,134,138));
	m_vNodes.push_back(CNode(17,4,130,132,135,136,137,138));
	m_vNodes.push_back(CNode(18,4,124));

	// [[136 - 140]]
	m_vNodes.push_back(CNode(18,5,135,139));
	m_vNodes.push_back(CNode(17,5,136));
	m_vNodes.push_back(CNode(16,5,137));
	m_vNodes.push_back(CNode(17,6,137,138,141));
	m_vNodes.push_back(CNode(18,6,136,139,141));

	// [[141 - 145]]
	m_vNodes.push_back(CNode(18,7,142));
	m_vNodes.push_back(CNode(19,8,143,145));
	m_vNodes.push_back(CNode(19,7,141,145));
	m_vNodes.push_back(CNode(19,6,136,140,141,143));
	m_vNodes.push_back(CNode(20,7,144,147));

	// [[146 - 150]]
	m_vNodes.push_back(CNode(20,6,144,145,148));
	m_vNodes.push_back(CNode(21,6,146,149));
	m_vNodes.push_back(CNode(20,5,144,147));
	m_vNodes.push_back(CNode(21,5,148,152));
	m_vNodes.push_back(CNode(22,5,147,149,152));

	// [[151 - 155]]
	m_vNodes.push_back(CNode(22,4,150,156));
	m_vNodes.push_back(CNode(21,4,148,151,154,156));
	m_vNodes.push_back(CNode(20,4,148,152,154));
	m_vNodes.push_back(CNode(20,3,158,159));
	m_vNodes.push_back(CNode(21,3,152,154,156));

	// [[156 - 160]]
	m_vNodes.push_back(CNode(22,3,157));
	m_vNodes.push_back(CNode(22,2,162));
	m_vNodes.push_back(CNode(21,2,155,156,157,159,161));
	m_vNodes.push_back(CNode(20,2,160));
	m_vNodes.push_back(CNode(20,1,158,163));

	// [[161 - 165]]
	m_vNodes.push_back(CNode(21,1,160));
	m_vNodes.push_back(CNode(22,1,158,161,163));
	m_vNodes.push_back(CNode(21,0,161));

	
	// Now that node information is filled, translate the target node values
	// into x,y coordinates.
	
	// Loop through nodes.  (Here is where an iterator comes in handy.)
	for (	itrNodeType itrNode = m_vNodes.begin();
			itrNode < m_vNodes.end();
			itrNode++)
	{

		// Loop through connections for the current node.
		for ( itrConnectType itrConnect = 
					itrNode->m_vConnect.begin();
				itrConnect < itrNode->m_vConnect.end();
				itrConnect++)
		{
			// Set the connection coordinates.
			itrConnect->x = m_vNodes[itrConnect->m_nNode - 1].x;
			itrConnect->y = m_vNodes[itrConnect->m_nNode - 1].y;		
		}
	
	}

	
	// Create a new quadric and set our pointer to it
	m_pQuadSphere = gluNewQuadric();
	if (m_pQuadSphere == 0)
		throw "CComaLogo.init()\r\nNot enough memory to allocate m_pQuadSphere";

	// Set options to how quadric behaves in OpenGL environment
	gluQuadricDrawStyle(	m_pQuadSphere,		GLU_FILL);
	gluQuadricNormals(	m_pQuadSphere,		GLU_SMOOTH);
	gluQuadricOrientation(m_pQuadSphere,	GLU_OUTSIDE);
	gluQuadricTexture(	m_pQuadSphere,		GL_FALSE);
	
	// Load textures	
	
	md::Cimage oImage;	// Create a "media duke" image object
	
	// Load title image as an OpenGL texture.
	if (!m_pEnvInfo->oMedia.read("nodelogo.png", oImage))
		throw "CComaLogo.init()\r\nCould not load nodelogo.png";
	m_punTitle = new unsigned int;
	*m_punTitle = oImage.makeGLTexture(m_pEnvInfo->glWantMipmap,m_pEnvInfo->glWantLinear);
   if (*m_punTitle==-1)
      throw "CComaLogo.init()\r\nUnable to create texture for nodelogo.png";
	oImage.destroy();

	// Load background image as an OpenGL texture.
	if (!m_pEnvInfo->oMedia.read("coma2bg.png", oImage))
		throw "CComaLogo.init()\r\nCould not load coma2bg.png";
	m_punBGTexture = new unsigned int;
	*m_punBGTexture = oImage.makeGLTexture(m_pEnvInfo->glWantMipmap,m_pEnvInfo->glWantLinear);
   if (*m_punBGTexture==-1)
      throw "CComaLogo.init()\r\nUnable to create texture for coma2bg.png";
	oImage.destroy();

	// Load shadow image as an OpenGL texture.
	if (!m_pEnvInfo->oMedia.read("nodeshadow.png", oImage))
		throw "CComaLogo.init()\r\nCould not load nodeshadow.png";
	m_punBGShadow = new unsigned int;
	*m_punBGShadow = oImage.makeGLTexture(m_pEnvInfo->glWantMipmap,m_pEnvInfo->glWantLinear);
   if (*m_punBGShadow==-1)
      throw "CComaLogo.init()\r\nUnable to create texture for nodeshadow.png";
	oImage.destroy();

	return true;
}
Esempio n. 19
0
void compoe_cadeiras(void){
  GLUquadricObj *quadric;
  // inicia a composicao do computador
  cadeiras = glGenLists(1);
  glNewList(cadeiras, GL_COMPILE);
  quadric = gluNewQuadric();
  //gluQuadricTexture(quadric, GL_TRUE);

  GLfloat lado, atras = 0;
  //compoe cadeiras, 4 colunas
  for(int i = 0; i<4; i++){
    atras = i * 9.5;
    //6 cadeiras lado a lado - 3 da cada lado
    for(int j=0; j<6; j++){
      lado = j*6.0;
      if (j>2){
        lado = lado + 8;
      }

      glColor3f(0,0,0);

      //pe cadeira - atrás esquerda
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      gluQuadricTexture(quadric, GL_TRUE);
      glPushMatrix();
      glRotatef(90,1,0,0);
      //-tras/frente+ - +esquerda/direita- - +baixo/cima-
      glTranslatef (8-lado, -0.8-atras, 6.8);
      SOLID_CLOSED_CYLINDER(quadric, 0.1, 0.1, 3.3, 30, 5)
      gluDeleteQuadric(quadric);
      glPopMatrix();


      //pe cadeira - atrás direita
      quadric = gluNewQuadric();
      gluQuadricOrientation(quadric, GLU_INSIDE);
      gluQuadricTexture(quadric, GL_TRUE);
      glPushMatrix();
      glRotatef(90,1,0,0);
      //-tras/frente+ - +esquerda/direita- - +baixo/cima-
      glTranslatef (6-lado, -0.8-atras, 6.8);
      SOLID_CLOSED_CYLINDER(quadric, 0.1, 0.1, 3.3, 30, 5)
      gluDeleteQuadric(quadric);
      glPopMatrix();


      //pe cadeira - frente esquerda
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      gluQuadricTexture(quadric, GL_TRUE);
      glPushMatrix();
      glRotatef(90,1,0,0);
      //-tras/frente+ - +esquerda/direita- - +baixo/cima-
      glTranslatef (8-lado, 1.2-atras, 6.8);
      SOLID_CLOSED_CYLINDER(quadric, 0.1, 0.1, 3.3, 30, 5)
      gluDeleteQuadric(quadric);
      glPopMatrix();


      //pe cadeira - frente direita
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      gluQuadricTexture(quadric, GL_TRUE);
      glPushMatrix();
      glRotatef(90,1,0,0);
      //-tras/frente+ - +esquerda/direita- - +baixo/cima-
      glTranslatef (6-lado, 1.2-atras, 6.8);
      SOLID_CLOSED_CYLINDER(quadric, 0.1, 0.1, 3.3, 30, 5)
      gluDeleteQuadric(quadric);
      glPopMatrix();

      

      //assento cadeira
      glPushMatrix();  
      //+tras/frente- - +baixo/cima- - - +esquerda/direita-
      glTranslatef (7-lado, -6.8, 0.3-atras);
      glScalef(4.0,0.3,3.0);
      quadric=gluNewQuadric();

      glColor3f(0,0,1);
      gluSphere(quadric,0.5,15,12);

      glPopMatrix();

      //encosto cadeira
      glPushMatrix();  
      //+tras/frente- - +baixo/cima- - - +esquerda/direita-
      glTranslatef (7-lado, -4.75, -1.5-atras);
      glRotatef(-15,1,0,1);
      glScalef(4,3,0.5);
      quadric=gluNewQuadric();
      
      gluSphere(quadric,0.5,15,12);
      glPopMatrix();
      
      glBindTexture(GL_TEXTURE_2D, 0);

      //apoio encosto cadeira - vertical
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      glPushMatrix();   
      glColor3f(0,0,0);
      glRotatef(90,1,0,0);  
      glTranslatef (7-lado, -1.8-atras, 5);
      //tras/frente - direita/esquerda - cima/baixo 
      SOLID_CLOSED_CYLINDER(quadric, 0.15, 0.15, 2.2, 30, 1)
      //gluDeleteQuadric(quadric);
      glPopMatrix();

  //apoio encosto cadeira - horizontal
      quadric = gluNewQuadric();
      gluQuadricDrawStyle(quadric, GLU_FILL);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      glPushMatrix();   
      glColor3f(0,0,0);
      glTranslatef (7-lado, -7, -2-atras);
      //tras/frente - cima/baixo - direita/esquerda 
      SOLID_CLOSED_CYLINDER(quadric, 0.15, 0.15, 2.2, 30, 1)
      gluDeleteQuadric(quadric);
      glPopMatrix();
    }
  }
}
Esempio n. 20
0
	void GrassLamp::makeHead(){
		GLUquadricObj * _cylinderObj = gluNewQuadric();
		gluQuadricNormals(_cylinderObj, GLU_FLAT);
		gluQuadricOrientation(_cylinderObj, GLU_INSIDE);

		glPushMatrix();
			glTranslatef(0.0f,0.55f,0.0f);
			glScalef(0.1f,0.125f,0.1f);
			
			
			makeBulb(); //bulb

			glBegin(GL_POLYGON); //top
				glVertex3d(0,1,0);
				glVertex3d(1,1,0);
				glVertex3d(1,1,1);
				glVertex3d(0,1,1);
				
			glEnd();

			glBegin(GL_POLYGON); // bot
				glVertex3d(0,0,0);
				glVertex3d(1,0,0);
				glVertex3d(1,0,1);
				glVertex3d(0,0,1);
				
			glEnd();

			glPushMatrix(); // cylinders

				glPushMatrix();
				glTranslatef(0.1f,0.0f,0.1f);
				glScaled(0.1,1.0,0.1);
				glRotatef(270,1.0f,0.0f,0.0f);
				gluCylinder	(_cylinderObj, 1, 1, 1, 25, 10);
				glPopMatrix();

				glPushMatrix();
					glTranslatef(0.9f,0.0f,0.1f);
					glScaled(0.1,1.0,0.1);
					glRotatef(270,1.0f,0.0f,0.0f);
					gluCylinder	(_cylinderObj, 1, 1, 1, 25, 10);
				glPopMatrix();
				
				glPushMatrix();
					glTranslatef(0.9f,0.0f,0.9f);
					glScaled(0.1,1.0,0.1);
					glRotatef(270,1.0f,0.0f,0.0f);
					gluCylinder	(_cylinderObj, 1, 1, 1, 25, 10);
				glPopMatrix();

				glPushMatrix();
					glTranslatef(0.1f,0.0f,0.9f);
					glScaled(0.1,1.0,0.1);
					glRotatef(270,1.0f,0.0f,0.0f);
					gluCylinder	(_cylinderObj, 1, 1, 1, 25, 10);
				glPopMatrix();
			glPopMatrix();
		glPopMatrix();

	}
Esempio n. 21
0
static void Init( int argc, char *argv[] )
{
   GLboolean convolve = GL_FALSE;
   GLboolean fullscreen = GL_FALSE;
   int i;

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-info")==0) {
         printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
         printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
         printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
         printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
      }
      else if (strcmp(argv[i], "-c")==0) {
         convolve = GL_TRUE;
      }
      else if (strcmp(argv[i], "-f")==0) {
         fullscreen = GL_TRUE;
      }
   }

   if (fullscreen)
      glutFullScreen();

   /* Cylinder object */
   {
      static GLfloat height = 100.0;
      static GLfloat radius = 40.0;
      static GLint slices = 24;  /* pie slices around Z axis */
      static GLint stacks = 10;  /* subdivisions along length of cylinder */
      static GLint rings = 4;    /* rings in the end disks */
      GLUquadricObj *q = gluNewQuadric();
      assert(q);
      gluQuadricTexture(q, GL_TRUE);

      CylinderObj = glGenLists(1);
      glNewList(CylinderObj, GL_COMPILE);

      glPushMatrix();
      glTranslatef(0.0, 0.0, -0.5 * height);

      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      /*glScalef(8.0, 4.0, 2.0);*/
      glMatrixMode(GL_MODELVIEW);

      /* cylinder */
      gluQuadricNormals(q, GL_SMOOTH);
      gluQuadricTexture(q, GL_TRUE);
      gluCylinder(q, radius, radius, height, slices, stacks);

      /* end cap */
      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glScalef(3.0, 3.0, 1.0);
      glMatrixMode(GL_MODELVIEW);

      glTranslatef(0.0, 0.0, height);
      gluDisk(q, 0.0, radius, slices, rings);

      /* other end cap */
      glTranslatef(0.0, 0.0, -height);
      gluQuadricOrientation(q, GLU_INSIDE);
      gluDisk(q, 0.0, radius, slices, rings);

      glPopMatrix();

      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glMatrixMode(GL_MODELVIEW);

      glEndList();
      gluDeleteQuadric(q);
   }

   /* Teapot */
   {
      TeapotObj = glGenLists(1);
      glNewList(TeapotObj, GL_COMPILE);

      glFrontFace(GL_CW);
      glutSolidTeapot(40.0);
      glFrontFace(GL_CCW);

      glEndList();
   }

   /* show cylinder by default */
   Object = CylinderObj;


   /* lighting */
   glEnable(GL_LIGHTING);
   {
      GLfloat pos[4] = { 3, 3, 3, 1 };
      glLightfv(GL_LIGHT0, GL_AMBIENT, Black);
      glLightfv(GL_LIGHT0, GL_DIFFUSE, White);
      glLightfv(GL_LIGHT0, GL_SPECULAR, White);
      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glEnable(GL_LIGHT0);
      glMaterialfv(GL_FRONT, GL_AMBIENT, Black);
      glMaterialf(GL_FRONT, GL_SHININESS, Shininess);
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
   }

   /* Base texture */
   glGenTextures(1, &BaseTexture);
   glBindTexture(GL_TEXTURE_2D, BaseTexture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   if (!LoadRGBMipmaps(BASE_TEXTURE_FILE, GL_RGB)) {
      printf("Error: couldn't load texture image file %s\n", BASE_TEXTURE_FILE);
      exit(1);
   }

   /* Specular texture */
   glGenTextures(1, &SpecularTexture);
   glBindTexture(GL_TEXTURE_2D, SpecularTexture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   if (convolve) {
      /* use convolution to blur the texture to simulate a dull finish
       * on the object.
       */
      GLubyte *img;
      GLenum format;
      GLint w, h;
      GLfloat filter[FILTER_SIZE][FILTER_SIZE][4];

      for (h = 0; h < FILTER_SIZE; h++) {
         for (w = 0; w < FILTER_SIZE; w++) {
            const GLfloat k = 1.0 / (FILTER_SIZE * FILTER_SIZE);
            filter[h][w][0] = k;
            filter[h][w][1] = k;
            filter[h][w][2] = k;
            filter[h][w][3] = k;
         }
      }

      glEnable(GL_CONVOLUTION_2D);
      glConvolutionParameteri(GL_CONVOLUTION_2D,
                              GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
      glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGBA,
                            FILTER_SIZE, FILTER_SIZE,
                            GL_RGBA, GL_FLOAT, filter);

      img = LoadRGBImage(SPECULAR_TEXTURE_FILE, &w, &h, &format);
      if (!img) {
         printf("Error: couldn't load texture image file %s\n",
                SPECULAR_TEXTURE_FILE);
         exit(1);
      }

      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0,
                   format, GL_UNSIGNED_BYTE, img);
      free(img);
   }
   else {
      /* regular path */
      if (!LoadRGBMipmaps(SPECULAR_TEXTURE_FILE, GL_RGB)) {
         printf("Error: couldn't load texture image file %s\n",
                SPECULAR_TEXTURE_FILE);
         exit(1);
      }
   }

   /* misc */
   glEnable(GL_CULL_FACE);
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_NORMALIZE);

   glPolygonOffset( -1, -1 );
}
Esempio n. 22
0
void SkyDome::draw(int time){
  
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, m_gradient);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

  float U = (float)time/(CYCLE);

  for(int i=0; i<m_nLat; i++){
    for(int j=0; j<m_nLong; j++){
      int a = i*(m_nLong+1) + j;
      int b = a + (m_nLong+1);


      float VTop = (float)(i+1)*2/(m_nLat+3);
      float VBot = (float)(i+2)*2/(m_nLat+3);

      glBegin(GL_TRIANGLES);
      glTexCoord2f(U,VTop);
      glVertex3d(m_vertices[a][0], m_vertices[a][1], m_vertices[a][2]);
      glTexCoord2f(U,VBot);
      glVertex3d(m_vertices[b][0], m_vertices[b][1], m_vertices[b][2]);
      glTexCoord2f(U,VTop);
      glVertex3d(m_vertices[a+1][0], m_vertices[a+1][1], m_vertices[a+1][2]);
      glEnd();

      glBegin(GL_TRIANGLES);
      glTexCoord2f(U,VBot);
      glVertex3d(m_vertices[b][0], m_vertices[b][1], m_vertices[b][2]);
      glVertex3d(m_vertices[b+1][0], m_vertices[b+1][1], m_vertices[b+1][2]);
      glTexCoord2f(U,VTop);
      glVertex3d(m_vertices[a+1][0], m_vertices[a+1][1], m_vertices[a+1][2]);
      glEnd();
    }
  }

  glDisable(GL_TEXTURE_2D);

  // calc sun position
  Point3D* sunPos = getSunPos(time);
  Point3D* moonPos = getMoonPos(time);

  //TODO calc sun color and size
  double sina = sin(getT(time, 0.1, 0.55)*M_PI);
  int sunSize = 2500 - sina*1200;
  Colour sunColor = Colour(1,0.85,0.7)*(1-sina) + Colour(1,1,1)*sina;


  // draw sun
  GLUquadricObj* qsphere = gluNewQuadric();

  gluQuadricDrawStyle(qsphere, GLU_FILL);
  gluQuadricOrientation(qsphere, GLU_OUTSIDE);
  gluQuadricTexture(qsphere, GL_FALSE);

  glColor3f(sunColor.R(),sunColor.G(),sunColor.B());
  glPushMatrix();
  glTranslatef((*sunPos)[0],(*sunPos)[1],(*sunPos)[2]);
  gluSphere(qsphere, sunSize, 20, 20);
  glPopMatrix();

  // draw moon
  GLUquadricObj* qsphere2 = gluNewQuadric();

  gluQuadricDrawStyle(qsphere2, GLU_FILL);
  gluQuadricOrientation(qsphere2, GLU_OUTSIDE);
  gluQuadricTexture(qsphere2, GL_FALSE);

  glColor3f(1,0.9,0.6);
  glPushMatrix();
  glTranslatef((*moonPos)[0],(*moonPos)[1],(*moonPos)[2]);
  gluSphere(qsphere2, 1000, 20, 20);
  glPopMatrix();

}
Esempio n. 23
0
///////////////////////////////////////////////////////////////////
// Draw the unit axis. A small white sphere represents the origin
// and the three axes are colored Red, Green, and Blue, which 
// corresponds to positive X, Y, and Z respectively. Each axis has
// an arrow on the end, and normals are provided should the axes
// be lit. These are all built using the quadric shapes. For best
// results, put this in a display list.
void gltDrawUnitAxes(void)
	{
	GLUquadricObj *pObj;	// Temporary, used for quadrics
	
	// Measurements
	float fAxisRadius = 0.025f;
	float fAxisHeight = 1.0f;
	float fArrowRadius = 0.06f;
	float fArrowHeight = 0.1f;
	
	// Setup the quadric object
	pObj = gluNewQuadric();
	gluQuadricDrawStyle(pObj, GLU_FILL);
	gluQuadricNormals(pObj, GLU_SMOOTH);
	gluQuadricOrientation(pObj, GLU_OUTSIDE);
	gluQuadricTexture(pObj, GLU_FALSE);
	
	///////////////////////////////////////////////////////
	// Draw the blue Z axis first, with arrowed head
	glColor3f(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
	glPopMatrix();
	
	///////////////////////////////////////////////////////
	// Draw the Red X axis 2nd, with arrowed head
    glColor3f(1.0f, 0.0f, 0.0f);
	glPushMatrix();
	glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
	gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
	glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
	gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
	glPopMatrix();
	glPopMatrix();
	
	///////////////////////////////////////////////////////
	// Draw the Green Y axis 3rd, with arrowed head
	glColor3f(0.0f, 1.0f, 0.0f);
	glPushMatrix();
	glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
	gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
	glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
	gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
	glPopMatrix();
	glPopMatrix();
	
	////////////////////////////////////////////////////////
	// White Sphere at origin
	glColor3f(1.0f, 1.0f, 1.0f);
	gluSphere(pObj, 0.05f, 15, 15);
	
	// Delete the quadric
	gluDeleteQuadric(pObj);
	}
Esempio n. 24
0
// RENDERING DEL SISTEMA SOLARE
void solarScene(void){

	

	// ogni volta che disegno incremento il numero dei frame
	g_frames++;
    
	// Do all your OpenGL rendering here
	
 	
	// cancelliamo il  buffer video e lo z buffer
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* ------------------------------------------------------------------------- */
  	// attiva il viewport principale
  	glViewport( 0, 0, width, height); 
        
    	glMatrixMode(GL_MODELVIEW); 
    	glLoadIdentity();

    	glPushMatrix();

        g_camera.look();    // chiama la gluLookAt con i parametri opportuni
    
        // posizionando la luce dopo la telecamera la luce risulta fissa nel mondo 
        glLightfv(GL_LIGHT0, GL_POSITION, g_light0_pos);
        glLightfv(GL_LIGHT1, GL_POSITION, g_light1_pos);
        glLightfv(GL_LIGHT2, GL_POSITION, g_light2_pos);
	
	glDisable(GL_CULL_FACE);
	
	// texture dello sfondo
	{
		GLUquadric* a = gluNewQuadric();
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glEnable(GL_TEXTURE_2D);
		Point3 poscam = g_camera.getPos();
		glPushMatrix();
			glTranslatef(poscam.x, poscam.y, poscam.z);
			gluQuadricOrientation(a, GLU_INSIDE);
			glBindTexture(GL_TEXTURE_2D, g_textureSfondo[0]);
			gluQuadricTexture(a, GL_TRUE);						
			gluSphere(a, 900, 24, 24);
		glPopMatrix();
		glDisable(GL_TEXTURE_2D);
		glPopAttrib();
	}
	glEnable(GL_CULL_FACE);
	
	/* PIANETI */
	drawPlanet(posPlanet[0], radius[0], g_texturePlanet[0]);	//	mercury
	drawPlanet(posPlanet[1], radius[1], g_texturePlanet[1]);	//	venus
	drawPlanet(posPlanet[2], radius[2], g_texturePlanet[2]);	//	earth
	drawPlanet(posPlanet[3], radius[3], g_texturePlanet[3]);	//	mars
	drawPlanet(posPlanet[4], radius[4], g_texturePlanet[4]);	//	jupiter
	drawPlanet(posPlanet[5], radius[5], g_texturePlanet[5]);	//	saturn
	drawPlanet(posPlanet[6], radius[6], g_texturePlanet[6]);	//	uranus
	drawPlanet(posPlanet[7], radius[7], g_texturePlanet[7]);	//	neptune
	drawPlanet(posPlanet[8], radius[8], g_texturePlanet[8]);	//	pluto


	/* SATELLITI */
	drawSatellite(&satellite[0], 'y', 0.00012, g_textureSatellite[0]);	// moon
	//drawShield(satellite[0].pos, satellite[0].rad+1);
	drawSatellite(&satellite[1], 'z', 0.00024, g_textureSatellite[1]);	// io
	drawSatellite(&satellite[2], 'y', 0.00012, g_textureSatellite[2]);	// europa
	
	/* ANELLI DI SATURNO */
	drawRing(posPlanet[5], 85, 120);				//	anello saturno

	// HENRY 
	//	gestione dei nemici: posizione, movimenti, inseguimenti
	//	FILE:		enemy_police.c
	insertEnemy();
	insertPolice();
	
	//ALBERTO
	// 	disegno di tutte le collisioni se attivate
	//	FILE		explosion.c
	insertExplosion();
		
	//ALBERTO LASER
	//	disegno di tutti i laser e controllo collisioni
	//	FILE		shooting.c
	hitEnemy=laserHitEnemy();
	hitPolice=laserHitPolice();
	insertRemoveLaser();
	// se siamo stati colpiti dal laser nemico si decrementa la vita
	shooted();
	// inseriamo il super-sparo
	insertSuperShoot();
		
    glPopMatrix();
}
JNIEXPORT void JNICALL Java_OpenGL_GLUQuadric_quadricOrientation
(JNIEnv *env, jobject obj, jlong quadric, jint orientation)
{
    gluQuadricOrientation(TO_POINTER(quadric), orientation);
}
Esempio n. 26
0
//mykey
void Lizandrokey(Game *game, int w, int h)
{
    int l = h / 1*5;

    glPushMatrix();
    glTranslatef(w/2,h/2,0);
    glColor4f(0,0,0,0.9);
    glBegin(GL_LINE);
    GLUquadric* qobj = gluNewQuadric();
    gluQuadricOrientation(qobj,GLU_INSIDE);
    gluDisk(qobj, (float)l/5.0*.5, l/5, 62, 1);
    glEnd(); 
    glPopMatrix();
    
    glLineWidth(1);
    glBegin(GL_LINES);
    glColor3f(0.0f,0.0f,0.0f);
    glVertex2d(w / 2 - l / 20, h / 2);
    glVertex2d(w / 2 + l / 20, h / 2);
    glEnd();
    glBegin(GL_LINES);
    glVertex2d(w / 2, h / 2 - l / 20);
    glVertex2d(w / 2, h / 2 + l / 20);
    glEnd();
    glBegin(GL_LINES);
    glColor3f(0.0f,0.0f,0.0f);
    glVertex2d(w / 2 - l / 20, h / 2+1);
    glVertex2d(w / 2 + l / 20, h / 2+1);
    glEnd();
    glBegin(GL_LINES);
    glVertex2d(w / 2+1, h / 2 - l / 20);
    glVertex2d(w / 2+1, h / 2 + l / 20);
    glEnd();
    
    int hitAnim = game->hitAnim;
    if (hitAnim > 0) {
    glLineWidth(1);
    glBegin(GL_LINES);
    glColor3f(1.0f,0.0f,0.0f);
    glVertex2d(w / 2 - l / 20, h / 2);
    glVertex2d(w / 2 + l / 20, h / 2);
    glEnd();
    glBegin(GL_LINES);
    glVertex2d(w / 2, h / 2 - l / 20);
    glVertex2d(w / 2, h / 2 + l / 20);
    glEnd();
    glBegin(GL_LINES);
    glColor3f(0.0f,0.0f,0.0f);
    glVertex2d(w / 2 - l / 20, h / 2+1);
    glVertex2d(w / 2 + l / 20, h / 2+1);
    glEnd();
    glBegin(GL_LINES);
    glVertex2d(w / 2+1, h / 2 - l / 20);
    glVertex2d(w / 2+1, h / 2 + l / 20);
    glEnd();
    
    }
    
    glBegin(GL_LINES);
    Rect r;
    r.bot = h-100;
    r.left = w/2;
    r.center = 0;
    glColor3f(1.0f,0.0f,0.0f);
    ggprint13(&r, 16, 0, "");
    ggprint13(&r, 16, 0, "Mob: %i", game->mobNum);
    ggprint13(&r, 16, 0, "Distance: %f", game->mobDist);
    glEnd();
     

}
Esempio n. 27
0
void display(void)
{
  GLUquadricObj* cyl = gluNewQuadric();
  GLfloat texcol[4] = {0.0, 0.0, 0.0, 0.0};
#ifndef MULTITEXTURE
  int repeat;
#endif

  gluQuadricNormals(cyl, GLU_SMOOTH);
  
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

#ifdef MULTITEXTURE
  /* setup front texture */
  glActiveTexture(GL_TEXTURE0);
  setup_texture_matrix(0);
  glBindTexture(GL_TEXTURE_2D, front_txr);

  /* setup back texture */
  glActiveTexture(GL_TEXTURE1);
  setup_texture_matrix(1);
  glBindTexture(GL_TEXTURE_2D, back_txr);
#endif

  glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, texcol);
  
#ifndef MULTITEXTURE
  glEnable(GL_ALPHA_TEST);
  glAlphaFunc(GL_GREATER, 0.5f);
  
  for (repeat=0; repeat<2; repeat++)
  {
    setup_texture_matrix(repeat);
    glBindTexture(GL_TEXTURE_2D, repeat==0 ? front_txr : back_txr);
#endif

    glMatrixMode(GL_MODELVIEW);

    glPushMatrix();

    glRotatef(rot, 0, 1, 0);
    glRotatef(rot/2.0, 1, 0, 0);

  /*  glColor3f(1.0, 0.6, 0.0);*/
    glColor4f(0.0, 1.0, 0.0, 1.0);

    switch (curobj)
    {
      case 0:
      glTranslatef(0, 0, -1.5);
      gluCylinder(cyl, 0.5, 0.5, 3, 40, 4);
      gluQuadricOrientation(cyl, GLU_INSIDE);
      gluDisk(cyl, 0, 0.5, 40, 1);
      gluQuadricOrientation(cyl, GLU_OUTSIDE);
      glTranslatef(0, 0, 3);
      gluDisk(cyl, 0, 0.5, 40, 1);
      break;

      case 1:
      glScalef(-1, 1, 1);
      glutSolidTeapot(1.5);
      break;

      case 2:
      glutSolidTorus(0.7, 1.3, 20, 40);
      break;
    }

    glPopMatrix();

#ifndef MULTITEXTURE
  }
  glDisable(GL_ALPHA_TEST);
#endif
    
  gluDeleteQuadric(cyl);
  
  glutSwapBuffers();
}
Esempio n. 28
0
void display(void)
{
	// ****** declaracoes internas 'a funcao display() ******
	
	float temp;

	GLUquadric* glQ;	// nec. p/ criar sup. quadraticas (cilindros, esferas...)

	// ****** fim de todas as declaracoes da funcao display() ******

	glQ = gluNewQuadric();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	camara_control(camera_select);

	/*// permissao de atribuicao directa de cores
	// para objectos que nao tem material atribuido, como
	// e' o caso dos eixos e da esfera que simboliza a fonte de luz...
	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);

	// cilindro representativo do eixo X
	glColor3f(1.0,0.0,0.0);		// vermelho
	glPushMatrix();
	glRotated(90.0, 0.0,1.0,0.0 );
	gluCylinder(glQ, axis_radius_begin, axis_radius_end,
		             axis_lenght, axis_nslices, axis_nstacks);   // nao tem bases
	glPopMatrix();

	// cilindro representativo do eixo Y
	glColor3f(0.0,1.0,0.0);		// verde
	glPushMatrix();
	glRotated(-90.0, 1.0,0.0,0.0 );
	gluCylinder(glQ, axis_radius_begin, axis_radius_end,
		             axis_lenght, axis_nslices, axis_nstacks);   // nao tem bases
	glPopMatrix();
	
	// cilindro representativo do eixo Z
	glColor3f(0.0,0.0,1.0);		// azul
	glPushMatrix();
	// nao necessita rotacao... glRotated(...);
	gluCylinder(glQ, axis_radius_begin, axis_radius_end,
		             axis_lenght, axis_nslices, axis_nstacks);   // nao tem bases
	glPopMatrix();*/

	// Actualizacao da posicao da fonte de luz...
	light0_position[0] = light0x;	// por razoes de eficiencia, os restantes 
	light0_position[1] = light0y;	// parametros _invariaveis_ da LIGHT0 mantem os valores
	light0_position[2] = light0z;	// definidos na funcao de inicializacao
	glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light0_direction);

	// ... e da esfera que a simboliza
	glColor3f(1.0,1.0,0.0);		// cor amarela
	gluQuadricOrientation( glQ, GLU_INSIDE);
	glPushMatrix();
	glTranslated(light0x,light0y,light0z);
	gluSphere(glQ, symb_light0_radius, symb_light0_slices, symb_light0_stacks);
    glPopMatrix();
	gluQuadricOrientation( glQ, GLU_OUTSIDE);



	// SEGUEM-SE ALGUNS EXEMPLOS DE UTILIZACAO DE OPENGL (GL, GLU, GLUT)

	// GLU: funcoes para desenhar Quadraticas
	//   Permitem desenhar alguns objectos: disco, cilindro/cone, esfera
	//   O parametro do tipo GLUquadric (variavel glQ, declarada acima) passa,
	//   em argumento da funcao de desenho respectiva, algumas propriedades
	//   que esta tem em conta durante o desenho (estilo de desenho, calculo e
	//   orientacao de normais, mapeamento de texturas...

	// Funcoes para definicao dessas propriedades em glQ
	gluQuadricDrawStyle(glQ, GLU_LINE);		// GLU_FILL, GLU_LINE, GLU_SILHOUETTE, GLU_POINT
	gluQuadricNormals(glQ, GLU_SMOOTH);		// GLU_NONE, GLU_FLAT, GLU_SMOOTH
	gluQuadricOrientation(glQ, GLU_OUTSIDE);	// GLU_OUTSIDE, GLU_INSIDE
	gluQuadricTexture(glQ, GL_FALSE);		// GL_TRUE, GL_FALSE
	//gluQuadricCallback(glQ, GLU_ERROR, <CallBackFunc>);

	// inibicao de atribuicao directa de cores; os objectos que se seguem DEVEM
	// possuir materiais associados
	glDisable(GL_COLOR_MATERIAL);

	// Definicao de material a usar daqui em diante (valores declarados em materias.h)
	material1();

	//Terreno e árvores;
	glCallList(1);
	//Hospital (com telhado e letreiro incluídos);
	glCallList(2);
	//Heliporto (área de aterragem e holofotes).
	glCallList(3);

	hangar(); 
	torre();
	helicoptero();	

	// swapping the buffers causes the rendering above to be shown
	glutSwapBuffers();
	glFlush();
}
Esempio n. 29
0
bool CCubeZoom::init()
{ 
	// Setup colors to show for each depth of recursion
	ADD_COLOR(0,	1.0f,	0.6f, 0.6f);
	ADD_COLOR(1,	1.0f,	1.0f, 0.5f);
	ADD_COLOR(2,	0.6f,	1.0f, 0.6f);
	ADD_COLOR(3,	0.3f,	0.4f, 1.0f);
	ADD_COLOR(4,	0.0f,	0.0f, 1.0f);	// ???TBH not used
	ADD_COLOR(5,	0.0f,	0.0f, 1.0f);	// ???TBH not used
	
	// Setup initial lights and positions
	m_ambientLight[0] = 0.2f;
	m_ambientLight[1] = 0.2f;
	m_ambientLight[2] = 0.2f;
	m_ambientLight[3] = 1.0f;

	m_diffuseLight[0] = 0.7f;
	m_diffuseLight[1] = 0.7f;
	m_diffuseLight[2] = 0.7f;
	m_diffuseLight[3] = 1.0f;
	
	m_lightPos[0] = 20.0f;
	m_lightPos[1] = 40.0f;
	m_lightPos[2] = 2.0f;
	m_lightPos[3] = 1.0f;
	

	// Create displays lists for recursion
	m_vCubes.resize(nMAX_CUBE_DEPTH);
	m_glDispStartIndex = glGenLists(nMAX_CUBE_DEPTH);

	// Generate display list
	m_glDispObject = glGenLists(1);

	// Create a new quadric and set our pointer to it
	m_pQuadObject = gluNewQuadric();
	if (m_pQuadObject == 0)
		throw "CCubeZoom.init()\r\nNot enough memory to allocate m_pQuadObject";

	// Set options to how foreground quadric behaves in OpenGL environment
	gluQuadricDrawStyle(		m_pQuadObject, GLU_FILL);
	gluQuadricNormals(		m_pQuadObject, GLU_SMOOTH);
	gluQuadricOrientation(	m_pQuadObject, GLU_OUTSIDE);
	gluQuadricTexture(		m_pQuadObject, GL_TRUE);

	// Load textures	
	md::Cimage oImage;
	if (!m_pEnvInfo->oMedia.read("spheretex.png", oImage))
		throw "CCubeZoom.init()\r\nCould not load spheretex.png";

	m_punNodeTexture = new unsigned int;

	*m_punNodeTexture = oImage.makeGLTexture(m_pEnvInfo->glWantMipmap,m_pEnvInfo->glWantLinear);

	oImage.destroy();

	// To increase performace, I have the quadric rendered in a display list.
	// I have yet to find the time to see if this provides a significant
	// (if any) speed increase.
	glNewList(m_glDispObject, GL_COMPILE);
		glBindTexture(GL_TEXTURE_2D, *m_punNodeTexture);
		gluSphere(
			m_pQuadObject,			// Quadric identifier
			1.0,						// radius
			m_nSphereQuality,		// horizontal components
			m_nSphereQuality);	// verticle componetns
	glEndList();

	glEnable(GL_NORMALIZE);

	return true;
}
Esempio n. 30
0
int DrawGLScene(GLvoid)	            // Here's Where We Do All The Drawing
{								
	int i;
	static char frbuf[80] = "";
	
	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    
    //set camera in hookmode 
	if (hook_toball1)
	{
		TVector unit_followvector=sphere_speed[0];
		unit_followvector.unit();
 		gluLookAt(sphere_speed[0].X()+250,sphere_speed[0].Y()+250 ,sphere_speed[0].Z(), sphere_speed[0].X()+sphere_speed[0].X() ,sphere_speed[0].Y()+sphere_speed[0].Y() ,sphere_speed[0].Z()+sphere_speed[0].Z() ,0,1,0);  
    
    }
	else
	    gluLookAt(pos._x,pos._y,pos._z, pos._x + dir.X(),pos._y+dir.Y(),pos._z+dir.Z(), 0,1.0,0.0);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glRotatef(camera_rotation,0,1,0);
	
	for (i=0;i<NR_BALLS;i++)
	{
		switch(i % 7){
        case 1: glColor3f(1.0f,1.0f,1.0f);
			       break;
		case 2: glColor3f(1.0f,1.0f,0.0f);
			       break;
		case 3: glColor3f(0.0f,1.0f,1.0f);
			       break;
		case 4: glColor3f(0.0f,1.0f,0.0f);
			       break;
		case 5: glColor3f(0.0f,0.0f,1.0f);
			       break;
		case 6: glColor3f(0.65f,0.2f,0.3f);
			       break;
		case 7: glColor3f(1.0f,0.0f,1.0f);
			       break;
		case 8: glColor3f(0.0f,0.7f,0.4f);
			       break;
		default: glColor3f(1.0f,0,0);
		}
		glPushMatrix();
		glTranslated(sphere_poz[i]._x,sphere_poz[i]._y,sphere_poz[i]._z);
		GLUquadricObj *obj = gluNewQuadric();
		gluQuadricDrawStyle(obj,GLU_FILL);
		gluQuadricNormals(obj,GLU_SMOOTH);
		gluQuadricOrientation(obj,GLU_OUTSIDE);
		gluSphere(obj, 5.0f, 20, 20);
		glPopMatrix();
		gluDeleteQuadric(obj);
	}

	
	for (i=0;i<NR_CIL;i++)
	{
		switch(i % 7){
        case 1: glColor3f(1.0f,1.0f,1.0f);
			       break;
		case 2: glColor3f(1.0f,1.0f,0.0f);
			       break;
		case 3: glColor3f(0.0f,1.0f,1.0f);
			       break;
		case 4: glColor3f(0.0f,1.0f,0.0f);
			       break;
		case 5: glColor3f(0.0f,0.0f,1.0f);
			       break;
		case 6: glColor3f(0.65f,0.2f,0.3f);
			       break;
		case 7: glColor3f(1.0f,0.0f,1.0f);
			       break;
		case 8: glColor3f(0.0f,0.7f,0.4f);
			       break;
		default: glColor3f(1.0f,0,0);
		}
		glPushMatrix();
		glTranslated(cone_poz[i]._x,cone_poz[i]._y,cone_poz[i]._z);
		GLUquadricObj *obj = gluNewQuadric();
		gluQuadricDrawStyle(obj,GLU_FILL);
		gluQuadricNormals(obj,GLU_SMOOTH);
		gluQuadricOrientation(obj,GLU_OUTSIDE);
		gluCylinder(obj,5.0, 5.0, 10.0, 20.0, 20.0);
		glPopMatrix();
		gluDeleteQuadric(obj);
	}

	
	float df = 100.0;

	for (int i = 0; i < NR_CUBES; i += 1)
	{
		glPushMatrix();
		glTranslated(cube_pos[i]._x,cube_pos[i]._y,cube_pos[i]._z);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		glDrawCube();
		glPopMatrix();
	}
	
	glEnable(GL_TEXTURE_2D);

	

	//glMaterialfv(GL_FRONT,GL_SPECULAR,spec);
	//glMaterialfv(GL_FRONT,GL_SHININESS,&df);
	
	//render walls(planes) with texture
	glBindTexture(GL_TEXTURE_2D, texture[1]); 
	glColor3f(1, 1, 1);
	glBegin(GL_QUADS);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(520,520,520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(520,-520,520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-520,-520,520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-520,520,520);
        
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-520,520,-520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(-520,-520,-520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(520,-520,-520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(520,520,-520);
    
	glTexCoord2f(1.0f, 0.0f); glVertex3f(520,520,-520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(520,-520,-520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(520,-520,520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(520,520,520);
	
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-520,520,520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(-520,-520,520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-520,-520,-520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-520,520,-520);
	glEnd();

	//render floor (plane) with colours
	glBindTexture(GL_TEXTURE_2D, texture[0]); 
    glBegin(GL_QUADS);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-520,-520,520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(520,-520,520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(520,-520,-520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-520,-520,-520);
	glEnd();
	
	glDisable(GL_TEXTURE_2D);
	
	glRasterPos2i(10, 10);
	printstring(GLUT_BITMAP_HELVETICA_18, frbuf);
	glRasterPos2i(10, 10);
	
	FRAMES++;
	{
		GLint t = glutGet(GLUT_ELAPSED_TIME);
		if (t - TO >= 2000)
		{
			GLfloat seconds = (t - TO) / 1000.0;
			GLfloat fps = FRAMES / seconds;
			sprintf(frbuf, "Frame rate: %f", fps);
			TO = t;
			FRAMES = 0;
		}
	}
	return TRUE;										// Keep Going
}