コード例 #1
0
ファイル: final.c プロジェクト: sperry94/OpenGL-Cathedral
//Used to display the scene.
void display()
{
    glClearColor(skyColor[0],skyColor[1],skyColor[2],skyColor[3]);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();

    float Ambient[]   = {0.3 ,0.3 ,0.3 ,1.0};
    float Diffuse[]   = {1.0 ,1.0 ,1.0 ,1.0};

    if(mode == 0)
    {
        //Set up perspective projection
        double Ex = 5*dim*Sin(th)*Cos(ph);
        double Ey = 5*dim*Sin(ph);
        double Ez = -5*dim*Cos(th)*Cos(ph);
        gluLookAt(Ex,Ey,Ez ,0,0,0, 0,Cos(ph),0);
    }
    else
    {
        //Set up first person projection
        double Cx = -5*dim*Sin(th)*Cos(ph) + xOffset;
        double Cy = 5*dim*Sin(ph) + yOffset;
        double Cz = 5*dim*Cos(th)*Cos(ph) + zOffset;
        gluLookAt(xOffset,yOffset,zOffset ,Cx,Cy,Cz, 0,Cos(ph),0);
    }

    //Enable depth test.
    glEnable(GL_DEPTH_TEST);

    glEnable(GL_NORMALIZE);

    float hrMin = minOfHr+minHrOffset;
    float dayHr = (hourOfDay+hrDayOffset-6)%12;

    float relativeTime = (dayHr + hrMin/60)*3.1415926/11;

    float light0Position[] = {0,0,0,1.0};
    float light1Position[] = {-5*dim, dim, -5*dim, 1.0};

    if(outside)
    {
        light0Position[1]=5*dim*sin(relativeTime);
        light0Position[2]=5*dim*cos(relativeTime);
    }
    else
    {
        light0Position[0]=5*dim;
        light0Position[1]=dim;
        light0Position[2]=5*dim;
    }

    //make sphere at position of light
    if(outside)
    {
        int offsetTime = (hourOfDay+minHrOffset)%24;
        if(offsetTime >=6 && offsetTime <=17)
            glColor4f(1,1,1,1);
        else
            glColor4f(0.5,0.5,0.5,1);
        sphere(light0Position[0], light0Position[1], light0Position[2], 100,100,100);
    }

    //enable textures
    glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    //enable lighting
    glEnable(GL_LIGHTING);

    glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);

    //set light to be at position
    glLightfv(GL_LIGHT0,GL_POSITION,light0Position);

    //enable light 0
    glEnable(GL_LIGHT0);

    //set ambient and diffuse components of light 0
    glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
    glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);

    if(!outside)
    {
        glLightfv(GL_LIGHT1,GL_POSITION,light1Position);
        glEnable(GL_LIGHT1);
        glLightfv(GL_LIGHT1,GL_AMBIENT ,Ambient);
        glLightfv(GL_LIGHT1,GL_DIFFUSE ,Diffuse);
    }
    else{
        glDisable(GL_LIGHT1);
    }

    //make arches
    glCallList(cathedralList);

    glCallList(pewList);

    glCallList(towerList);

    glCallList(treeList);

    glCallList(floorList);

    glCallList(crossList);

    glColor4f(0.0,0.75,0.0,1.0);

    glBindTexture(GL_TEXTURE_2D, groundTexture);

    //grass
    glBegin(GL_QUADS);
    glNormal3d(0.0,1.0,0.0);
    glTexCoord2f(0.0,0.0);
    glVertex3f(-5*dim,-10.0,-5*dim);
    glNormal3d(0.0,1.0,0.0);
    glTexCoord2f(0.0,5*dim/4);
    glVertex3f(-5*dim,-10.0,5*dim);
    glNormal3d(0.0,1.0,0.0);
    glTexCoord2f(5*dim/4,5*dim/4);
    glVertex3f(5*dim,-10.0,5*dim);
    glNormal3d(0.0,1.0,0.0);
    glTexCoord2f(5*dim/4,0.0);
    glVertex3f(5*dim,-10.0,-5*dim);
    glEnd();

    drawStainedGlass(stainedGlassTexture, stainedGlassTexture2);

    glDisable(GL_TEXTURE_2D);

    //Print projection type in bottom left corner
    glColor3f(1,1,1);
    glWindowPos2i(5,5);
    if(mode == 0)
    {
        Print("Projection Type: Perspective");
        glWindowPos2i(5,25);
        Print("Dimension: %.0f", dim);
    }
    else
    {
        Print("Projection Type: First Person");
        glWindowPos2i(5,25);
        Print("User Location: { %.3f, %.3f, %.3f }", xOffset, yOffset, zOffset);
    }
    glWindowPos2i(5,65);
    Print("Time: %.2d:%.2d",hourOfDay,minOfHr);
    glWindowPos2i(5,45);
    Print("Offset Time: %.2d:%.2d",(int)(hourOfDay+hrDayOffset)%12,(int)hrMin);

    //check for errors
    ErrCheck("display");

    //Render scene
    glFlush();
    glutSwapBuffers();
}
コード例 #2
0
ファイル: hw2.c プロジェクト: louisfrancois/GRAPHICS
/*
 *  Display the scene
 */
void display()
{
   /*  Coordinates  */
   double x = 1;
   double y = 1;
   double z = 1;

   /*  Time step  */
   double dt = 0.001;

   //  Clear the image
   glClear(GL_COLOR_BUFFER_BIT);
   //  Reset previous transforms
   glLoadIdentity();
   //  Set view angle
   glRotated(ph,1,0,0);
   glRotated(th,0,1,0);
   //  Draw 10 pixel yellow points
   glColor3f(0.0,1.0,0.5);
   glPointSize(1);
   glScaled(0.045, 0.045, 0.045); // Scale the vertex placement
  

   int i; 
   for (i=0; i < 50000; i++)
   {
      double dx = s*(y-x);
      double dy = x*(r-z)-y;
      double dz = x*y - b*z;

      x += dt*dx;
      y += dt*dy;
      z += dt*dz;

      glBegin(GL_POINTS);
      glVertex4d(x,y,z,w);
      glEnd();
   }

   //  Draw axes in white
   glColor3f(1,1,1);
   glBegin(GL_LINES);
   glVertex3d(0,0,0);
   glVertex3d(30,0,0);
   glVertex3d(0,0,0);
   glVertex3d(0,30,0);
   glVertex3d(0,0,0);
   glVertex3d(0,0,30);
   glEnd();
   //  Label axes
   glRasterPos3d(30,0,0);
   Print("X");
   glRasterPos3d(0,30,0);
   Print("Y");
   glRasterPos3d(0,0,30);
   Print("Z");
   //  Display parameters
   glWindowPos2i(10,10);
   Print("Louis BOUDDHOU: View Angle = %d,%d  %s",th,ph, " 3D");
   //  Flush and swap
   glFlush();
   glutSwapBuffers();
}
コード例 #3
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL14_nglWindowPos2i(JNIEnv *env, jclass clazz, jint x, jint y, jlong function_pointer) {
	glWindowPos2iPROC glWindowPos2i = (glWindowPos2iPROC)((intptr_t)function_pointer);
	glWindowPos2i(x, y);
}
コード例 #4
0
/*
 *  Display the scene
 */
void display()
{
   
   //  Clear the image
   glClear(GL_COLOR_BUFFER_BIT);
   //  Reset previous transforms
   glLoadIdentity();
   //  Set view angle
   glRotated(ph,-1,0,0);
   glRotated(th,0,1,0);
   //  Color the attractor
   glColor3f(0,1,0.1);
   glPointSize(10);

   //  Draw the Lorenz Attractor
   glBegin(GL_LINE_STRIP);
   switch(initials)
   {
		case 1:
			glLorenz(28,10,2.666,w);
		break;
		
		case 2:
			glLorenz(13,10,2.666,w);
			break;
		
		case 3:
			glLorenz(14,30,4.666,w);
			break;
		
		case 4:
			glLorenz(42,15,4.666, w);
			break;
		
		case 5:
			if(usr_r != 0 && usr_s != 0 && usr_b != 0){
				glLorenz(usr_r, usr_s, usr_b, w);
			}else{
				printf("Please enter r(between 0-60 for optimal viewing): ");
				scanf("%s", usr_in);
				usr_r = atof(usr_in);
				printf("Please enter s: ");
				scanf("%s", usr_in);
				usr_s = atof(usr_in);
				printf("Please enter b(between 2-8 for optimal viewing): ");
				scanf("%s", usr_in);
				usr_b = atof(usr_in);
				glLorenz(usr_r, usr_s, usr_b, w);
			}
			break;
		
   }
   glEnd();
   //  Draw axes in white
   glColor3f(1,1,1);
   glBegin(GL_LINES);
   glVertex3d(100+x_trans,0+y_trans,0+z_trans);
   glVertex3d(-100+x_trans,0+y_trans,0+z_trans);
   glVertex3d(0+x_trans,100+y_trans,0+z_trans);
   glVertex3d(0+x_trans,-100+y_trans,0+z_trans);
   glVertex3d(0+x_trans,0+y_trans,100+z_trans);
   glVertex3d(0+x_trans,0+y_trans,-100+z_trans);
   glEnd();
   //  Label axes
   glRasterPos3d(100+x_trans,0+y_trans,0+z_trans);
   Print("X");
   glRasterPos3d(0+x_trans,100+y_trans,0+z_trans);
   Print("Y");
   glRasterPos3d(0+x_trans,0+y_trans,100+z_trans);
   Print("Z");
   //  Display parameters
   glWindowPos2i(5,5);
   Print("View Angle=%d,%d  %s",-th,-ph,text[initials]);
   Print("  w=%.1f",w);
   //  Flush and swap
   glFlush();
   glutSwapBuffers();
}
コード例 #5
0
ファイル: spacejump.c プロジェクト: rtvj/SpaceJump
/**********************************************************
 *
 * SUBROUTINE display()
 *
 * This is our main rendering subroutine, called each frame
 *
 *********************************************************/
void display(void)
{
    int i;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue


    width =  glutGet(GLUT_WINDOW_WIDTH);
    height = glutGet(GLUT_WINDOW_HEIGHT);

    glWindowPos2i(width - 100, height - 15);

    if(enter && flag3)
    {
        SwitchGameplay(2);
        glFlush(); // This force the execution of OpenGL commands
        glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer
        return;
    }

    Print("Score: %d", score);
    if(over)
    {
        SwitchGameplay(1);
        glFlush(); // This force the execution of OpenGL commands
        glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer
        return;
    }
    //  Erase the window and the depth buffer
    glClearColor(0,0.3,0.7,0);


    Background(3.5*dim); // draw space like looking texture
    gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f);
    glMatrixMode(GL_MODELVIEW); // Modeling transformation
    glLoadIdentity(); // Initialize the model matrix as identity
    //  Perspective - set eye position
    gluLookAt(Ex,Ey,Ez , Ox,Oy,Oz , Ux,Uy,Uz);



    for ( i = 0; i < NUM_STAR; i++ )
    {
        stars(star[i].x, star[i].y, star[i].z, star[i].a, star[i].b, star[i].c);
    }

    // draw laser cannon if fired
    if(bullet == 1 && space == 1)
    {
        laser_bullet(bx,by,bz,5,5,400);
    }

    // check if spaceship is hit by enemy
    if(px > ex-40 && px < ex+40 && py > ey-40 && py < ey+40 && pz > ez-40 && pz < ez+40 )
    {
        space = 0;
        CreateExplosion ();
        Mix_PlayMusic(blast,0);
        over = 1;
        enemy = 0;
    }
    // Check if spaceship hits the wall
    if(px >= wall_x-100 && px <= wall_x+100 && py >= wall_y-30 && py <= wall_y+10 && pz >= wall_z-100 && pz <= wall_z+100 )
    {
        space = 0;
        CreateExplosion ();
        Mix_PlayMusic(blast,0);
        over = 1;
    }

    // gravity, check if the spaceship fell off the road
    if( (px > 200 || px < -200) )
    {
        py -= 5;

        if( py < -40)
        {
            space = 0;
            gravity = 1;
            CreateExplosion ();
            Mix_PlayMusic(blast,0);
            over = 1;
        }
    }


    if(space)
    spaceship(px, py, pz, -90+up, side, 180,0.85,0.85,0.85);

    if(enemy == 1)
    spaceship(ex, ey, ez, -90, 0, 0,1,1,1);

    glLoadIdentity();
    glTranslatef(fx,fy,fz);

    if (fuel > 0)
    {
        glPushMatrix ();

        glBegin (GL_POINTS);

        for (i = 0; i < NUM_PARTICLES; i++)
        {
            glColor3fv (particles[i].color);
            glVertex3fv (particles[i].position);
        }

        glEnd ();

        for (i = 0; i < NUM_DEBRIS; i++)
        {
            glPushMatrix ();

            glTranslatef (debris[i].position[0],
            debris[i].position[1],
            debris[i].position[2]);

            glRotatef (debris[i].orientation[0], 1.0, 0.0, 0.0);
            glRotatef (debris[i].orientation[1], 0.0, 1.0, 0.0);
            glRotatef (debris[i].orientation[2], 0.0, 0.0, 1.0);

            glScalef (debris[i].scale[0],
            debris[i].scale[1],
            debris[i].scale[2]);

            glBegin (GL_TRIANGLES);
            glColor3f(((float) rand ()) / ((float) RAND_MAX), ((float) rand ()) / ((float) RAND_MAX), 0.3);
            glVertex3f (0.0, 0.5, 0.0);
            glVertex3f (-0.25, 0.0, 0.0);
            glVertex3f (0.25, 0.0, 0.0);
            glEnd ();

            glPopMatrix ();
        }
    }


    Road(road_x, road_y, road_z);
    wall(wall_x, wall_y, wall_z);

    glFlush(); // This force the execution of OpenGL commands
    glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer


    flag3++;
}
コード例 #6
0
//////////////////////////////////////////////////
// Draw everything
void RenderScene(void)
{
    static int iFrames = 0;   // Count frames to calculate fps ever 100 frames
    static float fps = 0.0f;  // Calculated fps

    // Clear the window
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glPushMatrix();
    frameCamera.ApplyCameraTransform();

    // Position light before any other transformations
    glLightfv(GL_LIGHT0, GL_POSITION, fLightPos);

    // Draw the ground
    glColor3f(1.0f, 1.0f, 1.0f);
    DrawGround();

    // Draw shadows first
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_STENCIL_TEST);
    glPushMatrix();
    glMultMatrixf(mShadowMatrix);
    DrawInhabitants(1);
    glPopMatrix();
    glDisable(GL_STENCIL_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);

    // Draw inhabitants normally
    DrawInhabitants(0);
    glPopMatrix();


    // Calculate Frame Rate, once every 100 frames
    iFrames++;
    if(iFrames == 100)
    {
        float fTime;

        // Get the current count
        LARGE_INTEGER lCurrent;
        QueryPerformanceCounter(&lCurrent);

        fTime = (float)(lCurrent.QuadPart - FPSCount.QuadPart) /
                (float)CounterFrequency.QuadPart;
        fps = (float)iFrames / fTime;


        // Reset frame count and timer
        iFrames = 0;
        QueryPerformanceCounter(&FPSCount);
    }

    // If we have the window position extension, display
    // the frame rate, and tell if multisampling was enabled
    // and if the VSync is turned on.
    if(glWindowPos2i != NULL)
    {
        int iRow = 10;
        char cBuffer[64];

        // Turn off depth test, lighting, and texture mapping
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_TEXTURE_2D);
        glColor3f(1.0f, 1.0f, 1.0f);


        // Set position and display message
        glWindowPos2i(0, iRow);
        glListBase(nFontList);
        glCallLists (13, GL_UNSIGNED_BYTE, "OpenGL Rocks!");
        iRow+= 20;

        // Display the frame rate
        sprintf(cBuffer,"FPS: %.1f", fps);
        glWindowPos2i(0, iRow);
        glCallLists(strlen(cBuffer), GL_UNSIGNED_BYTE, cBuffer);
        iRow += 20;

        // MultiSampled?
        if(startupOptions.bFSAA == TRUE && startupOptions.nPixelFormatMS != 0)
        {
            glWindowPos2i(0, iRow);
            glCallLists(25 ,GL_UNSIGNED_BYTE,"Multisampled Frame Buffer");
            iRow += 20;
        }

        // VSync?
        if(wglSwapIntervalEXT != NULL && startupOptions.bVerticalSync == TRUE)
        {
            glWindowPos2i(0, iRow);
            glCallLists(9 ,GL_UNSIGNED_BYTE, "VSync On");
            iRow += 20;
        }


        // Put everything back
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_LIGHTING);
        glEnable(GL_TEXTURE_2D);
    }
}
コード例 #7
0
ファイル: textures.c プロジェクト: untra/textures
  /*
  *  OpenGL (GLUT) calls this routine to display the scene
  */
  void display()
  {
    const double len=1.5;  //  Length of axes
    //  Erase the window and the depth buffer
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    //  Enable Z-buffering in OpenGL
    glEnable(GL_DEPTH_TEST);
    //  Undo previous transformations
    glLoadIdentity();
    //  Orthogonal - set world orientation
    if(mode == 0)
    {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
    }
    //  Perspective - set eye position
    else if (mode == 1)
    {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
    }
    // First person view
    else{
		// Recalculate where the camera is looking
		AX = -2*dim*Sin(th)*Cos(ph);
		AY = -2*dim*Sin(ph);
		AZ = -2*dim*Cos(th)*Cos(ph);
		// Orient the scene so it imitates first person movement
		gluLookAt(EX, EY, EZ, AX + EX, AY + EY, AZ + EZ, UX, UY, UZ);
	}


    //  Flat or smooth shading
    // glShadeModel(smooth ? GL_SMOOTH : GL_FLAT);

    //  Light switch
    if (light)
    {
      //  Translate intensity to color vectors
      float Ambient[]   = {0.3,0.3,0.3,1.0};
      float Diffuse[]   = {1,1,1,1};
      float Specular[]  = {1,1,0,1};
      float white[]     = {1,1,1,1};
      //  Light direction
      float Position[]  = {5*Cos(idle),0,5*Sin(idle),1};
      // printf("%f | %f | %f\n" , Position[0] , Position[1] , Position[2]    );
      //  Draw light position as ball (still no lighting here)
      ball(Position[0],Position[1],Position[2] , 0.1);
      //  Enable lighting with normalization
      glEnable(GL_NORMALIZE);
      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  Location of viewer for specular calculations
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
      //  glColor sets ambient and diffuse color materials
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Enable light 0
      glEnable(GL_LIGHT0);
      //  Set ambient, diffuse, specular components and position of light 0
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position);
      glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
    }

    //  Draw Barells
    barrel(0,0,0, 0.5,0.5,0.5 , 0);
    barrel(Cos(idle),Sin(idle), 0 ,.3,.3,.3 , Cos(3*idle));
    barrel(0,2*Cos(idle),2*Sin(idle) ,.3,.3,.3 , Sin(2*idle));
    barrel(3*Sin(idle), 0, 3*Cos(idle),.3,.3,.3 , 0);

    //  disbale lighting from here on
    glDisable(GL_LIGHTING);

    //  Draw axes
    glColor3f(1,1,1);
    if (axes)
    {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
    }
    //  Display parameters
    glWindowPos2i(10,10);
    Print("Angle=%d,%d  Dim=%.1f FOV=%d Projection=%d",th,ph,dim,fov,mode);
    glFlush();
    glutSwapBuffers();
  }
コード例 #8
0
ファイル: final.c プロジェクト: untra/final_project
  /*
  *  OpenGL (GLUT) calls this routine to display the scene
  */
  void display()
  {
    int i;
    double fall;
    const double len=10.0;  //  Length of axes
    //  Erase the window and the depth buffer
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    //  Enable Z-buffering in OpenGL
    glEnable(GL_DEPTH_TEST);
    //  Undo previous transformations
    glLoadIdentity();

    if(mode == 0)
    {
        //Set up perspective projection
        double Ex = 2*dim*Sin(th)*Cos(ph);
        double Ey = 2*dim*Sin(ph);
        double Ez = -2*dim*Cos(th)*Cos(ph);
        gluLookAt(Ex,Ey,Ez ,0,0,0, 0,Cos(ph),0);
    }
    else
    {
        //Set up first person projection
        double Cx = -2*dim*Sin(th)*Cos(ph) + xOffset;
        double Cy = 2*dim*Sin(ph) + yOffset;
        double Cz = 2*dim*Cos(th)*Cos(ph) + zOffset;
        gluLookAt(xOffset,yOffset,zOffset ,Cx,Cy,Cz, 0,Cos(ph),0);
    }

    //  Light switch
    if (light)
    {
      //  Translate intensity to color vectors
      float Ambient[]   = {0.1,0.1,0.1,1.0};
      float Diffuse[]   = {0.3,0.3,0.3,1};
      float Specular[]  = {0.2,0.2,0.2,1};
      float white[]     = {1,1,1,1};
      // float red[]     = {1,0,0,1};
      // float green[]     = {0,1,0,1};
      // float blue[]     = {0,0,1,1};
      //  Light direction
      float Position[6][4]  = {
        {68*Cos(idle[0])-38,30,20 , 1},
        {68*Cos(idle[1])-38,31,40 , 1},
        {68*Cos(idle[2])-38,32,60 , 1},
        {68*Cos(idle[3])-38,33,80 , 1},
        {68*Cos(idle[4])-38,34,100 , 1},
        {bowling_ball_x(4),bowling_ball_y(4),bowling_ball_z[4] , 1},
      };
      // printf("%f | %f | %f\n" , Position[0] , Position[1] , Position[2]    );
      //  Draw light position as ball (still no lighting here)
      ball(Position[0][0],Position[0][1],Position[0][2],1,white);
      // ball(Position[1][0],Position[1][1],Position[1][2],1,red);
      // ball(Position[2][0],Position[2][1],Position[2][2],1,green);
      // ball(Position[3][0],Position[3][1],Position[3][2],1,blue);
      // ball(Position[4][0],Position[4][1],Position[4][2],1,white);

      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  Enable lighting with normalization
      glEnable(GL_NORMALIZE);

      //  Location of viewer for specular calculations
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);

      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Enable light 0

      //  Set ambient, diffuse, specular components and position of light 0
      glEnable(GL_LIGHT0);
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position[0]);
      glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glEnable(GL_LIGHT1);
      // glLightfv(GL_LIGHT1,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT1,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT1,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT1,GL_POSITION,Position[1]);
      glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      //  Set ambient, diffuse, specular components and position of light 1

      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,red);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 2
      // glEnable(GL_LIGHT2);
      // glLightfv(GL_LIGHT2,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT2,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT2,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT2,GL_POSITION,Position[2]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,green);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 3
      // glEnable(GL_LIGHT3);
      // glLightfv(GL_LIGHT3,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT3,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT3,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT3,GL_POSITION,Position[3]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,blue);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 4
      // glEnable(GL_LIGHT4);
      // glLightfv(GL_LIGHT4,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT4,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT4,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT4,GL_POSITION,Position[4]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 5
      // glEnable(GL_LIGHT5);
      // glLightfv(GL_LIGHT5,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT5,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT5,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT5,GL_POSITION,Position[5]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,colors[4]);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
    }
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


    wall(33.5,0,-30,10,12,10,0,180,wall_texture);
    wall(33.5,0,0,10,12,10,0,180,wall_texture);
    wall(33.5,0,30,10,12,10,0,180,wall_texture);
    wall(33.5,0,60,10,12,10,0,180,wall_texture);
    wall(33.5,0,90,10,12,10,0,180,wall_texture);
    wall(33.5,0,120,10,12,10,0,180,wall_texture);
    mural(-2,0,-10, 12,12,10 , 0, 0, mural_texture[0], light);
    mural(-38,0,-10, 12,12,10 , 0, 0, mural_texture[1], light);
    mural(-74,0,-10, 12,12,10 , 0, 0, mural_texture[2], light);
    mural(-110,0,-10, 12,12,10 , 0, 0, mural_texture[3], light);
    for(i = 0 ; i < 8 ; i++)
    {
      fall = explosion[i] > 180 ? (double)explosion[i]/180.0 : 0;
      fall = fall*fall;
      pins(pin_x[i],reset[i] - fall,0,1,1,1,0,explosion[i]);
    }
    double_lane(0,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    double_lane(-36,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    double_lane(-72,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    double_lane(-108,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    wall(-110.5,0,-60,10,12,10,0,0,wall_texture);
    wall(-110.5,0,-30,10,12,10,0,0,wall_texture);
    wall(-110.5,0,0,10,12,10,0,0,wall_texture);
    wall(-110.5,0,30,10,12,10,0,0,wall_texture);
    wall(-110.5,0,60,10,12,10,0,0,wall_texture);
    wall(-110.5,0,90,10,12,10,0,0,wall_texture);
    for(i = 0 ; i < 8 ; i++)
    {
      bowling_ball(bowling_ball_x(i),bowling_ball_y(i),bowling_ball_z[i],1,1,1,ball_ph[i],ball_texture, colors[i]);
    }

    //enable textures


    //  disbale lighting from here on
    if (light)
    {
      glDisable(GL_LIGHTING);
    }
    //  Draw axes
    glColor3f(1,1,1);
    if (axes)
    {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
    }

      glWindowPos2i(5,5);
      if(mode == 0)
      {
          Print("Projection Type: Perspective");
          glWindowPos2i(5,25);
          Print("Dimension: %.0f", dim);
      }
      else
      {
          Print("Projection Type: First Person");
          glWindowPos2i(5,25);
          Print("User Location: { %.3f, %.3f, %.3f }", xOffset, yOffset, zOffset);
      }

      //Render scene
      glFlush();
      glutSwapBuffers();
  }
コード例 #9
0
ファイル: ex32.c プロジェクト: jchan1e/graphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   int k,i;
   Point S[NMAX];

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT);
   //  Enable vertex generation
   glEnable(GL_MAP1_VERTEX_3);

   //  Draw and label points
   glColor3f(1,1,1);
   glPointSize(5);
   glBegin(GL_POINTS);
   for (k=0;k<n;k++)
      glVertex2f(P[k].x,P[k].y);
   glEnd();
   for (k=0;k<n;k++)
   {
      glRasterPos2d(P[k].x,P[k].y);
      Print("P%d",k);
   }
   //  Draw curve when we have enough points
   switch (mode)
   {
      //  Continuous Bezier
      case 0:
         for (k=0;k<n-3;k+=3)
         {
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)(P+k));
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
         }
         break;
      //  Smooth Bezier
      case 1:
         //  First four
         if (n>=4)
         {
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)P);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
         }
         //  Subsequent triples
         for (k=3;k<n-2;k+=2)
         {
            Point r[4];
            //  P0, P2 and P3 are specified points
            r[0] = P[k];
            r[2] = P[k+1];
            r[3] = P[k+2];
            //  P1 is computed by reflecting P2 from previous segment
            r[1].x = 2*P[k].x-P[k-1].x;
            r[1].y = 2*P[k].y-P[k-1].y;
            r[1].z = 2*P[k].z-P[k-1].z;
            //  Draw curve
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)r);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
            //  Draw reflected point in red
            glColor3f(1,0,0);
            glBegin(GL_POINTS);
            glVertex2f(r[1].x,r[1].y);
            glEnd();
            glRasterPos2d(r[1].x,r[1].y);Print("R%d",k-1);
         }
         break;
      //  Interpolate 4 at a time
      case 2:
         for (k=0;k<n-3;k+=3)
         {
            Point r[4];
            //  Transform 4 data points to 4 control points
            Pmult(Mi,P+k,r);
            //  Draw curve
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)r);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
            //  Draw control points
            glColor3f(1,0,0);
            glBegin(GL_POINTS);
            glVertex2f(r[1].x,r[1].y);
            glVertex2f(r[2].x,r[2].y);
            glEnd();
            glRasterPos2d(r[1].x,r[1].y);Print("R%d",k+1);
            glRasterPos2d(r[2].x,r[2].y);Print("R%d",k+2);
         }
         break;
      //  B Spline 4 at a time
      case 3:
         for (k=0;k<n-3;k++)
         {
            int j;
            Point r[4];
            //  Transform 4 data points to 4 control points (note increment is 1)
            Pmult(Ms,P+k,r);
            //  Draw curve
            glColor3f(1,1,0);
            glMap1d(GL_MAP1_VERTEX_3,0.0,1.0,3,4,(void*)r);
            glMapGrid1f(m,0.0,1.0);
            glEvalMesh1(GL_LINE,0,m);
            //  Draw control points
            glColor3f(1,0,0);
            glBegin(GL_POINTS);
            for (j=0;j<4;j++)
               glVertex2f(r[j].x,r[j].y);
            glEnd();
         }
         break;
      //  Cubic Natural Spline
      case 4:
         //  Calculate (x,y,z) splines
         CubicSpline((void*)P,(void*)S,0,n);
         CubicSpline((void*)P,(void*)S,1,n);
         CubicSpline((void*)P,(void*)S,2,n);
         //  Draw entire curve
         glColor3f(1,1,0);
         glBegin(GL_LINE_STRIP);
         for (k=0;k<n-1;k++)
         {
            //  Cardinal point
            glVertex2d(P[k].x,P[k].y);
            //  Increment between k and k+1
            for (i=1;i<m;i++)
            {
               double f  = (double)i/m;
               double g  = 1-f;
               double f2 = (f*f*f-f)/6;
               double g2 = (g*g*g-g)/6;
               double x  = f*P[k+1].x + g*P[k].x + f2*S[k+1].x + g2*S[k].x;
               double y  = f*P[k+1].y + g*P[k].y + f2*S[k+1].y + g2*S[k].y;
               double z  = f*P[k+1].z + g*P[k].z + f2*S[k+1].z + g2*S[k].z;
               glVertex3d(x,y,z);
            }
         }
         //  Last cardinal point
         glVertex2d(P[n-1].x,P[n-1].y);
         glEnd();
         break;
      default:
         break;
   }
   
   //  Display parameters
   glColor3f(1,1,1);
   glWindowPos2i(5,5);
   Print(text[mode]);
   if (n<NMAX)
      Print(" Click to add point\n");
   else
      Print(" Click to start new curve\n");

   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #10
0
ファイル: main.cpp プロジェクト: sahle123/Personal-References
/*  display  */
void display()
{
    // Light emitter variables
    int light_distance  = 3;    // How far away the light is from the object
    GLfloat light_size  = 0.1;  // The size of the ball of light
    GLfloat ylight      = 2.0;    // y coordinate of light ball.
    // Light variables. (These values can be found in clank_builder.h)
    GLfloat Emission[]  = {emission,emission,emission, 1.0};
    GLfloat Ambient[]   = {ambient,ambient,ambient, 1.0};
    GLfloat Diffuse[]   = {diffuse,diffuse,diffuse, 1.0};
    GLfloat Specular[]  = {specular,specular,specular, 1.0};
    GLfloat Shinyness[] = {shinyness};

    // Position of the ball light and emanating light (Orbit)
    GLfloat Position[]  = {static_cast<GLfloat>(light_distance*Cos(Glo_zh)), ylight,
                           static_cast<GLfloat>(light_distance*Sin(Glo_zh)), 1.0};
    // Position of the ball light and emanating light (Circle)
    GLfloat Position2[] = {static_cast<GLfloat>(Cos(Glo_zh)), static_cast<GLfloat>(ylight + Sin(Glo_zh)), 2, 1};


    // Instantiate myClank object
    Obj_Clank myClank(Glo_th, Glo_ph);

    // Check which animation to use for clank object.
    Glo_is_animated = myClank.set_animation(Glo_is_animated);


    // Clear the image
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    // Enable Z-buffering depth test
    glEnable(GL_DEPTH_TEST);
    // Reset previous transforms
    glLoadIdentity();

    /// Choose how to rotate (For ortho and perspective)
    if(Glo_Mode == 1) // Ortho
    {
        // Sets ortho rotation view
        glRotated(Glo_ph, 1, 0, 0);
        glRotated(Glo_th, 0, 1, 0);
    }
    else if(Glo_Mode == 2) // Perspective
    {
        double Ex = -2*Glo_dim*Sin(Glo_th)*Cos(Glo_ph);
        double Ey = +2*Glo_dim*Sin(Glo_ph);
        double Ez = +2*Glo_dim*Cos(Glo_th)*Cos(Glo_ph);
        gluLookAt(Ex, Ey+Glo_y, Ez, 0, Glo_y, 0, 0, Cos(Glo_ph), 0);
    }

    // *** Lighting section ***//
    myClank.is_light(Glo_Light);

    // Draw a orbiting light
    if(Glo_Light)
        myClank.light_ball(Position[0],Position[1],Position[2] , light_size);
    // Else draw a circling light
    else
        myClank.light_ball(Position2[0],Position2[1],Position2[2] , light_size);

    //  OpenGL should normalize normal vectors
    glEnable(GL_NORMALIZE);
    //  Enable lighting
    glEnable(GL_LIGHTING);
    //  Enable light 0
    glEnable(GL_LIGHT0);
    //  Set ambient, diffuse, specular components and position of light 0
    glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
    glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
    glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);

    // Set the correct lighting according to light ball's position
    if(Glo_Light)
        glLightfv(GL_LIGHT0,GL_POSITION,Position);
    else
        glLightfv(GL_LIGHT0,GL_POSITION,Position2);

    // Set material properties
    glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,Shinyness);
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,  Ambient);
    glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,  Diffuse);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR, Specular);
    glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, Emission);
    // *** End of Lighting **//

    // Decide whether to draw Old Clank or New Clank
    if(Glo_oldClank)
    {
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
        myClank.simple_draw_clank();
    }
    else
    {
        // Disable lighting from Old Clank, otherwise render looks bad.
        glDisable(GL_COLOR_MATERIAL);

        // Compile the object file (Important step!!!)
        myClank.compile_clank(OBJ_Hand, OBJ_RightShoulder, OBJ_Right_hand2, OBJ_LeftShoulder,
                              OBJ_Left_hand2, OBJ_Body, OBJ_Head, Glo_Scale);
    }

    // Disable lighting
    glDisable(GL_LIGHTING);

    // Draw the cartesian coordinate plane
    draw_axes();

    // Display parameters
    switch(Glo_is_animated)
    {
    case 0:
        glWindowPos2i(5, 5);
        Print("Animation:   Standing");
        break;
    case 1:
        glWindowPos2i(5, 5);
        Print("Animation:   Waving");
        break;
    case 2:
        glColor3f(0.8,0.8,0);
        glWindowPos2i(5, 5);
        Print("Animation:   Praise the Sun!");
        glColor3f(1,1,1);
        break;
    }
    //Print("View Angle=%d, %d Glo_dim=%.1f Glo_FOV=%d Projection=%s",
    //      Glo_th, Glo_ph, Glo_dim, Glo_FOV, Glo_Text[Glo_Mode-1].c_str());

    glColor3f(1,1,1);
    // Displays Status
    glWindowPos2i(5,25);
    Print("Light Mode: %s",Glo_Light?"Orbiting":"Circling");

    // Rasterized "Hi" text for wave animation
    if(Glo_is_animated == 1)
    {
        glRasterPos3d(1, 4, 0);
        Print("Hi :)");
    }

    glFlush();
    glutSwapBuffers();
}
コード例 #11
0
ファイル: ex06.c プロジェクト: jchan1e/graphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.0;  //  Length of axes
   //  Light position and colors
   float Ambient[]   = {0.3,0.3,0.3,1.0};
   float Diffuse[]   = {1.0,1.0,1.0,1.0};
   float Specular[]  = {1.0,1.0,1.0,1.0};
   float Position[]  = {(float)(2*Cos(zh)),Ylight,(float)(2*Sin(zh)),1.0};

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);

   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      float Ex = -2*dim*Sin(th)*Cos(ph);
      float Ey = +2*dim        *Sin(ph);
      float Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Draw light position as sphere
   //  This uses the fixed pipeline
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Position[0],Position[1],Position[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();

   //  Fixed pipeline
   if (mode==0)
   {
      //  OpenGL should normalize normal vectors
      glEnable(GL_NORMALIZE);
      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  glColor sets ambient and diffuse color materials
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Enable light 0
      glEnable(GL_LIGHT0);
      //  Set ambient, diffuse, specular components and position of light 0
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position);

      //  Enable textures
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D,crate);

      //  Enabe arrays
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_NORMAL_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);

      //  Set pointers
      glVertexPointer  (4,GL_FLOAT,12*sizeof(GLfloat),cube_data);
      glNormalPointer  (  GL_FLOAT,12*sizeof(GLfloat),cube_data+4);
      glColorPointer   (3,GL_FLOAT,12*sizeof(GLfloat),cube_data+7);
      glTexCoordPointer(2,GL_FLOAT,12*sizeof(GLfloat),cube_data+10);

      //  Draw the cube
      glDrawArrays(GL_TRIANGLES,0,cube_size);

      //  Disable arrays
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_NORMAL_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);

      //  Disable textures
      glDisable(GL_TEXTURE_2D);
   }
   //  OpenGL 4 style shaders
   else
   {
      int loc;
      float ModelViewMatrix[16];
      float ProjectionMatrix[16];
      glGetFloatv(GL_PROJECTION_MATRIX,ProjectionMatrix);
      glGetFloatv(GL_MODELVIEW_MATRIX,ModelViewMatrix);

      // Use our shader
      glUseProgram(shader);

      //  Set Modelview and Projection Matrix
      loc = glGetUniformLocation(shader, "ModelViewMatrix");
      if (loc>=0) glUniformMatrix4fv(loc,1,GL_FALSE,ModelViewMatrix);
      loc = glGetUniformLocation(shader, "ProjectionMatrix");
      if (loc>=0) glUniformMatrix4fv(loc,1,GL_FALSE,ProjectionMatrix);

      //  Select cube buffer
      glBindBuffer(GL_ARRAY_BUFFER,cube_buffer);
      //   Attribute 0: vertex coordinate (vec4) at offset 0
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,12*sizeof(float),(void*)0);
      //   Attribute 1:  vertex color (vec3) offset 7 floats
      glEnableVertexAttribArray(1);
      glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,12*sizeof(float),(void*)(7*sizeof(float)));

      // Draw the cube
      glDrawArrays(GL_TRIANGLES,0,cube_size);

      //  Disable vertex arrays
      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);

      //  Unbind this buffer
      glBindBuffer(GL_ARRAY_BUFFER,0);

      // Back to fixed pipeline
      glUseProgram(0);
   }

   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("FPS=%d Dim=%.1f Projection=%s Mode=%s",
     FramesPerSecond(),dim,proj?"Perpective":"Orthogonal",text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #12
0
ファイル: hw5.c プロジェクト: gddmkr42171822/csci5229
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
	const double len=2.0;  //  Length of axes
	//  Erase the window and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	//  Enable Z-buffering in OpenGL
	glEnable(GL_DEPTH_TEST);
	// Enable face culling in OpenGL
	glEnable(GL_CULL_FACE);
	//  Undo previous transformations
	glLoadIdentity();
	//  Perspective - set eye position
	if (mode == 1){
		double Ex = -2*dim*Sin(th)*Cos(ph);
		double Ey = +2*dim        *Sin(ph);
		double Ez = +2*dim*Cos(th)*Cos(ph);
		gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
	}
	//  Orthogonal - set world orientation
	else if(mode == 0){
		glRotatef(ph,1,0,0);
		glRotatef(th,0,1,0);
	}

	if(light){
		//  Translate intensity to color vectors
		float Ambient[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
		float Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
		float Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};
		//  Light position
		float Position[]  = {distance*Cos(zh),ylight,distance*Sin(zh),1.0};
		//  Draw light position as ball (still no lighting here)
		glColor3f(1,1,1);
		sphere(Position[0],Position[1],Position[2] , 0.1, 1.0, 1.0, 1.0);
		//  OpenGL should normalize normal vectors
		glEnable(GL_NORMALIZE);
		//  Enable lighting
		glEnable(GL_LIGHTING);
		//  glColor sets ambient and diffuse color materials
		glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
		glEnable(GL_COLOR_MATERIAL);
		//  Enable light 0
		glEnable(GL_LIGHT0);
		//  Set ambient, diffuse, specular components and position of light 0
		glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
		glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
		glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
		glLightfv(GL_LIGHT0,GL_POSITION,Position);
	}else{
		glDisable(GL_LIGHTING);
	}

	glPushMatrix();
	//helicopter(0);
	movingHelicopter();
	glPopMatrix();
	glColor3f(1,1,1);

	//  Draw axes - no lighting from here on
	glDisable(GL_LIGHTING);
	glColor3f(1,1,1);
	if(axes){
		//  Draw axes
		glBegin(GL_LINES);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(len,0.0,0.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(0.0,len,0.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(0.0,0.0,len);
		glEnd();
		//  Label axes
		glRasterPos3d(len,0.0,0.0);
		Print("X");
		glRasterPos3d(0.0,len,0.0);
		Print("Y");
		glRasterPos3d(0.0,0.0,len);
		Print("Z");
	}
	//  Display parameters
	glWindowPos2i(5,5);
	Print("Angle=%d,%d  Dim=%.1f FOV=%d Projection=%s Light=%s",
	     th,ph,dim,fov,mode?"Perspective":"Orthogonal",light?"On":"Off");
	if (light)
	   {
	      glWindowPos2i(5,45);
	      Print("Distance=%d Elevation=%.1f", distance, ylight);
	      glWindowPos2i(5,25);
	      Print("Ambient=%d  Diffuse=%d Specular=%d Emission=%d Shininess=%.0f",ambient,diffuse,specular,emission,shinyvec[0]);
	   }
	// Check for any errors that have occurred
	ErrCheck("display");
	//  Render the scene and make it visible
	glFlush();
	glutSwapBuffers();
}
コード例 #13
0
ファイル: RenderTarget.cpp プロジェクト: JamesLinus/pipeline
    std::vector<uint8_t> RenderTarget::getImagePixels( GLenum mode, dp::PixelFormat pixelFormat, dp::DataType pixelDataType )
    {
      // FIXME use C++ object for current/noncurrent for exception safety
      makeCurrent();

      size_t components = 0;
      size_t bytesPerComponent = 0;

      // set up alignments
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
      glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
      glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
      glPixelStorei(GL_PACK_ALIGNMENT, 1);
      glPixelStorei(GL_PACK_ROW_LENGTH, 0);
      glPixelStorei(GL_PACK_SKIP_ROWS, 0);
      glPixelStorei(GL_PACK_SKIP_PIXELS, 0);

      // determine OpenGL format
      GLenum format = ~0;
      switch (pixelFormat)
      {
      case dp::PixelFormat::RGB:
        format = GL_RGB;
        components = 3;
        break;
      case dp::PixelFormat::RGBA:
        format = GL_RGBA;
        components = 4;
        break;
      case dp::PixelFormat::BGR:
        format = GL_BGR;
        components = 3;
        break;
      case dp::PixelFormat::BGRA:
        format = GL_BGRA;
        components = 4;
        break;
      case dp::PixelFormat::LUMINANCE:
        format = GL_LUMINANCE;
        components = 1;
        break;
      case dp::PixelFormat::ALPHA:
        format = GL_ALPHA;
        components = 1;
        break;
      case dp::PixelFormat::LUMINANCE_ALPHA:
        format = GL_LUMINANCE_ALPHA;
        components = 2;
        break;
      case dp::PixelFormat::DEPTH_COMPONENT:
        format = GL_DEPTH_COMPONENT;
        components = 1;
        break;
      case dp::PixelFormat::DEPTH_STENCIL:
        format = GL_DEPTH_STENCIL;
        components = 1;
        break;
      case dp::PixelFormat::STENCIL_INDEX:
        format = GL_STENCIL_INDEX;
        components = 1;
        break;
      default:
        DP_ASSERT(0 && "unsupported PixelFormat");
      };

      GLenum dataType = ~0;
      switch (pixelDataType)
      {
      case dp::DataType::INT_8:
        dataType = GL_BYTE;
        bytesPerComponent = 1;
        break;
      case dp::DataType::UNSIGNED_INT_8:
        dataType = GL_UNSIGNED_BYTE;
        bytesPerComponent = 1;
        break;
      case dp::DataType::INT_16:
        dataType = GL_SHORT;
        bytesPerComponent = 2;
        break;
      case dp::DataType::UNSIGNED_INT_16:
        dataType = GL_UNSIGNED_SHORT;
        bytesPerComponent = 2;
        break;
      case dp::DataType::INT_32:
        dataType = GL_INT;
        bytesPerComponent = 4;
        break;
      case dp::DataType::UNSIGNED_INT_32:
        dataType = GL_UNSIGNED_INT;
        bytesPerComponent = 4;
        break;
      case dp::DataType::FLOAT_32:
        dataType = GL_FLOAT;
        bytesPerComponent = 4;
        break;
      case dp::DataType::FLOAT_16:
        dataType = GL_HALF_FLOAT;
        bytesPerComponent = 2;
        break;
      default:
        DP_ASSERT(0 && "unsupported PixelDataType");
      }

      size_t imageSizeInBytes = m_width * m_height * components * bytesPerComponent;
      std::vector<uint8_t> output(imageSizeInBytes);

      if ( imageSizeInBytes )
      {
        // read the pixels
        glWindowPos2i(0,0);
        glReadBuffer( mode );

        glReadPixels(0, 0, m_width, m_height, format, dataType, &output[0]);
      }

      makeNoncurrent();

      return output;
    }
コード例 #14
0
ファイル: RenderTarget.cpp プロジェクト: JamesLinus/pipeline
    bool RenderTarget::copyToBuffer( GLenum mode, dp::sg::core::Image::PixelFormat pixelFormat, dp::sg::core::Image::PixelDataType pixelDataType, const dp::sg::core::BufferSharedPtr & buffer )
    {
      // FIXME use C++ object for current/noncurrent for exception safety
      makeCurrent();

      size_t components = 0;
      size_t bytesPerComponent = 0;

      // set up alignments
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
      glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
      glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
      glPixelStorei(GL_PACK_ALIGNMENT, 1);
      glPixelStorei(GL_PACK_ROW_LENGTH, 0);
      glPixelStorei(GL_PACK_SKIP_ROWS, 0);
      glPixelStorei(GL_PACK_SKIP_PIXELS, 0);

      // determine OpenGL format
      GLenum format = ~0;
      switch (pixelFormat)
      {
      case dp::PixelFormat::RGB:
        format = GL_RGB;
        components = 3;
      break;
      case dp::PixelFormat::RGBA:
        format = GL_RGBA;
        components = 4;
      break;
      case dp::PixelFormat::BGR:
        format = GL_BGR;
        components = 3;
      break;
      case dp::PixelFormat::BGRA:
        format = GL_BGRA;
        components = 4;
      break;
      case dp::PixelFormat::LUMINANCE:
        format = GL_LUMINANCE;
        components = 1;
      break;
      case dp::PixelFormat::ALPHA:
        format = GL_ALPHA;
        components = 1;
      break;
      case dp::PixelFormat::LUMINANCE_ALPHA:
        format = GL_LUMINANCE_ALPHA;
        components = 2;
      break;
      case dp::PixelFormat::DEPTH_COMPONENT:
        format = GL_DEPTH_COMPONENT;
        components = 1;
      break;
      case dp::PixelFormat::DEPTH_STENCIL:
        format = GL_DEPTH24_STENCIL8;
        components = 1;
      break;
      default:
        DP_ASSERT(0 && "unsupported PixelFormat");
      };

      GLenum dataType = ~0;
      switch (pixelDataType)
      {
      case dp::PixelFormat::PF_BYTE:
        dataType = GL_BYTE;
        bytesPerComponent = 1;
      break;
      case dp::PixelFormat::PF_UNSIGNED_BYTE:
        dataType = GL_UNSIGNED_BYTE;
        bytesPerComponent = 1;
      break;
      case dp::PixelFormat::PF_SHORT:
        dataType = GL_SHORT;
        bytesPerComponent = 2;
      break;
      case dp::PixelFormat::PF_UNSIGNED_SHORT:
        dataType = GL_UNSIGNED_SHORT;
        bytesPerComponent = 2;
      break;
      case dp::PixelFormat::PF_INT:
        dataType = GL_INT;
        bytesPerComponent = 4;
      break;
      case dp::PixelFormat::PF_UNSIGNED_INT:
        dataType = GL_UNSIGNED_INT;
        bytesPerComponent = 4;
      break;
      case dp::PixelFormat::PF_FLOAT32:
        dataType = GL_FLOAT;
        bytesPerComponent = 4;
      break;
      case dp::PixelFormat::PF_FLOAT16:
        dataType = GL_HALF_FLOAT;
        bytesPerComponent = 2;
      break;
      default:
        DP_ASSERT(0 && "unsupported PixelDataType");
      }

      BufferLock(buffer)->setSize(m_width * m_height * components * bytesPerComponent);

      // read the pixels
      glWindowPos2i(0,0);
      glReadBuffer( mode );

      bool isBufferGL = std::dynamic_pointer_cast<BufferGL>(buffer);
      if ( isBufferGL )
      {
        GLint oldPBO;
        glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &oldPBO);
        // FIXME it's necessary to check wheter the buffer object shared data with the current context...
        BufferGLLock bufferGL( sharedPtr_cast<BufferGL>( buffer ) );
        bufferGL->bind( GL_PIXEL_PACK_BUFFER );
        glReadPixels(0, 0, m_width, m_height, format, dataType, 0);
        glBindBuffer(GL_PIXEL_PACK_BUFFER, (GLuint)oldPBO);
      }
      else
      {
        Buffer::DataWriteLock bufferLock(buffer, Buffer::MAP_WRITE);
        glReadPixels(0, 0, m_width, m_height, format, dataType, bufferLock.getPtr());
      }

      makeNoncurrent();

      return true;
    }
コード例 #15
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.0;  //  Length of axes
   //  Light position and colors
   float Emission[]  = {0.0,0.0,0.0,1.0};
   float Ambient[]   = {0.3,0.3,0.3,1.0};
   float Diffuse[]   = {1.0,1.0,1.0,1.0};
   float Specular[]  = {spc,spc,spc,1.0};
   float Position[]  = {2*Cos(zh),Ylight,2*Sin(zh),1.0};
   float Shinyness[] = {16};

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Draw light position as sphere (still no lighting here)
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Position[0],Position[1],Position[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();

   //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  Enable light 0
   glEnable(GL_LIGHT0);
   //  Set ambient, diffuse, specular components and position of light 0
   glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
   glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
   glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
   glLightfv(GL_LIGHT0,GL_POSITION,Position);
   //  Set materials
   glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,Shinyness);
   glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,RGBA);
   glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,RGBA);
   glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Specular);
   glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Emission);
   glColor3f(0.1,0.3,0.8);
   //  Draw the model
   glPushMatrix();
   glScaled(scale,scale,scale);
   glCallList(obj);
   int i;
   for (i = 1; i < 100; i ++)
   {
   glTranslated(i, 0, i);
   glCallList(obj);
   }
   glPopMatrix();

   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(0.2,0.7,0.1);

   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f Projection=%s",
     th,ph,dim,proj?"Perpective":"Orthogonal");
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #16
0
/*
 *  Display the scene
 *  Taken from HW3 and Example 9
 */
void display()
{
   const double len=1.5;  //  Length of axes
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();

   if (fp) {
      Cx = +2*dim*Sin(rot); //Ajust the camera vector based on rot
      Cz = -2*dim*Cos(rot);

      gluLookAt(Ex,Ey,Ez, Cx+Ex,Ey,Cz+Ez, 0,1,0); //  Use gluLookAt, y is the up-axis

   }
   else {
      //  Perspective - set eye position
      if (mode)
      {
         double px = -2*dim*Sin(th)*Cos(ph);
         double py = +2*dim        *Sin(ph);
         double pz = +2*dim*Cos(th)*Cos(ph);
         gluLookAt(px,py,pz , 0,0,0 , 0,Cos(ph),0);
      }
      //  Orthogonal - set world orientation
      else
      {
         glRotatef(ph,1,0,0);
         glRotatef(th,0,1,0);
      }
   }

   glShadeModel(GL_SMOOTH);
   //  Translate intensity to color vectors
   float Ambient[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
   float Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
   float Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};
   //  Light position
   float Position[]  = {distance*Cos(zh),ylight,distance*Sin(zh),1.0};
   //  Draw light position as ball (still no lighting here)
   glColor3f(1,1,1);
   ball(Position[0],Position[1],Position[2] , 0.1);
   //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  Location of viewer for specular calculations
   glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
   //  glColor sets ambient and diffuse color materials
   glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
   glEnable(GL_COLOR_MATERIAL);
   //  Enable light 0
   glEnable(GL_LIGHT0);
   //  Set ambient, diffuse, specular components and position of light 0
   glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
   glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
   glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
   glLightfv(GL_LIGHT0,GL_POSITION,Position);

   /* Draw 4 Clyinders */   
   drawCylinder(0, 0, 0, 1, 1, 1, 0, 'b', 'b');
   drawCylinder(.5, .5, .5, 1, 3, 1, 20, 'q', 'q');
   drawCylinder(-.9, 0, 0, 2, 2, 1, 90, 'g', 'g');
   drawCylinder(-.6, -.6, -.8, .3, .5, .3, -45, 'r', 'r');

//  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }

   //  Display parameters
   glWindowPos2i(5,5);   
   if (fp) {
      Print("FP=On View Angle=%d",rot);
   }
   else {
      Print("FP=Off Angle=%d,%d  Dim=%.1f FOV=%d Projection=%s",th,ph,dim,fov,mode?"Perpective":"Orthogonal");
   }

   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #17
0
ファイル: fbo-viewport.c プロジェクト: ThirteenFish/piglit
enum piglit_result
piglit_display(void)
{
	GLubyte *win_image, *fbo_image;
	GLuint fbo, rb;
	bool pass = true;

	win_image = (GLubyte *) malloc(piglit_width * piglit_height * 3);
	fbo_image = (GLubyte *) malloc(piglit_width * piglit_height * 3);

	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	glGenRenderbuffers(1, &rb);
	glBindRenderbuffer(GL_RENDERBUFFER, rb);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA,
			      piglit_width, piglit_height);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				  GL_RENDERBUFFER, rb);

	assert(glGetError() == 0);

	assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
			 GL_FRAMEBUFFER_COMPLETE_EXT);

	/* draw reference image in the window */
	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
	draw_test_image();
	glReadPixels(0, 0, piglit_width, piglit_height,
		     GL_RGB, GL_UNSIGNED_BYTE, win_image);

	/* draw test image in fbo */
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	glReadBuffer(GL_COLOR_ATTACHMENT0);
	draw_test_image();
	glReadPixels(0, 0, piglit_width, piglit_height,
		     GL_RGB, GL_UNSIGNED_BYTE, fbo_image);

	/* compare images */
	if (memcmp(win_image, fbo_image, piglit_width * piglit_height * 3)) {
#if 0 /* helpful debug code */
		int i, k;
		for (i = k = 0; i < piglit_width * piglit_height * 3; i++) {
			if (win_image[i] != fbo_image[i] && k++ < 40)
				printf("%d: %d vs. %d\n",
				       i, win_image[i], fbo_image[i]);
		}
#endif
		printf("Image comparison failed!\n");
		pass = false;
	}
	else if (!piglit_automatic) {
		printf("Image comparison passed.\n");
	}

	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);

#if 0	/* for debug/compare (alternate diplaying Window vs. FBO image) */
	{
		int i;
		glWindowPos2i(0,0);
		for (i = 0; i < 10; i++) {
			GLubyte *image = (i & 1) ? fbo_image : win_image;
			printf("Showing %s image\n", (i & 1) ? "FBO" : "window");
			glDrawPixels(piglit_width, piglit_height,
				     GL_RGB, GL_UNSIGNED_BYTE, image);
			piglit_present_results();
			sleep(1);
		}
	}
#endif

	piglit_present_results();

	glDeleteRenderbuffers(1, &rb);
	glDeleteFramebuffers(1, &fbo);
	free(win_image);
	free(fbo_image);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
コード例 #18
0
/*
 *  Display the scene
 */
void display()
{
   //  Clear the image
   glClear(GL_COLOR_BUFFER_BIT);
   
   //  Reset previous transforms
   glLoadIdentity();
   
   //  Set view angle
   glRotated(ph,1,0,0);
   glRotated(th,0,1,0);
   
   //  Draw 10 pixel yellow points
   glPointSize(2);
   glBegin(GL_LINE_STRIP);
   switch (mode)
   {
   //  Two dimensions
   case 1:
   /*  Coordinates  */
      x = 1.0;
      y = 1.0;
      z = 1.0;

      /*  Time step  */
      dt = 0.001;

      /*
       *  Integrate 50,000 steps (50 time units with dt = 0.001)
       *  Explicit Euler integration
       */
      for (i=0; i<50000; i++)
      {
         //Calculate differentials
         dx = s*(y-x);
         dy = x*(r-z)-y;
         dz = x*y - b*z;
         
         // Determine new variables for point
         x = (double)(x + dt*dx);
         y = (double)(y + dt*dy);
         z = (double)(z + dt*dz);
         
         /* Set Color and Create Point */
         // Make dx positive and scale
         if (dx < 0)
            cx = (-1 * dx) / 200.00;
         else
            cx = dx / 200.00;
         
         // Make dy positive and scale
         if (dy < 0)
            cy = (-1 * dy) / 200.00;
         else
            cy = dy / 200.00;
         
         //Make dz positive and scale
         if (dx < 0)
            cz = (-1 * dz) / 200.00;
         else
            cz = dz / 200.00;

         glColor3f(cx, cy, cz);
         glVertex2d(x, y);
      }
      break;
   //  Three dimensions - constant Z
   case 2:
      /*  Coordinates  */
      x = 1.0;
      y = 1.0;
      z = 1.0;

      /*  Time step  */
      dt = 0.001;

      /*
       *  Integrate 50,000 steps (50 time units with dt = 0.001)
       *  Explicit Euler integration
       */
      for (i=0; i<50000; i++)
      {
         //Calculate differentials
         dx = s*(y-x);
         dy = x*(r-z)-y;
         dz = x*y - b*z;
         
         // Determine new variables for point
         x = (double)(x + dt*dx);
         y = (double)(y + dt*dy);
         z = (double)(z + dt*dz);
         
         /* Set Color and Create Point */
         // Make dx positive and scale
         if (dx < 0)
            cx = (-1 * dx) / 200.00;
         else
            cx = dx / 200.00;
         
         // Make dy positive and scale
         if (dy < 0)
            cy = (-1 * dy) / 200.00;
         else
            cy = dy / 200.00;
         
         //Make dz positive and scale
         if (dx < 0)
            cz = (-1 * dz) / 200.00;
         else
            cz = dz / 200.00;

         glColor3f(cx, cy, cz);
         glVertex3d( x, y, def_z);
      }
      break;
   //  Three dimensions - variable Z
   case 3:
      /*  Coordinates  */
      x = 1.0;
      y = 1.0;
      z = 1.0;

      /*  Time step  */
      dt = 0.001;

      /*
       *  Integrate 50,000 steps (50 time units with dt = 0.001)
       *  Explicit Euler integration
       */
      for (i=0; i<50000; i++)
      {
         //Calculate differentials
         dx = s*(y-x);
         dy = x*(r-z)-y;
         dz = x*y - b*z;
         
         // Determine new variables for point
         x = (double)(x + dt*dx);
         y = (double)(y + dt*dy);
         z = (double)(z + dt*dz);
         
         /* Set Color and Create Point */
         // Make dx positive and scale
         if (dx < 0)
            cx = (-1 * dx) / 200.00;
         else
            cx = dx / 200.00;
         
         // Make dy positive and scale
         if (dy < 0)
            cy = (-1 * dy) / 200.00;
         else
            cy = dy / 200.00;
         
         //Make dz positive and scale
         if (dx < 0)
            cz = (-1 * dz) / 200.00;
         else
            cz = dz / 200.00;

         glColor3f(cx, cy, cz);
         glVertex3d( x, y, z);
      }
      break;
   //  Four dimensions
   case 4:
      /*  Coordinates  */
      x = 1.0;
      y = 1.0;
      z = 1.0;

      /*  Time step  */
      dt = 0.001;

      /*
       *  Integrate 50,000 steps (50 time units with dt = 0.001)
       *  Explicit Euler integration
       */
      for (i=0; i<50000; i++)
      {
         //Calculate differentials
         dx = s*(y-x);
         dy = x*(r-z)-y;
         dz = x*y - b*z;
         
         // Determine new variables for point
         x = (double)(x + dt*dx);
         y = (double)(y + dt*dy);
         z = (double)(z + dt*dz);
         
         /* Set Color and Create Point */
         // Make dx positive and scale
         if (dx < 0)
            cx = (-1 * dx) / 200.00;
         else
            cx = dx / 200.00;
         
         // Make dy positive and scale
         if (dy < 0)
            cy = (-1 * dy) / 200.00;
         else
            cy = dy / 200.00;
         
         //Make dz positive and scale
         if (dx < 0)
            cz = (-1 * dz) / 200.00;
         else
            cz = dz / 200.00;

         glColor3f(cx, cy, cz);
         glVertex4d(x, y, z, def_w);
      }
      break;
   }
   glEnd();

   //  Draw axes in white
   glColor3f(1,1,1);
   glBegin(GL_LINES);
      glVertex3d(0,0,0);
      glVertex3d(dim - 5,0,0);
      glVertex3d(0,0,0);
      glVertex3d(0,dim -5,0);
      glVertex3d(0,0,0);
      glVertex3d(0,0,dim -5);
   glEnd();

   //  Label axes
   glRasterPos3d(dim - 5,0,0);
   Print("X");
   glRasterPos3d(0,dim - 5,0);
   Print("Y");
   glRasterPos3d(0,0,dim -5);
   Print("Z");

   //  Display parameters
   glWindowPos2i(5,5);
   Print("View Angle=%d,%d  %s",th,ph,text[mode]);
   if (mode==2)
      Print("  z=%.1f",z);
   else if (mode==4)
      Print("  w=%.1f",def_w);

   //  Flush and swap
   glFlush();
   glutSwapBuffers();
}
コード例 #19
0
ファイル: ex8.c プロジェクト: abgordon/CSCI4229
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=1.5;  //  Length of axes
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Set view angle
   glRotatef(ph,1,0,0);
   glRotatef(th,0,1,0);
   //  Decide what to draw
   switch (mode)
   {
      //  Draw cubes
      case 0:
         cube(0,0,0 , 0.3,0.3,0.3 , 0);
         cube(1,0,0 , 0.2,0.2,0.2 , 45);
         cube(0,1,0 , 0.4,0.4,0.2 , 90);
         break;
      //  Draw spheres
      case 1:
         sphere1(0,0,0 , 0.4);
         sphere1(1,0,0 , 0.2);
         sphere2(0,1,0 , 0.2);
         break;
      //  Line airplane
      case 2:
         PolyPlane(GL_LINE_LOOP , 0,0,0);
         break;
      //  Polygon airplane
      case 3:
         PolyPlane(GL_POLYGON , 0,0,0);
         break;
      //  Three flat airplanes
      case 4:
         FlatPlane( 0.0, 0.0, 0.0);
         FlatPlane(-0.5, 0.5,-0.5);
         FlatPlane(-0.5,-0.5,-0.5);
         break;
      // Three solid airplanes
      case 5:
         SolidPlane( 0, 0, 0 , 1,0,0 , 0, 1,0);
         SolidPlane(-1, 1, 0 ,-1,0,0 , 0,-1,0);
         SolidPlane(-1,-1, 0 ,-1,0,0 , 0, 1,0);
         break;
      // Mix of objects
      case 6:
         //  Cube
         cube(-1,0,0 , 0.3,0.3,0.3 , 3*zh);
         //  Ball
         sphere1(0,0,0 , 0.3);
         //  Solid Airplane
         SolidPlane(Cos(zh),Sin(zh), 0 ,-Sin(zh),Cos(zh),0 , Cos(4*zh),0,Sin(4*zh));
         //  Utah Teapot
         glPushMatrix();
         glTranslatef(0,0,-1);
         glRotatef(zh,0,1,0);
         glColor3f(Cos(zh)*Cos(zh),0,Sin(zh)*Sin(zh));
         glutSolidTeapot(0.5);
         glPopMatrix();
         break;
   }
   //  White
   glColor3f(1,1,1);
   //  Draw axes
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Five pixels from the lower left corner of the window
   glWindowPos2i(5,5);
   //  Print the text string
   Print("Angle=%d,%d",th,ph);
   //  Render the scene
   glFlush();
   //  Make the rendered scene visible
   glutSwapBuffers();
}
コード例 #20
0
ファイル: ex26.cpp プロジェクト: jchan1e/graphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.5;  //  Length of axes
   double Ex = -2*dim*Sin(th)*Cos(ph);
   double Ey = +2*dim        *Sin(ph);
   double Ez = +2*dim*Cos(th)*Cos(ph);

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);

   //  Integrate
   Step();

   //  Set shader
   glUseProgram(shader);
   int id = glGetUniformLocation(shader,"star");
   if (id>=0) glUniform1i(id,0);
   id = glGetUniformLocation(shader,"size");
   if (id>=0) glUniform1f(id,0.1);
   glBlendFunc(GL_ONE,GL_ONE);
   glEnable(GL_BLEND);

   //  Draw stars using vertex arrays
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_COLOR_ARRAY);
   glVertexPointer(3,GL_FLOAT,sizeof(float3),pos[src]);
   glColorPointer(3,GL_FLOAT,sizeof(Color),col);
   //  Draw all stars
   glDrawArrays(GL_POINTS,0,N);
   //  Disable vertex arrays
   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_COLOR_ARRAY);

   //  Unset shader
   glUseProgram(0);
   glDisable(GL_BLEND);

   //  Draw axes
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("FPS=%d Angle=%d,%d Mode=%s",
      FramesPerSecond(),th,ph,text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #21
0
ファイル: fbo-integer.c プロジェクト: RAOF/piglit
/** \return GL_TRUE for pass, GL_FALSE for fail */
static GLboolean
test_fbo(const struct format_info *info)
{
   const int max = get_max_val(info);
   const int comps = num_components(info->BaseFormat);
   const GLenum type = get_datatype(info);
   GLint f;
   GLuint fbo, texObj;
   GLenum status;
   GLboolean intMode;
   GLint buf;

   if (0)
      fprintf(stderr, "============ Testing format = %s ========\n", info->Name);

   /* Create texture */
   glGenTextures(1, &texObj);
   glBindTexture(GL_TEXTURE_2D, texObj);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

   glTexImage2D(GL_TEXTURE_2D, 0, info->IntFormat, TexWidth, TexHeight, 0,
                info->BaseFormat, type, NULL);

   if (check_error(__FILE__, __LINE__))
      return GL_FALSE;

   glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &f);
   assert(f == info->IntFormat);


   /* Create FBO to render to texture */
   glGenFramebuffers(1, &fbo);
   glBindFramebuffer(GL_FRAMEBUFFER, fbo);
   glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                          GL_TEXTURE_2D, texObj, 0);

   if (check_error(__FILE__, __LINE__))
      return GL_FALSE;

   status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
   if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
      fprintf(stderr, "%s: failure: framebuffer incomplete.\n", TestName);
      return GL_FALSE;
   }


   glGetBooleanv(GL_RGBA_INTEGER_MODE_EXT, &intMode);
   if (check_error(__FILE__, __LINE__))
      return GL_FALSE;
   if (!intMode) {
      fprintf(stderr, "%s: GL_RGBA_INTEGER_MODE_EXT return GL_FALSE\n",
              TestName);
      return GL_FALSE;
   }

   glGetIntegerv(GL_READ_BUFFER, &buf);
   assert(buf == GL_COLOR_ATTACHMENT0_EXT);
   glGetIntegerv(GL_DRAW_BUFFER, &buf);
   assert(buf == GL_COLOR_ATTACHMENT0_EXT);


   /* test clearing */
   if (1) {
      static const GLint clr[4] = { 8, 7, 6, 5 };
      GLint pix[4], i;

      glClearColorIiEXT(clr[0], clr[1], clr[2], clr[3]);
      glClear(GL_COLOR_BUFFER_BIT);

      glReadPixels(5, 5, 1, 1, GL_RGBA_INTEGER_EXT, GL_INT, pix);

      for (i = 0; i < comps; i++) {
         if (pix[i] != clr[i]) {
            fprintf(stderr, "%s: glClear failed\n", TestName);
            fprintf(stderr, "  Texture format = %s\n", info->Name);
            fprintf(stderr, "  Expected %d, %d, %d, %d\n",
                    clr[0], clr[1], clr[2], clr[3]);
            fprintf(stderr, "  Found %d, %d, %d, %d\n",
                    pix[0], pix[1], pix[2], pix[3]);
            return GL_FALSE;
         }
      }
   }


   /* Do glDraw/ReadPixels test */
   if (1) {
#define W 15
#define H 10
      GLint image[H * W * 4], readback[H * W * 4];
      GLint i;

      if (info->Signed) {
         for (i = 0; i < W * H * 4; i++) {
            image[i] = (i - 10) % max;
            assert(image[i] < max);
         }
      }
      else {
         for (i = 0; i < W * H * 4; i++) {
            image[i] = (i + 3) % max;
            assert(image[i] < max);
         }
      }

      glUseProgram(PassthroughProgram);
      if(0)glUseProgram(SimpleProgram);

      glWindowPos2i(1, 1);
      glDrawPixels(W, H, GL_RGBA_INTEGER_EXT, GL_INT, image);

      if (check_error(__FILE__, __LINE__))
         return GL_FALSE;

      glReadPixels(1, 1, W, H, GL_RGBA_INTEGER_EXT, GL_INT, readback);

      if (check_error(__FILE__, __LINE__))
         return GL_FALSE;

      for (i = 0; i < W * H * 4; i++) {
         if (readback[i] != image[i]) {
            if (comps == 3 && i % 4 == 3 && readback[i] == 1)
               continue; /* alpha = 1 if base format == RGB */

            fprintf(stderr,
                 "%s: glDraw/ReadPixels failed at %d.  Expected %d, found %d\n",
                    TestName, i, image[i], readback[i]);
            fprintf(stderr, "Texture format = %s\n", info->Name);
            assert(0);
            return GL_FALSE;
         }
      }
#undef W
#undef H
   }

   /* Do rendering test */
   if (1) {
      GLint value[4], result[4], loc, w = piglit_width, h = piglit_height;
      GLint error = 1; /* XXX fix */

      /* choose random value/color for polygon */
      value[0] = rand() % 100;
      value[1] = rand() % 100;
      value[2] = rand() % 100;
      value[3] = rand() % 100;

      glUseProgram(SimpleProgram);
      check_error(__FILE__, __LINE__);

      loc = glGetUniformLocation(SimpleProgram, "value");
      assert(loc >= 0);
      glUniform4iv(loc, 1, value);
      check_error(__FILE__, __LINE__);

#if 0 /* allow testing on mesa until this is implemented */
      loc = glGetFragDataLocationEXT(SimpleProgram, "out_color");
      assert(loc >= 0);
#endif

      glBegin(GL_POLYGON);
      glVertex2f(0, 0);
      glVertex2f(w, 0);
      glVertex2f(w, h);
      glVertex2f(0, h);
      glEnd();
      check_error(__FILE__, __LINE__);

      glReadPixels(w/2, h/2, 1, 1, GL_RGBA_INTEGER, GL_INT, result);
      check_error(__FILE__, __LINE__);

      if (info->BaseFormat == GL_RGB_INTEGER_EXT) {
         value[3] = 1;
      }

      if (abs(result[0] - value[0]) > error ||
          abs(result[1] - value[1]) > error ||
          abs(result[2] - value[2]) > error ||
          abs(result[3] - value[3]) > error) {
         fprintf(stderr, "%s: failure with format %s:\n", TestName, info->Name);
         fprintf(stderr, "  input value = %d, %d, %d, %d\n",
                 value[0], value[1], value[2], value[3]);
         fprintf(stderr, "  result color = %d, %d, %d, %d\n",
                 result[0], result[1], result[2], result[3]);
         return GL_FALSE;
      }
   }

   piglit_present_results();

   glDeleteTextures(1, &texObj);
   glDeleteFramebuffers(1, &fbo);

   return GL_TRUE;
}
コード例 #22
0
ファイル: ex7.c プロジェクト: abgordon/CSCI4229
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=1.5;  //  Length of axes
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

   //  Undo previous transformations
   glLoadIdentity();
   //  Set view angle
   glRotatef(ph,1,0,0);
   glRotatef(th,0,1,0);

   //  Enable Z-buffering
   if (mode==2 || mode==3)
      glEnable(GL_DEPTH_TEST);
   else
      glDisable(GL_DEPTH_TEST);
   //  Enable face culling
   if (mode!=2)
      glEnable(GL_CULL_FACE);
   else
      glDisable(GL_CULL_FACE);

   //  Draw a single cube
   if (n==1)
      cube(0,0,0 , 1,1,1 , 0);
   //  Multiple cubes - fixed order
   else if (mode != 1)
   {
      int k;
      for (k=0;k<n;k++)
         cube(Cube[k].x,Cube[k].y,Cube[k].z , Cube[k].dx,Cube[k].dy,Cube[k].dz , Cube[k].th);
   }
   //  Multiple cubes - Z-sorted
   else
   {
      int i,k;
      cube_t* cubep[Nk];
      //  Calculate projection Z component
      for (k=0;k<n;k++)
         Cube[k].Zp = Zp(Cube[k].x,Cube[k].y,Cube[k].z);
      //  Initialize Z pointer array
      for (k=0;k<n;k++)
         cubep[k] = Cube+k;
      //  Sort cubes on Z ascending using bubble sort
      for (k=0;k<n-1;k++)
         for (i=k+1;i<n;i++)
            if (cubep[k]->Zp > cubep[i]->Zp)
            {
               cube_t* t = cubep[k];
               cubep[k]  = cubep[i];
               cubep[i]  = t;
            }
      //  Draw cubes
      for (k=0;k<n;k++)
         cube(cubep[k]->x,cubep[k]->y,cubep[k]->z , cubep[k]->dx,cubep[k]->dy,cubep[k]->dz , cubep[k]->th);
      //  Print sequence
      glColor3f(1,1,1);
      glWindowPos2i(5,25);
      Print("Z order");
      for (k=0;k<n;k++)
         Print(" %d=%.3f",cubep[k]->id,cubep[k]->Zp);
   }
   //  White
   glColor3f(1,1,1);
   //  Draw axes
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Five pixels from the lower left corner of the window
   glWindowPos2i(5,5);
   //  Print the text string
   Print("Angle=%d,%d  Hidden=%s",th,ph,text[mode]);
   if (rev) Print(" Reverse");
   //  Render the scene
   glFlush();
   //  Make the rendered scene visible
   glutSwapBuffers();
}
コード例 #23
0
ファイル: projection.c プロジェクト: qubick/ComputerGraphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=1.5;  //  Length of axes
   int i = 0;
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();

   if (view){
   	double Ex = -2*dim*Sin(th)*Cos(ph);
	double Ey = +2*dim		  *Sin(ph);
	double Ez = +2*dim*Cos(th)*Cos(ph);
	gluLookAt(Ex, Ey, Ez, 0,0,0,	0,Cos(ph),0);
   }
   else {
   //  Set view angle
   	glRotatef(ph,1,0,0);
   	glRotatef(th,0,1,0);
   }
   //  Decide what to draw
   switch (mode)
   {
      //  Draw cubes
      case 2:
         truck(0,0,0 , 0.2,0.2,0.2 , 0);
         truck(1,0,2 , 0.1,0.1,0.1 , 30);
         truck(0,1,0 , 0.4,0.3,0.2 , 90);
         break;
      //  Draw spheres
      case 1:
         taxi(0,0,0 , 0.2,0.2,0.2 , 0);
         taxi(0,0,0 , 0.2,0.2,0.2 , 0);
         taxi(0,0,0 , 0.2,0.2,0.2 , 0);
        
		 //tree(0,0,0,1);
		 break;
      case 0:
	  	//	printf("ph: %f\t th: %f\t zh:%f\n", ph, th, zh);
		//road
		glBegin(GL_QUADS);
		 glColor3f(0.3, 0.3, 0.3);
		 glVertex3f(-100, -.1,-1);
		 glVertex3f(100, -.1, -1);
		 glVertex3f(100, -.1, 3);
		 glVertex3f(-100, -.1, 3);

		//stripes
		glColor3f(1,1,0);
		for(i=-10; i<100; i++){
			glVertex3f(i,		-.1+offset, 1);
			glVertex3f(i+.7,	-.1+offset, 1);
			glVertex3f(i+.7,	-.1+offset, 1.1);
			glVertex3f(i,		-.1+offset, 1.1);
		}
		glEnd();

		 truck((zh-120)*0.1,.1,1.5,	.15,.15,.15, 180);
		 taxi(-(zh-120)*0.15,0,.5, 		.1,.1,.1, 0);

		 truck(2-(zh-120)*0.1,.1,.1,	.1,.1,.1, 0);
		 taxi(-5+(zh-100)*0.07,.2,1.5, .1,.1,.1, 180);
	
		sleep(10000); 
		truck(10-(zh-120)*0.15,.1,.5,	.1,.1,.1, 0);
		// taxi(-2-(zh-120)*0.05,0,1,		.1,.1,.1, 0);
		 break;
      case 3:
         //  Cube
         truck(-1,0,0 , 0.2,0.2,0.2 , 3*zh);
         //  Ball
         //vaxisphere2(0,0,0 , 0.3);
         
		 taxi(Cos(zh), Sin(zh), Cos(zh)*Sin(zh), .1,.1,.1,1 );
         break;
   }
   //  White
   glColor3f(1,1,1);
   //  Draw axes
   if (mode != 0)
   	
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Five pixels from the lower left corner of the window
   glWindowPos2i(5,5);
   //  Print the text string
   Print("Angle=%d,%d",th,ph);
   //  Render the scene
   glFlush();
   //  Make the rendered scene visible
   glutSwapBuffers();
}
コード例 #24
0
ファイル: ex32.c プロジェクト: spoonertb/turbineSim
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   int i,j;
   const double len=2.0;  //  Length of axes
   //  Light position and colors
   float Ambient[]  = {0.3,0.3,0.3,1.0};
   float Diffuse[]  = {1.0,1.0,1.0,1.0};
   float Position[] = {Cos(zh),Ylight,Sin(zh),1.0};

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Draw light position as sphere (still no lighting here)
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Position[0],Position[1],Position[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();
   //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  glColor sets ambient and diffuse color materials
   glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
   glEnable(GL_COLOR_MATERIAL);
   //  Enable light 0
   glEnable(GL_LIGHT0);
   //  Set ambient, diffuse, specular components and position of light 0
   glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
   glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
   glLightfv(GL_LIGHT0,GL_POSITION,Position);

   //  Draw floor
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_POLYGON_OFFSET_FILL);
   glPolygonOffset(1,1);
   glColor3f(1,1,1);
   glNormal3f(0,1,0);
   for (j=-Dfloor;j<Dfloor;j++)
   {
      glBegin(GL_QUAD_STRIP);
      for (i=-Dfloor;i<=Dfloor;i++)
      {
         glTexCoord2f(i,j); glVertex3f(i,Yfloor,j);
         glTexCoord2f(i,j+1); glVertex3f(i,Yfloor,j+1);
      }
      glEnd();
   }
   glDisable(GL_POLYGON_OFFSET_FILL);
   glDisable(GL_TEXTURE_2D);

   //  Draw scene
   glColor3f(1,1,0);
   scene();

   //  Save what is glEnabled
   glPushAttrib(GL_ENABLE_BIT);
   //  Draw shadow
   switch (mode)
   {
      //  No shadow
      case 0:
         break;
      //  Draw flattened scene
      case 1:
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Transformation with lighting disabled
      case 2:
         glDisable(GL_LIGHTING);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Set shadow color
      case 3:
         glDisable(GL_LIGHTING);
         glColor3f(0.3,0.3,0.3);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Blended shadows
      case 4:
         glDisable(GL_LIGHTING);
         //  Blended color
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.4);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Blended shadows Z-buffer masked
      case 5:
         glDisable(GL_LIGHTING);
         //  Draw blended 
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.4);
         //  Make Z-buffer read-only
         glDepthMask(0);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         //  Make Z-buffer read-write
         glDepthMask(1);
         break;
      //  Blended with stencil buffer
      case 6:
         glDisable(GL_LIGHTING);
         //  Enable stencil operations
         glEnable(GL_STENCIL_TEST);

         /*
          *  Step 1:  Set stencil buffer to 1 where there are shadows
          */
         //  Existing value of stencil buffer doesn't matter
         glStencilFunc(GL_ALWAYS,1,0xFFFFFFFF);
         //  Set the value to 1 (REF=1 in StencilFunc)
         //  only if Z-buffer would allow write
         glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
         //  Make Z-buffer and color buffer read-only
         glDepthMask(0);
         glColorMask(0,0,0,0);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         //  Make Z-buffer and color buffer read-write
         glDepthMask(1);
         glColorMask(1,1,1,1);

         /*
          *  Step 2:  Draw shadow masked by stencil buffer
          */
         //  Set the stencil test draw where stencil buffer is > 0
         glStencilFunc(GL_LESS,0,0xFFFFFFFF);
         //  Make the stencil buffer read-only
         glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
         //  Enable blending
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.5);
         //  Draw the shadow over the entire floor
         glBegin(GL_QUADS);
         glVertex3f(-Dfloor,Yfloor,-Dfloor);
         glVertex3f(+Dfloor,Yfloor,-Dfloor);
         glVertex3f(+Dfloor,Yfloor,+Dfloor);
         glVertex3f(-Dfloor,Yfloor,+Dfloor);
         glEnd();
         break;
      default:
         break;
   }    
   //  Undo glEnables
   glPopAttrib();
   
   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f Projection=%s Light Elevation=%.1f",
     th,ph,dim,proj?"Perpective":"Orthogonal",Ylight);
   glWindowPos2i(5,25);
   Print(text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #25
0
ファイル: main.c プロジェクト: ElDeveloper/computer_graphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display(){
	const double len=4.5;  //  Length of axes

	float cylinder_color_a[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
	float cylinder_color_b[3][3] = {{252.0/255.0, 141.0/255.0, 89/255.0},
		{1, 1, 191/255.0}, {145/255.0, 207/255.0, 96/255.0}};


	//  Erase the window and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	//  Enable Z-buffering in OpenGL
	glEnable(GL_DEPTH_TEST);
	//  Undo previous transformations
	glLoadIdentity();
	//  Set view angle
	glRotatef(ph,1,0,0);
	glRotatef(th,0,1,0);

	// cylinder one
	glPushMatrix();
	glRotatef(cylinder_rotation, 1, 0, 0);
	glRotatef(cylinder_rotation/0.5, 0, 1, 0);
	glScaled(0.9, 0.78, 0.4);
	draw_cylinder(0, 0, 0, 500, cylinder_color_a);
	glPopMatrix();

	// cylinder two
	glPushMatrix();
	glScaled(0.5, 0.5, 0.5);
	draw_cylinder(2, 2, 2, 500, cylinder_color_b);
	glPopMatrix();

	// house one
	glPushMatrix();
	draw_house(-2, -2, -2, cylinder_color_b);
	glPopMatrix();

	// house two
	glPushMatrix();
	draw_house(0.5, -.8, -2, cylinder_color_b);
	glPopMatrix();


	glPushMatrix();
	draw_house(house_x, house_y, house_z, cylinder_color_a);
	glPopMatrix();

	//  White
	glColor3f(1,1,1);
	//  Draw axes
	if (axes)
	{
		glBegin(GL_LINES);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(len,0.0,0.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(0.0,len,0.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(0.0,0.0,len);
		glEnd();
		//  Label axes
		glRasterPos3d(len,0.0,0.0);
		Print("X");
		glRasterPos3d(0.0,len,0.0);
		Print("Y");
		glRasterPos3d(0.0,0.0,len);
		Print("Z");
	}
	//  Five pixels from the lower left corner of the window
	glWindowPos2i(5,5);
	//  Print the text string
	Print("Angle=%d,%d",th,ph);
	//  Render the scene
	glFlush();
	//  Make the rendered scene visible
	glutSwapBuffers();
}
コード例 #26
0
ファイル: ex35.c プロジェクト: jchan1e/graphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   //  Length of axes
   const double len=2.0;
   //  Eye position
   float Ex = -2*dim*Sin(th)*Cos(ph);
   float Ey = +2*dim        *Sin(ph);
   float Ez = +2*dim*Cos(th)*Cos(ph);
   //  Light position
   Lpos[0] = 2*Cos(zh);
   Lpos[1] = Ylight;
   Lpos[2] = 2*Sin(zh);
   Lpos[3] = 1;

   //  Erase the window and the depth and stencil buffers
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);

   //  Set perspective
   glLoadIdentity();
   gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);

   //  Draw light position as sphere (still no lighting here)
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Lpos[0],Lpos[1],Lpos[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();

   //  Draw the scene with shadows
   DrawSceneWithShadows();

   //  Draw axes (white)
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }

   //  Display parameters
   glWindowPos2i(5,5);
   Print("Ylight=%.1f Angle=%d,%d,%d  Dim=%.1f Slices=%d Mode=%s Inf=%s Stencil=%d",
     Ylight,th,ph,zh,dim,n,text[mode],inf?"Fixed":"Calculated",depth);

   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #27
0
ファイル: hw3.c プロジェクト: mazdeh/pyramids-lightntexture
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2000;  //  Length of axes

   float Position[] = {X+700*Cos(Th)-400,Y+50*Sin(Th),300+Z+1200*Sin(Th),1-inf};
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (mode)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }
   glShadeModel(smooth?GL_SMOOTH:GL_FLAT);
   //  Light switch
   if (light)
   {
      //  Translate intensity to color vectors
      float Ambient[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
      float Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
      float Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};
      //  Spotlight color and direction
      float yellow[] = {1.0,1.0,0.0,1.0};
      float Direction[] = {Cos(Th)*Sin(Ph),Sin(Th)*Sin(Ph),-Cos(Ph),0};
      //  Draw light position as ball (still no lighting here)
      ball(Position[0],Position[1],Position[2] , 10);
      //  OpenGL should normalize normal vectors
      glEnable(GL_NORMALIZE);
      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  Location of viewer for specular calculations
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
      //  Two sided mode
      glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,side);
      //  glColor sets ambient and diffuse color materials
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Set specular colors
      glMaterialfv(GL_FRONT,GL_SPECULAR,yellow);
      glMaterialfv(GL_FRONT,GL_SHININESS,shinyvec);
      //  Enable light 0
      glEnable(GL_LIGHT0);
      //  Set ambient, diffuse, specular components and position of light 0
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position);
      //  Set spotlight parameters
      glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,Direction);
      glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,sco);
      glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,Exp);
      //  Set attenuation
      glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION ,at0/100.0);
      glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION   ,at1/100.0);
      glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,at2/100.0);
   }
   else
      glDisable(GL_LIGHTING);
   //  Enable textures
   if (ntex)
      glEnable(GL_TEXTURE_2D);
   else
      glDisable(GL_TEXTURE_2D);
   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
   


   // drawing the 3 great pyramids of Egypt
      pyramid(0,0,0,      230.124,138.684,230.124, 0);
       
      pyramid(300,0,115,  30,30,30, 0);
      pyramid(300,0,20,  30,30,30, 0);
      pyramid(300,0,-75,  30,30,30, 0);

      pyramid(-500,0,600, 230,136,230, 0);

      cube(-100, 0, 600, 115, 30, 50, 0);
      // sphere2(-20, 90, 600, 30);

      pyramid(-900,0,990, 103.327,60.96,103.327, 0);
      
      // drawig the queens' pyramids
      pyramid(-900,0, 1200, 30, 30, 30, 0);
      pyramid(-1000,0, 1200, 30, 30, 30, 0);
      pyramid(-800,0, 1200, 30, 30, 30, 0);
   


   glDisable(GL_TEXTURE_2D);
   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f Projection=%s Light=%s",
     th,ph,dim,mode?"Orthogonal":"Perpective",light?"On":"Off");
   if (light)
   {
      glWindowPos2i(5,65);
      Print("Cutoff=%.0f Exponent=%.1f Direction=%d,%d Attenuation=%.2f,%.2f,%.2f",sco,Exp,Th,Ph,at0/100.0,at1/100.0,at2/100.0);
      glWindowPos2i(5,45);
      Print("Model=%s LocalViewer=%s TwoSided=%s Position=%.1f,%.1f,%.1f,%.1f",smooth?"Smooth":"Flat",local?"On":"Off",side?"On":"Off",Position[0],Position[1],Position[2],Position[3]);
      glWindowPos2i(5,25);
      Print("Ambient=%d  Diffuse=%d Specular=%d Emission=%d Shininess=%.0f",ambient,diffuse,specular,emission,shinyvec[0]);
   }
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #28
0
ファイル: light.c プロジェクト: qubick/ComputerGraphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.0;  //  Length of axes
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);

   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (mode)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Flat or smooth shading
   glShadeModel(smooth ? GL_SMOOTH : GL_FLAT);

   //  Light switch
   if (light)
   {
        //  Translate intensity to color vectors
        float Ambient[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
        float Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
        float Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};
        //  Light position
        float Position[]  = {distance*Cos(zh),ylight,distance*Sin(zh),1.0};
        //  Draw light position as ball (still no lighting here)
        glColor3f(1,1,1);
        ball(Position[0],Position[1],Position[2] , 0.1);
        //  OpenGL should normalize normal vectors
        glEnable(GL_NORMALIZE);
        //  Enable lighting
        glEnable(GL_LIGHTING);
        //  Location of viewer for specular calculations
        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
        //  glColor sets ambient and diffuse color materials
        glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
        //  Enable light 0
        glEnable(GL_LIGHT0);
        //  Set ambient, diffuse, specular components and position of light 0
        glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
        glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
        glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
        glLightfv(GL_LIGHT0,GL_POSITION,Position);
   }
   else
     glDisable(GL_LIGHTING);

   //  Draw scene
   //cube(+1,0,0 , 0.5,0.5,0.5 , 0);
   //ball(-1,0,0 , 0.5);

	street();
   truck((zh-12)*0.1,.1,1.5,	.15,.15,.15, 180);
	truck(2-(zh-120)*0.1,.1,.1,    .1,.1,.1, 0);
	
	//taxi(-5+(zh-100)*0.07,.2,1.5, .1,.1,.1, 180);
	
	sleep(10000);
	truck(10-(zh-120)*0.15,.1,.5,   .1,.1,.1, 0);

	//  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }

   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f FOV=%d Projection=%s Light=%s",
     th,ph,dim,fov,mode?"Perpective":"Orthogonal",light?"On":"Off");
   if (light)
   {
      glWindowPos2i(5,45);
      Print("Model=%s LocalViewer=%s Distance=%d Elevation=%.1f",smooth?"Smooth":"Flat",local?"On":"Off",distance,ylight);
      glWindowPos2i(5,25);
      Print("Ambient=%d  Diffuse=%d Specular=%d Emission=%d Shininess=%.0f",ambient,diffuse,specular,emission,shinyvec[0]);
   }

   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #29
0
ファイル: shadow.c プロジェクト: HackUniverse/ptam-gr
void render(void)
{
static GLint iFrames = 0;
static GLfloat fps = 0.0f, DeltaT;
static char cBuffer[64];
struct timeval tv;
GLuint model_id;

	// Update timer
	gettimeofday(&tv, NULL);
	etime = (double)tv.tv_sec + tv.tv_usec / 1000000.0f;

	dt = etime - t0;
	t0 = etime;

	/*
	 * Make the shadow pass
	 *
	 */

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, FBO );

	glPushMatrix();

		//Compute light position
		sinE = sinf(eLit);
		cosE = cosf(eLit);
		sinA = sinf(aLit);
		cosA = cosf(aLit);

		lightPos[0] = lightRadius * cosE * sinA;
		lightPos[1] = lightRadius * sinE;
		lightPos[2] = lightRadius * cosE * cosA;
		lightPos[3] = 1.0f;

		//Set light position
		glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

		//Set up camera to light location
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective( 70.0f, 1.0f, 75.0f, 350.0f );
		glGetDoublev(GL_PROJECTION_MATRIX, lightProjection );
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt( lightPos[0], lightPos[1], lightPos[2],
			0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f );
		glGetDoublev(GL_MODELVIEW_MATRIX, lightModelview );
		glViewport( 0, 0, shadow_sz, shadow_sz );

		glClear(GL_DEPTH_BUFFER_BIT);

		glEnable(GL_POLYGON_OFFSET_FILL);
		glShadeModel(GL_FLAT);

		//Rotate scene, if required
		glRotatef(xRot, 1.0f, 0.0f, 0.0f);
		glRotatef(yRot, 0.0f, 1.0f, 0.0f);

		//Disable shaders
		glUseProgramObjectARB(0);
		glDisable(GL_VERTEX_PROGRAM_ARB);
		glDisable(GL_FRAGMENT_PROGRAM_ARB);

		// Draw dynamic objects
		for (model_id = 0; model_id < NUM_MODELS; model_id++ )
		{
			//Update the kinematic's state
			UpdateMD2(md2_model[model_id], dt);
	
			//Animate the MD2 models
			AnimateMD2(md2_model[model_id], dt);
			
			//Draw the geometry
			glPushMatrix();
				glTranslatef(	md2_model[model_id]->position.x,
						md2_model[model_id]->position.y,
						md2_model[model_id]->position.z );
				glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f );
				DrawMD2(md2_model[model_id]);
			glPopMatrix();
		}

	glPopMatrix();

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );

	/*
	 * And now the normal pass
	 *
	 */

	//Back to normal settings
	glDisable(GL_POLYGON_OFFSET_FILL);
	glShadeModel(GL_SMOOTH);
	change_size( width, height );

	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();

		//Set up camera location and parameters
		setup_camera((float)dt);

		//Retrieve modelview matrix and invert it
		glGetDoublev(GL_MODELVIEW_MATRIX, cameraModelview );
		FastInvert4( cameraModelview, cameraModelviewInverse );

		//Set up depth texture
		glActiveTexture(GL_TEXTURE2);
		glBindTexture(GL_TEXTURE_2D, shadow_tx);

		//Set up texture matrix for shadow map projection
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		glTranslatef(0.5f, 0.5f, 0.5f);
		glScalef(0.5f, 0.5f, 0.5f);
		glMultMatrixd(lightProjection);
		glMultMatrixd(lightModelview);
		glMultMatrixd(cameraModelviewInverse);
		glMatrixMode(GL_MODELVIEW);

		//Rotate scene
		glRotatef(xRot, 1.0f, 0.0f, 0.0f);
		glRotatef(yRot, 0.0f, 1.0f, 0.0f);

		//Re-enable shaders
		glEnable(GL_VERTEX_PROGRAM_ARB);
		glEnable(GL_FRAGMENT_PROGRAM_ARB);

		if (GLSLshader)
			glUseProgramObjectARB(progObj);
		else
			glUseProgramObjectARB(0);

		//Floor

		//Color
		glColor3f(0.64f, 0.63f, 0.65f);

		//Set textures
		glActiveTexture(GL_TEXTURE0);	//Diffuse map
		glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-2]);

		glActiveTexture(GL_TEXTURE1);	//Normal map
		glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-1]);

		//Set Tangent vector
		glVertexAttrib3fv( tangent, floorT );

		//Set Binormal vector
		glVertexAttrib3fv( binormal, floorB );

		//Set Normal vector
		glNormal3fv( floorN );

		//Call Display List to draw
		glCallList(FList);

		// Draw dynamic objects
		for (model_id = 0; model_id < NUM_MODELS; model_id++ )
		{
			//Set color
			glColor3f(	md2_model[model_id]->color.x,
					md2_model[model_id]->color.y,
					md2_model[model_id]->color.z );
	
			//Set texture
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id]);
			glActiveTexture(GL_TEXTURE1);
			glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id+1]);
	
			//Draw the geometry
			glPushMatrix();
				glTranslatef(	md2_model[model_id]->position.x,
						md2_model[model_id]->position.y,
						md2_model[model_id]->position.z );
				glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f );
				DrawMD2(md2_model[model_id]);
			glPopMatrix();
		}

	glPopMatrix();

	iFrames++;
	DeltaT = (GLfloat)(etime-t1);
	if( DeltaT >= Timed )
	{
		fps = (GLfloat)(iFrames)/DeltaT;
		fps_count++;
		fps_mean = ((fps_count - 1.0f) * fps_mean + fps ) / fps_count;

		iFrames = 0;
		t1 = etime;

		sprintf(cBuffer,"FPS: %.1f Mean FPS: %.1f Poly Scale: %.1f Bias: %.1f", fps, fps_mean, scalePoly, biasPoly);
	}
	if (print_fps)
	{
		if (windowpos)
		{
			glColor3f(1.0f, 1.0f, 1.0f);
			glPushAttrib(GL_LIST_BIT);
				glListBase(fps_font - ' ');
				glWindowPos2i(0,2);
				glCallLists(strlen(cBuffer), GL_UNSIGNED_BYTE, cBuffer);
			glPopAttrib();
		}
		if( iFrames == 0 )
			printf("FPS: %.1f Mean FPS: %.1f\n", fps, fps_mean);
	}
	lCam = 0.0f;
	vCam = 0.0f;
	dCam = 0.0f;
}
コード例 #30
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   //  Length of axes
   const double len=1.2;
   //  Eye position
   double Ex = -2*dim*Cos(ph);
   double Ey = +2*dim*Sin(ph);
   double Ez = 0;
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Set perspective
   glLoadIdentity();
   gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   //  Draw scene
   glEnable(GL_DEPTH_TEST);
   //  Rotate Z up
   glRotated(-90,1,0,0);

   /*
    * Draw solar system
    */
   if (mode<0)
   {
      glRotated(th,0,0,1);  //  View angle
      SolarSystem();
   }
   /*
    *  Draw planet
    */
   else
   {
      glRotated(th,1,0,0);  // Declination
      glRotated(zh,0,0,1);  // Spin around axes
      DrawPlanet(mode);
   }

   /*
    *  Draw axes - no textures from here
    */
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f Object=%s",th,ph,2*dim,mode<0?"Solar System":planet[mode].name);
   if (mode<0) Print(" Magnification %d Year %.1f",mag,2000+day/365.25);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}