Esempio n. 1
0
void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   glFlush();
}
void
Display( )
{
    if( DebugOn != 0 )
    {
        fprintf( stderr, "Display\n" );
    }


    // set which window we want to do the graphics into:

    glutSetWindow( MainWindow );


    // erase the background:

    glDrawBuffer( GL_BACK );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glEnable( GL_DEPTH_TEST );


    // specify shading to be flat:

    glShadeModel( GL_FLAT );


    // set the viewport to a square centered in the window:

    GLsizei vx = glutGet( GLUT_WINDOW_WIDTH );
    GLsizei vy = glutGet( GLUT_WINDOW_HEIGHT );
    GLsizei v = vx < vy ? vx : vy;   // minimum dimension
    GLint xl = ( vx - v ) / 2;
    GLint yb = ( vy - v ) / 2;
    glViewport( xl, yb,  v, v );


    // set the viewing volume:
    // remember that the Z clipping  values are actually
    // given as DISTANCES IN FRONT OF THE EYE
    // USE gluOrtho2D( ) IF YOU ARE DOING 2D !

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    if( WhichProjection == ORTHO )
        glOrtho( -3., 3.,     -3., 3.,     0.1, 1000. );
    else
        gluPerspective( 90., 1., 0.1, 1000. );


    // place the objects into the scene:

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity( );


    // set the eye position, look-at position, and up-vector:

    if(view == OUTSIDE){
        //float ypos = cos(Yrot*PI/180) * Scale;
        //float hpos = sin(Yrot*PI/180) * Scale;
        //float xpos = cos(Xrot*PI/180) * Scale;
        //float zpos = sin(Xrot*PI/180) * Scale;
        gluLookAt( 100., 100., 10.,     0., 0., 0.,     0., 1., 0. );
        // rotate the scene:
        glRotatef( (GLfloat)Yrot, 0., 1., 0. );
        glRotatef( (GLfloat)Xrot, 1., 0., 0. );

        // uniformly scale the scene:
        if( Scale < MINSCALE )
            Scale = MINSCALE;
        glScalef( (GLfloat)Scale, (GLfloat)Scale, (GLfloat)Scale );
    }else{
        gluLookAt( -0.4, 1.8, -4.9,     0., 0., -OBJECT_DISTANCE,     0., 1., 0. );
        //glTranslatef( -0.4, 1.8, -4.9 );
        //glRotatef( (GLfloat)Yrot, 0., 1., 0. );
        //glRotatef( (GLfloat)Xrot, 1., 0., 0. );
        //glTranslatef( 0.4, -1.8, 4.9 );
    }


    // set the fog parameters:

    if( DepthCueOn != 0 )
    {
        glFogi( GL_FOG_MODE, FOGMODE );
        glFogfv( GL_FOG_COLOR, FOGCOLOR );
        glFogf( GL_FOG_DENSITY, FOGDENSITY );
        glFogf( GL_FOG_START, FOGSTART );
        glFogf( GL_FOG_END, FOGEND );
        glEnable( GL_FOG );
    }
    else
    {
        glDisable( GL_FOG );
    }


    // possibly draw the axes:

    if( AxesOn != 0 )
    {
        glColor3fv( &Colors[WhichColor][0] );
        glCallList( AxesList );
    }


    // since we are using glScalef( ), be sure normals get unitized:

    glEnable( GL_NORMALIZE );


    // draw the helicopter:

    glCallList( HeliList );

    glColor3f( 1., 0., 1. );

    // draw the big blade

    glPushMatrix();
    glTranslatef(0., 2.9, -2.);
    glRotatef(BladeAngle, 0., 1., 0.);
    glScalef(5., 0., 5.);
    glRotatef(90., 1., 0., 0.);
    glCallList(BladeList);
    glPopMatrix();

    // draw the little blade

    glPushMatrix();
    glTranslatef(.5, 2.5, 9.);
    glRotatef(BladeAngle*3, 1., 0., 0.);
    glScalef(0., 1.5, 1.5);
    glRotatef(90., 0., 1., 0.);
    glCallList(BladeList);
    glPopMatrix();

    // draw the world:
    glCallList( WorldList );

    // draw the object:
    glCallList( ObjectList );

    // swap the double-buffered framebuffers:

    glutSwapBuffers( );

    // be sure the graphics buffer has been sent:
    // note: be sure to use glFlush( ) here, not glFinish( ) !

    glFlush( );
}
void display(void)
{
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    /*glLightfv(GL_LIGHT0,GL_POSITION,lPosition);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mSpecular);
    glMaterialfv(GL_FRONT, GL_SHININESS,mShininess);
    glMaterialfv(GL_FRONT, GL_AMBIENT, cGrey);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, cWhite);
    glColor3f(1.0,1.0,1.0);*/

    float v = rand();
    float a = sin(v);
    float b = cos(v);
    float d = sqrt(float(gridLength)*float(gridLength) + float(gridWidth)*float(gridWidth));		// rand() / RAND_MAX gives a random number between 0 and 1.
    float temp=float(rand()) / float(RAND_MAX);			// therefore c will be a random number between -d/2 and d/2
    float c = temp * d - d/2;
    float p=0.0;
    int temp1=0;
     float x=-(float(gridLength)/2.0),y=-(float(gridWidth)/2.0),z=0.0;
    glPushMatrix();
    glRotatef(rotatex,1.0,0.0,0.0);
    glRotatef(rotatez,0.0,0.0,1.0);
    if(iterations<1000)
    {
        for(x=-(float(gridLength)/2.0);x<(float(gridLength)/2.0);x+=interval)
        {
            for(float y=-(float(gridWidth)/2.0);y<(float(gridWidth)/2.0);y+=interval)
            {
                p=0.0;
                p=faultAlgo(x,y,a,b,c);
                if(p>=-1.57 && p<=1.57)
                {
                    terrainData[temp1][2]+=sin(p)/5; //for cos use cos function here
                    temp1++;
                    //break;
                }
                else if(p<-1.57)
                {
                    terrainData[temp1][2]-=0.4;
                    temp1++;
                    //break;
                }
                else if(p>1.57)
                {
                    terrainData[temp1][2]+=0.4;
                    temp1++;
                    //break;
                }
                else
                    break;

                if(maxHeight<terrainData[temp1][2])
                    maxHeight = terrainData[temp1][2];
                if(minHeight > terrainData[temp1][2])
                    minHeight = terrainData[temp1][2];
            }
        }
        iterations++;
        multiTex.abSetUniformVariable("maxHeight",maxHeight);
        multiTex.abSetUniformVariable("minHeight",minHeight);
        maxHeight=0.0;
        minHeight=0.0;
    }
//	compute();
//	terrainComputeNormals();
    
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D,textures[0]);
    multiTex.abSetUniformTexture("sand",0);

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D,textures[1]);
    multiTex.abSetUniformTexture("grass",1);

    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D,textures[2]);
    multiTex.abSetUniformTexture("ice",2);

    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D,textures[3]);
    multiTex.abSetUniformTexture("rock",3);
    multiTex.abUseProgram();
    temp1=0;
    int temp2=0;
        for(int i=0; i<length-1;i++)
        {	
            glBegin(GL_TRIANGLE_STRIP);
            for(int j=0;j<width;j++)
            {
            
                //temp1++;
        /*		glNormal3f(terrainNormals[3*(i*terrainGridWidth + j)],
                          terrainNormals[3*(i*terrainGridWidth + j)+1],
                          terrainNormals[3*(i*terrainGridWidth + j)+2]);
        */		
            
                glMultiTexCoord2f(GL_TEXTURE0,GLfloat(j)/width,GLfloat(i)/length);
                glMultiTexCoord2f(GL_TEXTURE1,GLfloat(j)/width,GLfloat(i)/length);
                glMultiTexCoord2f(GL_TEXTURE2,GLfloat(j)/width,GLfloat(i)/length);
                glMultiTexCoord2f(GL_TEXTURE3,GLfloat(j)/width,GLfloat(i)/length);
                
                                
                glVertex3f(terrainData[i*(width)+j][0],terrainData[i*(width)+j][1],terrainData[i*(width)+j][2]); 
                
        /*		glNormal3f(terrainNormals[3*((i+1)*terrainGridWidth + j)],
                          terrainNormals[3*((i+1)*terrainGridWidth + j)+1],
                          terrainNormals[3*((i+1)*terrainGridWidth + j)+2]);
        */		
                glMultiTexCoord2f(GL_TEXTURE0,GLfloat(j)/width,GLfloat(i+1)/length);
                glMultiTexCoord2f(GL_TEXTURE1,GLfloat(j)/width,GLfloat(i+1)/length);
                glMultiTexCoord2f(GL_TEXTURE2,GLfloat(j)/width,GLfloat(i+1)/length);
                glMultiTexCoord2f(GL_TEXTURE3,GLfloat(j)/width,GLfloat(i+1)/length);
                
                temp2=(i+1)*(width)+j; //terrainData is a 1D array 
                glVertex3f(terrainData[temp2][0],terrainData[temp2][1],terrainData[temp2][2]);
            }
            glEnd();
        }
        
   glPopMatrix();
   glFlush();
   glutSwapBuffers();
}
Esempio n. 4
0
/*
 * display
 *  a function to display the model
 *  Parameters:
 *  	none
 *  Returns:
 *  	none
 */
void display(void) {
	if (stereo == 0){
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(vangle, 1.0, dnear, dfar);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(myCam.Eye.x, myCam.Eye.y, myCam.Eye.z, myCam.Rotate.x, myCam.Rotate.y, myCam.Rotate.z, myCam.ViewNorm.x, myCam.ViewNorm.y, myCam.ViewNorm.z);
		glColor3f(red, green, blue);
		myWorld.draw_world(); // draw all objects in the world


	}else{
		Point r;
		GLdouble ratio, radians, wd2, ndfl;
		GLdouble left1, right1,top1,bottom1,near1,far1;
		near1 = 0.1;
		far1 = 10000;
		near1 = myCam.focalLength / 5;

		/*Misc Stuff */
		ratio = myCam.screenWidth / (GLdouble)myCam.screenHeight;
		radians = DTOR * myCam.aperture / 2;
		wd2 = near1 * tan(radians);
		ndfl = near1 / myCam.focalLength;
		r.CrossProduct(myCam.ViewVector, myCam.ViewNorm);
		r.Normalize();
		/* Derive the two eye positions */
		r.x *= myCam.eyesep / 2.0;
		r.y *= myCam.eyesep / 2.0;
		r.z *= myCam.eyesep / 2.0;

		r.printPoint();
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		//left eye
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		left1 = - ratio * wd2 - 0.5 * myCam.eyesep * ndfl;
		right1 = ratio * wd2 - 0.5 * myCam.eyesep * ndfl;
		top1 = wd2;
		bottom1 = - wd2;
		glFrustum(left1,right1,bottom1,top1,near1,far1);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(myCam.Eye.x + r.x, myCam.Eye.y + r.y,myCam.Eye.z + r.z,
				  myCam.Rotate.x + r.x,
				  myCam.Rotate.y + r.y,
				  myCam.Rotate.z + r.z,
				  myCam.ViewNorm.x,myCam.ViewNorm.y,myCam.ViewNorm.z);
		glColor3f(0.0, 0.0, 0.4);
		glLineWidth(3.0);
		glScalef(8.0, 8.0, 8.0);
		myWorld.draw_world();
		printf("LEft eye done\n");

		//right eye
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		left1 = - ratio * wd2 + 0.5 * myCam.eyesep * ndfl;
		right1 = ratio * wd2 + 0.5 * myCam.eyesep * ndfl;
		top1 = wd2;
		bottom1 = - wd2;
		glFrustum(left1,right1,bottom1,top1,near1,far1);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(myCam.Eye.x - r.x,myCam.Eye.y - r.y,myCam.Eye.z - r.z,
				  myCam.Rotate.x - r.x,
				  myCam.Rotate.y - r.y,
				  myCam.Rotate.z - r.z,
				  myCam.ViewNorm.x,myCam.ViewNorm.y,myCam.ViewNorm.z);
		glColor3f(0.4, 0.0, 0.0);
		glScalef(8.0, 8.0, 8.0);
		myWorld.draw_world();
	}
	glFlush();
	glutSwapBuffers();
}
Esempio n. 5
0
void Mandelbrot::Draw2Dmandelbrot()
{
    unsigned int h, w;
    float xPoint, yPoint;

    mDisplay->getWindowSize(&w, &h);
    float xRatio = w/2, yRatio = h/2;

    glViewport(0,0,w,h);
    glOrtho(-1.0, 1.0,-1.0,1.0,1.0,1.0);

    while(!mDisplay->IsClosed())
    {
        glClearColor(0.2f , 0.1f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        glBegin(GL_POINTS);
        for(unsigned int y = 0; y < h; y++)
        {
            for(unsigned int x = 0; x < w; x++)
            {

                pr = 1.5 * (x - w / 2) / (0.5 * zoom * w) + moveX;
                pi = (y - h / 2) / (0.5 * zoom * h) + moveY;
                newRe = newIm = oldRe = oldIm = 0;

                unsigned int i;

                for(i = 0; i < numIteration; i++)
                {

                    oldRe = newRe;
                    oldIm = newIm;

                    newRe = oldRe * oldRe - oldIm * oldIm + pr;
                    newIm = 2 * oldRe * oldIm + pi;

                    if((newRe * newRe + newIm * newIm) > 4) break;
                }
                xPoint = (-(1-((float)x/xRatio)));
                yPoint = (-(1-((float)y/yRatio)));
                hsv cVal;
                cVal.h = i%256;
                cVal.s=200;
                cVal.v=255*(i < numIteration);
                rgb color = hsv2rgb(cVal);

                glColor3f(color.r, color.g, color.b);
                glVertex2f(xPoint,yPoint);
                glVertex2f(-xPoint,-yPoint);
                glVertex2f(xPoint,-yPoint);
                glVertex2f(-xPoint,yPoint);
            }
        }
        glEnd();
        glFlush();

        if(is_anim)
        {
            if(numIteration > e)
            {
               numIteration-=5;
            }
            else if(numIteration <= s)
            {
                numIteration += 5;
            }
        }
        if(sv)
        {
            mDisplay->saveScreeshot2("mandelbrot.bmp");
            sv = false;
        }
        mDisplay->swapBuffer();
    }
}
Esempio n. 6
0
void display(void){//Crea la nave
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	GLfloat mat_ambient[] = { 0.7f, 0.0f, 0.0f, 0.5f };
	GLfloat mat_diffuse[] = { 0.1f, 0.5f, 0.8f, 0.5f };
	GLfloat mat_specular[] = { 0.2f, 0.2f, 0.2f, 0.5f };
	GLfloat mat_shininess[] = { 100.0f };

	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	//glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	
    glPushMatrix ();
      
      glutSolidSphere (0.75, 20, 20);

	  glPushMatrix ();
         glTranslatef (0.0, 0.0, 3.0);
		 glutSolidSphere(.65,8,8);
      glPopMatrix ();

	  glRotatef (20.0, 1.0, 0.0, 0.0);

      glPushMatrix ();
         glRotatef (90.0, 0.0, 1.0, 0.0);
		 glTranslatef (0.0,0.0,0.7);
         glutSolidTorus (0.1,0.3, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glRotatef (90.0, 0.0, 1.0, 0.0);
		 glTranslatef (0.0,0.0,-0.7);
         glutSolidTorus (0.1,0.3, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glTranslatef (2.0,0.0,0.0);
		 glScalef (0.2,2.5,1.0);
         glutSolidIcosahedron ();
      glPopMatrix ();

      glPushMatrix ();
         glTranslatef (2.0, 0.0, 0.0); 
		 glScalef(0.3,1.0,1.0);
         glRotatef (-90.0, 0.0, 1.0, 0.0);
         glutSolidCone (1.0, 2.0, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glTranslatef (1.0,0.0, 0.0); 
		 glScalef (1.5,.4,0.6);
         glutSolidCube (1.0);
      glPopMatrix ();
	
 	  glPushMatrix ();
         glTranslatef (-2.0,0.0,0.0);
		 glScalef (0.2,2.5,1.0);
         glutSolidIcosahedron ();
      glPopMatrix ();

      glPushMatrix ();
         glTranslatef (-2.0, 0.0, 0.0); 
		 glScalef(0.3,1.0,1.0);
         glRotatef (90.0, 0.0, 1.0, 0.0);
         glutSolidCone (1.0, 2.0, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glTranslatef (-1.0,0.0, 0.0); 
		 glScalef (1.5,.4,0.6);
         glutSolidCube (1.0);
      glPopMatrix ();

    glPopMatrix ();
    glFlush();
}
Esempio n. 7
0
void Draw() {
	glClear(GL_COLOR_BUFFER_BIT);
	DrawStripes();
	DrawStars();
	glFlush();
}
Esempio n. 8
0
void
display()
{
    //glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
	//glBindTexture(GL_TEXTURE_2D,texName);
	glClear(GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
	glRotatef(xr,1,0,0);
	glRotatef(yr,0,1,0);
	glTranslatef(x,0,z);
	//glLoadIdentity();
	glPushMatrix();
	//glLoadIdentity();
	//glRotatef(45,0,1,0);
	glTranslatef(0,-25,-50);
	//glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,tex1);
	glBegin(GL_POLYGON);
	 glColor3f(0,50,0);
	 glTexCoord2f (0,0);
	 glVertex3f(-100,50,0);
	 glTexCoord2f (0,5);
	 glVertex3f(-100,0,0);
	 glTexCoord2f (15,5);
	 glVertex3f(100,0,0);
	 glTexCoord2f (15,0);
	 glVertex3f(100,50,0);
	glEnd();
	//glDisable(GL_TEXTURE_2D);
	glPopMatrix();
	glPushMatrix();
	//glLoadIdentity();
	glTranslatef(50,-25,0);
	glRotatef(-90,0,1,0);
	glBegin(GL_POLYGON);
	 glColor3f(50,0,0);
	 glTexCoord2f (0,0);
	 glVertex3f(-100,50,0);
	 glTexCoord2f (0,5);
	 glVertex3f(-100,0,0);
	 glTexCoord2f (15,5);
	 glVertex3f(100,0,0);
	 glTexCoord2f (15,0);
	 glVertex3f(100,50,0);
	glEnd();
	glPopMatrix();
	glPushMatrix();
	//glLoadIdentity();
	glTranslatef(0,-25,50);
	glRotatef(180,0,1,0);
	glBegin(GL_POLYGON);
	 glTexCoord2f (0,0);
	 glVertex3f(-100,50,0);
	 glTexCoord2f (0,5);
	 glVertex3f(-100,0,0);
	 glTexCoord2f (15,5);
	 glVertex3f(100,0,0);
	 glTexCoord2f (15,0);
	 glVertex3f(100,50,0);
	glEnd();
	glPopMatrix();
	glPushMatrix();
	//glLoadIdentity();
	glTranslatef(-50,-25,0);
	glRotatef(90,0,1,0);
	glBegin(GL_POLYGON);
	 glTexCoord2f (0,0);
	 glVertex3f(-100,50,0);
	 glTexCoord2f (0,5);
	 glVertex3f(-100,0,0);
	 glTexCoord2f (15,5);
	 glVertex3f(100,0,0);
	 glTexCoord2f (15,0);
	 glVertex3f(100,50,0);
	glEnd();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0,-25,0);
    glRotatef(-90,1,0,0);
	glBindTexture(GL_TEXTURE_2D,tex2);
	glBegin(GL_POLYGON);
     glTexCoord2f (0,0);
	 glVertex3f(-50,50,0);
	 glTexCoord2f (0,1);
	 glVertex3f(-50,-50,0);
	 glTexCoord2f (1,1);
	 glVertex3f(50,-50,0);
	 glTexCoord2f (1,0);
	 glVertex3f(50,50,0);
	glEnd();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0,25,0);
    glRotatef(90,1,0,0);
	//glBindTexture(GL_TEXTURE_2D,tex3);
	glBegin(GL_POLYGON);
     glTexCoord2f (0,0);
	 glVertex3f(-50,50,0);
	 glTexCoord2f (0,10);
	 glVertex3f(-50,-50,0);
	 glTexCoord2f (10,10);
	 glVertex3f(50,-50,0);
	 glTexCoord2f (10,0);
	 glVertex3f(50,50,0);
	glEnd();
	glPopMatrix();
	glPopMatrix();
	glFlush();
	SwapBuffers(hDC);
}
Esempio n. 9
0
void Screen::SwapSurfaces()
{
	glFlush();
}
Esempio n. 10
0
//scroll through our hit buffer and see what we picked with the mouse
void hit_test()
{


//convert to third person view and execute a hit_test
    GLint viewport[4];
    glGetIntegerv (GL_VIEWPORT, viewport);
    GLuint selectBuf[HITBUFSIZE];
    glSelectBuffer (HITBUFSIZE, selectBuf);


    glRenderMode (GL_SELECT);
    glInitNames();
    glPushName(0);

    if(overheadView)
    {
        pickMatrixX = pickMatrixX/20;
        pickMatrixY = (H-pickMatrixY)/3;

        glMatrixMode (GL_PROJECTION);
        glPushMatrix ();
        glLoadIdentity ();
        gluPickMatrix ( pickMatrixX,
                        pickMatrixY,
                        pickMatrixWidth+10,
                        pickMatrixHeight+20,  viewport);
//		glRotatef(shadowx,1,0,0);
//		glRotatef(shadowy,0,1,0);
//		glRotatef(shadowz,0,0,1);
        //glRotatef(10,0,0,1);
        //glFrustum(-worldX/4,worldX/8,-worldY/4, worldY/8, 20.0f, 8000.0f);
        //glFrustum(1,worldX-25+shadowx,-26 +shadowz, worldY-4+shadowy, 2.0f, 8000.0f);
        //glFrustum(0,overheadSelectX,shadowy,overheadSelectY, 2.0f, 8000.0f);
        //glFrustum(1,75+shadowx,-25+shadowz, 100+shadowy, 2.0f, 8000.0f);
        //glFrustum(-20,worldX-25+shadowx,-26 +shadowz, worldY-4+shadowy, 20.0f, 8000.0f);
        glFrustum(pickMatrixX-28,worldX-25,-25, worldY-4, 20.0f, 8000.0f);
    } else
    {   //third and first person view)
        pickMatrixX = pickMatrixX*8/(worldX);
        pickMatrixY = (H-pickMatrixY)/3;

        glMatrixMode (GL_PROJECTION);
        glPushMatrix ();
        glLoadIdentity ();
        gluPickMatrix (pickMatrixX,
                       pickMatrixY,
                       pickMatrixWidth-shadowz,
                       pickMatrixHeight-shadowz,  viewport);
        glFrustum( 1,worldX,-26, worldY, 5.0f, 40.0f);
    }

    glMatrixMode(GL_MODELVIEW);
    display();
    glMatrixMode (GL_PROJECTION);
    glPopMatrix ();
    glFlush();
    GLint hits = glRenderMode (GL_RENDER);
    process_Hits (hits, selectBuf);


    glutPostRedisplay();
}
Esempio n. 11
0
void
display(void)
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );

    convertToView();

    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf( modelViewMatrix );
    glColor4f(1,1,1,1);
    drawFloor(textures[FLOORID]);
    drawWalls(textures[WALLID]);


    //draw the items on the screen
    glRotatef(angle,0,1,0); //rotate the square

    //draw the snowman
    snowman.display();
    snowman2.display();
    snowman3.display();

    //draw the car
    Point tmpOrigin = vehicle.getOrigin();

    vehicle.display(translateToThirdPerson,
                    textures[SIRENID],
                    textures[VEHICLEID],
                    firstPersonView,
                    overheadView);
    if(overheadView)
        vehicle.setOrigin(tmpOrigin);




//scoreboard
    sb.setMsg2(msgDamage);

    //draw the Snowdift
    snowcave.display(textures[FLOORID]);
    snowcave2.display(textures[FLOORID]);

    //pond display
    pond.display(textures[PONDID],textures[WATERID]);

    //gifts
    //for (int i=0; i<giftCount;i++)
    //	gifts[i].display();
    glPushMatrix();
    for (int i=0; i<giftCount; i++)
        gifts[i].display();
    glPopMatrix();

    // Tractor Beam Function
    pullInObject();

    glPopMatrix();


    //ScoreBoard()
    glPushMatrix();
    glLoadIdentity();
    if(!overheadView)
        glTranslatef(sbOrigin.x,sbOrigin.y,sbOrigin.z);
    else
        glTranslatef(0,0,-40);

    sb.display(overheadView);
    glPopMatrix();

    drawCieling();


    npc.display(textures[BUTTONID]);

    glFlush();
    glutSwapBuffers();
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
	EGLDisplay display;
	EGLint egl_major, egl_minor;
	EGLConfig config;
	EGLint num_config;
	EGLContext context;
	EGLSurface surface;
	GLuint vertex_shader;
	GLuint fragment_shader;
	GLuint program;
	GLint ret;
	GLint width, height;
#ifdef HOOK
        the_hook("/mnt/sdcard/egl2.fdr");
#endif

	const char *vertex_shader_source =
	  "uniform mat4 modelviewMatrix;\n"
	  "uniform mat4 modelviewprojectionMatrix;\n"
	  "uniform mat3 normalMatrix;\n"
	  "\n"
	  "attribute vec4 in_position;    \n"
	  "attribute vec3 in_normal;      \n"
	  "attribute vec2 in_texcoord;       \n"
	  "\n"
	  "vec4 lightSource = vec4(2.0, 2.0, 20.0, 0.0);\n"
	  "                             \n"
	  "varying vec4 vColor;         \n"
	  "varying vec2 vTexCoord;         \n"
          "uniform sampler2D s_texture;                      \n"
	  "                             \n"
	  "void main()                  \n"
	  "{                            \n"
          "    float texvalue = texture2D(s_texture, in_texcoord).x;\n"
	  "    gl_Position = modelviewprojectionMatrix * (in_position + vec4(0.2 * texvalue * in_normal, 0));\n"
	  "    vec3 vEyeNormal = normalMatrix * in_normal;\n"
	  "    vec4 vPosition4 = modelviewMatrix * in_position;\n"
	  "    vec3 vPosition3 = vPosition4.xyz / vPosition4.w;\n"
	  "    vec3 vLightDir = normalize(lightSource.xyz - vPosition3);\n"
	  "    float diff = max(0.0, dot(vEyeNormal, vLightDir));\n"
	  "    vColor = vec4(diff, 0.0, 0.0, 1.0);\n"
	  "    vTexCoord = in_texcoord;\n"
	  "}                            \n";

	const char *fragment_shader_source =
	  "precision mediump float;     \n"
	  "                             \n"
	  "varying vec4 vColor;         \n"
	  "varying vec2 vTexCoord;         \n"
	  "                             \n"
	  "void main()                  \n"
	  "{                            \n"
	  "    gl_FragColor = vColor;// * texture2D(s_texture, vTexCoord);   \n"
	  "}                            \n";
	
        display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	if (display == EGL_NO_DISPLAY) {
		printf("Error: No display found!\n");
		return -1;
	}

	if (!eglInitialize(display, &egl_major, &egl_minor)) {
		printf("Error: eglInitialise failed!\n");
		return -1;
	}

	printf("Using display %p with EGL version %d.%d\n",
	       display, egl_major, egl_minor);

	printf("EGL Version \"%s\"\n", eglQueryString(display, EGL_VERSION));
	printf("EGL Vendor \"%s\"\n", eglQueryString(display, EGL_VENDOR));
	printf("EGL Extensions \"%s\"\n", eglQueryString(display, EGL_EXTENSIONS));

	/* get an appropriate EGL frame buffer configuration */
	eglChooseConfig(display, config_attribute_list, &config, 1, &num_config);

	/* create an EGL rendering context */
	context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list);
	if (context == EGL_NO_CONTEXT) {
		printf("Error: eglCreateContext failed: %d\n", eglGetError());
		return -1;
	}

	surface = eglCreatePbufferSurface(display, config, pbuffer_attribute_list);
	if (surface == EGL_NO_SURFACE) {
		printf("Error: eglCreatePbufferSurface failed: %d (%s)\n",
		       eglGetError(), eglStrError(eglGetError()));
		return -1;
	}

	if (!eglQuerySurface(display, surface, EGL_WIDTH, &width) ||
	    !eglQuerySurface(display, surface, EGL_HEIGHT, &height)) {
		printf("Error: eglQuerySurface failed: %d (%s)\n",
		       eglGetError(), eglStrError(eglGetError()));
		return -1;
	}
	printf("PBuffer: %dx%d\n", width, height);
        printf("GL Extensions \"%s\"\n", glGetString(GL_EXTENSIONS));

	/* connect the context to the surface */
	if (!eglMakeCurrent(display, surface, surface, context)) {
		printf("Error: eglMakeCurrent() failed: %d (%s)\n",
		       eglGetError(), eglStrError(eglGetError()));
		return -1;
	}

	vertex_shader = glCreateShader(GL_VERTEX_SHADER);
	if (!vertex_shader) {
		printf("Error: glCreateShader(GL_VERTEX_SHADER) failed: %d (%s)\n",
		       eglGetError(), eglStrError(eglGetError()));
		return -1;
	}


	glShaderSource(vertex_shader, 1, &vertex_shader_source, NULL);
	glCompileShader(vertex_shader);

	glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &ret);
	if (!ret) {
		char *log;

		printf("Error: vertex shader compilation failed!:\n");
		glGetShaderiv(vertex_shader, GL_INFO_LOG_LENGTH, &ret);

		if (ret > 1) {
			log = malloc(ret);
			glGetShaderInfoLog(vertex_shader, ret, NULL, log);
			printf("%s", log);
		}
		return -1;
	} else
		printf("Vertex shader compilation succeeded!\n");

	fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
	if (!fragment_shader) {
		printf("Error: glCreateShader(GL_FRAGMENT_SHADER) failed: %d (%s)\n",
		       eglGetError(), eglStrError(eglGetError()));
		return -1;
	}


	glShaderSource(fragment_shader, 1, &fragment_shader_source, NULL);
	glCompileShader(fragment_shader);

	glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &ret);
	if (!ret) {
		char *log;

		printf("Error: fragment shader compilation failed!:\n");
		glGetShaderiv(fragment_shader, GL_INFO_LOG_LENGTH, &ret);

		if (ret > 1) {
			log = malloc(ret);
			glGetShaderInfoLog(fragment_shader, ret, NULL, log);
			printf("%s", log);
		}
		return -1;
	} else
		printf("Fragment shader compilation succeeded!\n");

	program = glCreateProgram();
	if (!program) {
		printf("Error: failed to create program!\n");
		return -1;
	}
        
        GLfloat *vVertices;
        GLfloat *vNormals;
        GLfloat *vTexCoords;
        GLushort *vIndices;
        int numIndices = esGenSphere(40, 1.0f, &vVertices, &vNormals,
                                            &vTexCoords, &vIndices, NULL);
        GLuint texId = createSimpleTexture();
	
        glAttachShader(program, vertex_shader);
	glAttachShader(program, fragment_shader);

	glBindAttribLocation(program, 0, "in_position");
	glBindAttribLocation(program, 1, "in_normal");
	glBindAttribLocation(program, 2, "in_texcoord");

	glLinkProgram(program);

	glGetProgramiv(program, GL_LINK_STATUS, &ret);
	if (!ret) {
		char *log;

		printf("Error: program linking failed!:\n");
		glGetProgramiv(program, GL_INFO_LOG_LENGTH, &ret);

		if (ret > 1) {
			log = malloc(ret);
			glGetProgramInfoLog(program, ret, NULL, log);
			printf("%s", log);
		}
		return -1;
	} else
		printf("program linking succeeded!\n");

	glUseProgram(program);

	glViewport(0, 0, width, height);

	/* clear the color buffer */
	glClearColor(0.5, 0.5, 0.5, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
	glEnableVertexAttribArray(0);

	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, vNormals);
	glEnableVertexAttribArray(1);

	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords);
	glEnableVertexAttribArray(2);

	ESMatrix modelview;
	esMatrixLoadIdentity(&modelview);
	esTranslate(&modelview, 0.0f, 0.0f, -8.0f);
	esRotate(&modelview, 45.0f, 1.0f, 0.0f, 0.0f);
	esRotate(&modelview, 45.0f, 0.0f, 1.0f, 0.0f);
	esRotate(&modelview, 10.0f, 0.0f, 0.0f, 1.0f);

	GLfloat aspect = (GLfloat)(height) / (GLfloat)(width);

	ESMatrix projection;
	esMatrixLoadIdentity(&projection);
	esFrustum(&projection, -1.8f, +1.8f, -1.8f * aspect, +1.8f * aspect, 6.0f, 10.0f);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esMatrixMultiply(&modelviewprojection, &modelview, &projection);

	float normal[9];
	normal[0] = modelview.m[0][0];
	normal[1] = modelview.m[0][1];
	normal[2] = modelview.m[0][2];
	normal[3] = modelview.m[1][0];
	normal[4] = modelview.m[1][1];
	normal[5] = modelview.m[1][2];
	normal[6] = modelview.m[2][0];
	normal[7] = modelview.m[2][1];
	normal[8] = modelview.m[2][2];

	GLint modelviewmatrix_handle = glGetUniformLocation(program, "modelviewMatrix");
	GLint modelviewprojectionmatrix_handle = glGetUniformLocation(program, "modelviewprojectionMatrix");
	GLint normalmatrix_handle = glGetUniformLocation(program, "normalMatrix");
        GLint sampler_handle = glGetUniformLocation(program, "s_texture");

	glUniformMatrix4fv(modelviewmatrix_handle, 1, GL_FALSE, &modelview.m[0][0]);
	glUniformMatrix4fv(modelviewprojectionmatrix_handle, 1, GL_FALSE, &modelviewprojection.m[0][0]);
	glUniformMatrix3fv(normalmatrix_handle, 1, GL_FALSE, normal);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texId);
        glUniform1i(sampler_handle, 0);

	glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);

        glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, vIndices);

	glFlush();

	fflush(stdout);
        dump_gl_screen("/sdcard/egl2.bmp", width, height);

#ifdef HOOK
        close_hook();
#endif

	return 0;
}
Esempio n. 13
0
int main(int argc, char *argv[])
{
   int Width  = 384;
   int Height = 384;

    OSMesaContext ctx;
    void *buffer;
    char *filename = NULL;
    int ev;
    int repeat=1;

   /* Create an RGBA-mode context */
   /* specify Z, stencil, accum sizes */

    ctx = OSMesaCreateContextExt( OSMESA_BGRA, 16, 0, 0, NULL );
    if (!ctx) {
        printf("OSMesaCreateContext failed!\n");
        return 0;
    }

   /* Allocate the image buffer */
    buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
    if (!buffer) {
        printf("Alloc image buffer failed!\n");
        return 0;
    }

   /* Bind the buffer to the context and make it current */
   if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
      printf("OSMesaMakeCurrent failed!\n");
      return 0;
   }

   {
      int z, s, a;
      glGetIntegerv(GL_DEPTH_BITS, &z);
      glGetIntegerv(GL_STENCIL_BITS, &s);
      glGetIntegerv(GL_ACCUM_RED_BITS, &a);
      printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
   }

    reshape(Width, Height);

    glClearColor( 0, 0, 0, 1);

    init();
    draw();

    DrawWindow(10, 10, Width+TYPE_3_BORDER_WIDTH*2, Height+TYPE_3_BORDER_WIDTH+get_skin_height(),
               "OpenGL Engine Demo", 0x000000, 0x74);
    Blit(buffer, TYPE_3_BORDER_WIDTH, get_skin_height(), 0, 0, Width, Height, Width,Height,Width*4);

    int start = time_now();
    int frames = 0;

    while(repeat)
    {
        int now = time_now();
        oskey_t   key;

        ev = check_os_event();
        switch(ev)
        {
            case 1:
                DrawWindow(0,0,0,0, NULL, 0x000000,0x74);
                break;

            case 2:
                key = get_key();
                keyboard(key.code);
                break;

            case 3:
                if(get_os_button()==1)
                    repeat=0;
                    continue;
        };

        if (now - start >= 5000)
        {
            double elapsed = (double) (now - start) / 1000.0;

            printf("%d frames in %3.1f seconds = %6.3f FPS\n",
                    frames, elapsed, frames / elapsed);
            fflush(stdout);

            start = now;
            frames = 0;
        }

        idle();
        draw();
        glFlush();
        Blit(buffer, TYPE_3_BORDER_WIDTH, get_skin_height(), 0, 0, Width, Height, Width,Height,Width*4);
        frames++;
    };

   /* free the image buffer */
   free( buffer );

   /* destroy the context */
   OSMesaDestroyContext( ctx );

   return 0;
}
Esempio n. 14
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();
}
Esempio n. 15
0
/* Main display routine. Clears the drawing buffer and if transparency is
   set, displays the model twice, 1st time accepting those fragments with 
   a ALPHA value of 1 only, then with DEPTH_BUFFER writing disabled for 
   those with other values. */
void 
display(void)
{
  int pass;

#ifdef STEREO
  int i;

  /* enclose original rendering code in 2-pass loop */
  for (i=0; i<2; i++)
  {
  /* adjust projection matrix for stereo viewpoint */
  if (bStereoEnabled) {
	  glDrawBuffer((i==0) ? GL_BACK_LEFT : GL_BACK_RIGHT);
	  glMatrixMode(GL_PROJECTION);
	  glPushMatrix();
	  glLoadMatrixf((i==0) ? &mProjectionLeft : &mProjectionRight);
	  glMatrixMode(GL_MODELVIEW);
	  }
#endif

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();
	if (transparent) {
	  glEnable(GL_ALPHA_TEST);
	  pass = 2;
	} else {
	  glDisable(GL_ALPHA_TEST);
	  pass = 0;
	}

	/* Rotate the whole model */
	glRotatef(view_h, 0, 1, 0);
	glRotatef(view_v, 1, 0, 0);

	do {
	  if (pass == 2) {
		glAlphaFunc(GL_EQUAL, 1);
		glDepthMask(GL_TRUE);
		pass--;
      } else if (pass != 0) {
		glAlphaFunc(GL_NOTEQUAL, 1);
        glDepthMask(GL_FALSE);
        pass--;
      }
      draw_engine_pole();

      glPushMatrix();
        glTranslatef(0.5, 1.4, 0.0);
        draw_cylinder_head();
      glPopMatrix();

      glPushMatrix();
        glTranslatef(0.0, -0.8, 0.0);
        draw_crank();
      glPopMatrix();
    } while (pass > 0);
    glDepthMask(GL_TRUE);
  glPopMatrix();

#ifdef STEREO
  /* render twice for stereo, or once for mono */
  if (bStereoEnabled) {
	  glFlush();
	  glMatrixMode(GL_PROJECTION);
	  glPopMatrix();
	  glMatrixMode(GL_MODELVIEW);
	  }
  else
	  break;
  } /* for loop */
#endif

  glutSwapBuffers();
}
Esempio n. 16
0
int GLinitialize()
{
 //----------------------------------------------------// 
#ifdef _WINDOWS
 HGLRC objectRC;
 // init
 dcGlobal = GetDC(hWWindow);                           // FIRST: dc/rc stuff
 objectRC = wglCreateContext(dcGlobal);
 GLCONTEXT=objectRC;
 wglMakeCurrent(dcGlobal, objectRC);
 // CheckWGLExtensions(dcGlobal);
 if(bWindowMode) ReleaseDC(hWWindow,dcGlobal);         // win mode: release dc again
#endif
 //----------------------------------------------------// 

 glViewport(rRatioRect.left,                           // init viewport by ratio rect
            iResY-(rRatioRect.top+rRatioRect.bottom),
            rRatioRect.right,
            rRatioRect.bottom);

 glScissor(0, 0, iResX, iResY);                        // init clipping (fullscreen)
 glEnable(GL_SCISSOR_TEST);

#ifndef OWNSCALE
 glMatrixMode(GL_TEXTURE);                             // init psx tex sow and tow if not "ownscale"
 glLoadIdentity();
 glScalef(1.0f/255.99f,1.0f/255.99f,1.0f);             // geforce precision hack
#endif

 glMatrixMode(GL_PROJECTION);                          // init projection with psx resolution
 glLoadIdentity();
 glOrtho(0,PSXDisplay.DisplayMode.x,
         PSXDisplay.DisplayMode.y, 0, -1, 1);

 if(iZBufferDepth)                                     // zbuffer?
  {
   uiBufferBits=GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT;
   glEnable(GL_DEPTH_TEST);
   glDepthFunc(GL_ALWAYS);
   iDepthFunc=1;
  }
 else                                                  // no zbuffer?
  {
   uiBufferBits=GL_COLOR_BUFFER_BIT;
   glDisable(GL_DEPTH_TEST);
  }

 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                 // first buffer clear
 glClear(uiBufferBits);

 if(bUseLines)                                         // funny lines 
  {
   glPolygonMode(GL_FRONT, GL_LINE);
   glPolygonMode(GL_BACK, GL_LINE);
  }
 else                                                  // or the real filled thing
  {
   glPolygonMode(GL_FRONT, GL_FILL);
   glPolygonMode(GL_BACK, GL_FILL);
  }

 MakeDisplayLists();                                   // lists for menu/opaque
 GetExtInfos();                                        // get ext infos
 SetExtGLFuncs();                                      // init all kind of stuff (tex function pointers)

 glEnable(GL_ALPHA_TEST);                              // wanna alpha test

 if(!bUseAntiAlias)                                    // no anti-alias (default)
  {
   glDisable(GL_LINE_SMOOTH);
   glDisable(GL_POLYGON_SMOOTH);
   glDisable(GL_POINT_SMOOTH);
  }
 else                                                  // wanna try it? glitches galore...
  {
   glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
   glEnable(GL_LINE_SMOOTH);
   glEnable(GL_POLYGON_SMOOTH);
   glEnable(GL_POINT_SMOOTH);
   glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
   glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
   glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
  }

 ubGloAlpha=127;                                       // init some drawing vars
 ubGloColAlpha=127;
 TWin.UScaleFactor = 1;
 TWin.VScaleFactor = 1;
 bDrawMultiPass=FALSE;
 bTexEnabled=FALSE;
 bUsingTWin=FALSE;

 if(bDrawDither)  glEnable(GL_DITHER);                 // dither mode
 else             glDisable(GL_DITHER);

 glDisable(GL_FOG);                                    // turn all (currently) unused modes off
 glDisable(GL_LIGHTING);
 glDisable(GL_LOGIC_OP);
 glDisable(GL_STENCIL_TEST);
 glDisable(GL_TEXTURE_1D);
 glDisable(GL_TEXTURE_2D);
 glDisable(GL_CULL_FACE);

 glPixelTransferi(GL_RED_SCALE, 1);                    // to be sure:
 glPixelTransferi(GL_RED_BIAS, 0);                     // init more OGL vals
 glPixelTransferi(GL_GREEN_SCALE, 1);
 glPixelTransferi(GL_GREEN_BIAS, 0);
 glPixelTransferi(GL_BLUE_SCALE, 1);
 glPixelTransferi(GL_BLUE_BIAS, 0);
 glPixelTransferi(GL_ALPHA_SCALE, 1);
 glPixelTransferi(GL_ALPHA_BIAS, 0);

#ifdef _WINDOWS
                                                       // detect Windows hw/sw mode (just for info)
 if(!strcmp("Microsoft Corporation",(LPTSTR)glGetString(GL_VENDOR)) &&
    !strcmp("GDI Generic",          (LPTSTR)glGetString(GL_RENDERER)))
      bGLSoft=TRUE;
 else bGLSoft=FALSE;

#else

 printf(glGetString(GL_VENDOR));                       // linux: tell user what is getting used
 printf("\n");
 printf(glGetString(GL_RENDERER));
 printf("\n");

#endif

 glFlush();                                            // we are done...
 glFinish();

 CreateScanLines();                                    // setup scanline stuff (if wanted)

 CheckTextureMemory();                                 // check available tex memory

 if(bKeepRatio) SetAspectRatio();                      // set ratio

 if(iShowFPS)                                          // user wants FPS display on startup?
  {
   ulKeybits|=KEY_SHOWFPS;                             // -> ok, turn display on
   szDispBuf[0]=0;
   BuildDispMenu(0);
  }

 bIsFirstFrame = FALSE;                                // we have survived the first frame :)

 return 0;
}
Esempio n. 17
0
void
Display( void )
{
	if( DebugOn != 0 )
	{
		fprintf( stderr, "Display\n" );
	}


	// set which window we want to do the graphics into:

	glutSetWindow( MainWindow );


	// erase the background:

	glDrawBuffer( GL_BACK );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glEnable( GL_DEPTH_TEST );


	// specify shading to be flat:

	glShadeModel( GL_FLAT );


	// set the viewport to a square centered in the window:

	GLsizei vx = glutGet( GLUT_WINDOW_WIDTH );
	GLsizei vy = glutGet( GLUT_WINDOW_HEIGHT );
	GLsizei v = vx < vy ? vx : vy;			// minimum dimension
	GLint xl = ( vx - v ) / 2;
	GLint yb = ( vy - v ) / 2;
	glViewport( xl, yb,  v, v );


	// set the viewing volume:
	// remember that the Z clipping  values are actually
	// given as DISTANCES IN FRONT OF THE EYE
	// USE gluOrtho2D( ) IF YOU ARE DOING 2D !

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	if( WhichProjection == ORTHO )
		glOrtho( -3., 3.,     -3., 3.,     0.1, 1000. );
	else
		gluPerspective( 90., 1.,	0.1, 1000. );


	// place the objects into the scene:

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity( );


	// set the eye position, look-at position, and up-vector:
	// IF DOING 2D, REMOVE THIS -- OTHERWISE ALL YOUR 2D WILL DISAPPEAR !

	gluLookAt( 0., 0., 3.,     0., 0., 0.,     0., 1., 0. );


	// translate the objects in the scene:
	// note the minus sign on the z value
	// this is to make the appearance of the glui z translate
	// widget more intuitively match the translate behavior
	// DO NOT TRANSLATE IN Z IF YOU ARE DOING 2D !

	glTranslatef( (GLfloat)TransXYZ[0], (GLfloat)TransXYZ[1], -(GLfloat)TransXYZ[2] );


	// rotate the scene:
	// DO NOT ROTATE (EXCEPT ABOUT Z) IF YOU ARE DOING 2D !

	glRotatef( (GLfloat)Yrot, 0., 1., 0. );
	glRotatef( (GLfloat)Xrot, 1., 0., 0. );
	glMultMatrixf( (const GLfloat *) RotMatrix );


	// uniformly scale the scene:

	glScalef( (GLfloat)Scale, (GLfloat)Scale, (GLfloat)Scale );
	GLfloat scale2 = 1. + Scale2;		// because glui translation starts at 0.
	if( scale2 < MINSCALE )
		scale2 = MINSCALE;
	glScalef( (GLfloat)scale2, (GLfloat)scale2, (GLfloat)scale2 );


	// set the fog parameters:
	// DON'T NEED THIS IF DOING 2D !

	if( DepthCueOn != 0 )
	{
		glFogi( GL_FOG_MODE, FOGMODE );
		glFogfv( GL_FOG_COLOR, FOGCOLOR );
		glFogf( GL_FOG_DENSITY, FOGDENSITY );
		glFogf( GL_FOG_START, FOGSTART );
		glFogf( GL_FOG_END, FOGEND );
		glEnable( GL_FOG );
	}
	else
	{
		glDisable( GL_FOG );
	}


	// possibly draw the axes:

	if( AxesOn != 0 )
	{
		glColor3fv( &Colors[WhichColor][0] );
		glCallList( AxesList );
	}


	// set the color of the object:

	glColor3fv( Colors[WhichColor] );


	// draw the current object:

	glCallList( BoxList );


	// draw some gratuitous text that just rotates on top of the scene:

	glDisable( GL_DEPTH_TEST );
	glColor3f( 0., 1., 1. );
	DoRasterString( 0., 1., 0., "Text That Moves" );


	// draw some gratuitous text that is fixed on the screen:
	//
	// the projection matrix is reset to define a scene whose
	// world coordinate system goes from 0-100 in each axis
	//
	// this is called "percent units", and is just a convenience
	//
	// the modelview matrix is reset to identity as we don't
	// want to transform these coordinates

	glDisable( GL_DEPTH_TEST );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	gluOrtho2D( 0., 100.,     0., 100. );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity( );
	glColor3f( 1., 1., 1. );
	DoRasterString( 5., 5., 0., "Text That Doesn't" );


	// swap the double-buffered framebuffers:

	glutSwapBuffers( );


	// be sure the graphics buffer has been sent:
	// note: be sure to use glFlush( ) here, not glFinish( ) !

	glFlush( );
}
Esempio n. 18
0
void CollisionInterfaceDemo::displayCallback(void) {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
	glDisable(GL_LIGHTING);

	collisionWorld->getDispatchInfo().m_debugDraw = &debugDrawer;
	
	if (collisionWorld)
		collisionWorld->performDiscreteCollisionDetection();
	
	int i;

	///one way to draw all the contact points is iterating over contact manifolds / points:

	int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
	for (i=0;i<numManifolds;i++)
	{
		btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
	
		int numContacts = contactManifold->getNumContacts();
		for (int j=0;j<numContacts;j++)
		{
			btManifoldPoint& pt = contactManifold->getContactPoint(j);

			glBegin(GL_LINES);
			glColor3f(1, 0, 1);
			
			btVector3 ptA = pt.getPositionWorldOnA();
			btVector3 ptB = pt.getPositionWorldOnB();

			glVertex3d(ptA.x(),ptA.y(),ptA.z());
			glVertex3d(ptB.x(),ptB.y(),ptB.z());
			glEnd();
		}

		//you can un-comment out this line, and then all points are removed
		//contactManifold->clearManifold();	
	}

	//GL_ShapeDrawer::drawCoordSystem();

	btScalar m[16];
	
	btVector3	worldBoundsMin,worldBoundsMax;
	collisionWorld->getBroadphase()->getBroadphaseAabb(worldBoundsMin,worldBoundsMax);


	for (i=0;i<numObjects;i++)
	{
		
		objects[i].getWorldTransform().getOpenGLMatrix( m );
		m_shapeDrawer.drawOpenGL(m,objects[i].getCollisionShape(),btVector3(1,1,1),getDebugMode(),worldBoundsMin,worldBoundsMax);

	}


	btQuaternion orn;
	orn.setEuler(yaw,pitch,roll);
	objects[1].getWorldTransform().setOrigin(objects[1].getWorldTransform().getOrigin()+btVector3(0,-0.01,0));

	objects[0].getWorldTransform().setRotation(orn);

	pitch += 0.005f;
	yaw += 0.01f;

	glFlush();
    glutSwapBuffers();
}
Esempio n. 19
0
void widget3d::paint() {
  // Set border
  if (m_pixels.size() != 0) {
    auto x_bound = std::max_element(m_pixels.begin(), m_pixels.end(), [](pairp a, pairp b) {
      return std::abs(a.first.x) < std::abs(b.first.x);
    });
    auto y_bound = std::max_element(m_pixels.begin(), m_pixels.end(), [](pairp a, pairp b) {
      return std::abs(a.first.y) < std::abs(b.first.y);
    });
    auto z_bound = std::max_element(m_pixels.begin(), m_pixels.end(), [](pairp a, pairp b) {
      return std::abs(a.first.z) < std::abs(b.first.z);
    });
    double offset = 0.5;
    m_netXSize = ((*x_bound).first.x == 0) ? 1.0 : std::abs((*x_bound).first.x) + offset;
    m_netYSize = ((*y_bound).first.y == 0) ? 1.0 : std::abs((*x_bound).first.y) + offset;
    m_netZSize = ((*z_bound).first.z == 0) ? 1.0 : std::abs((*z_bound).first.z) + offset;
  }
  // opengl init
  glViewport(0, 0, m_real_size_x, m_real_size_y);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  GLfloat x = GLfloat(m_real_size_x) / m_real_size_y;
  glFrustum(-x, x, -1.0, 1.0, 4.0, 12.0 * m_zValue);  // Multiply current matrix with perspective matrix
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  /* GL init config */
  glTranslatef(-0.0, -0.25, -6.0 * m_zValue);
  glRotatef(m_xAngle, 1.0, 0.0, 0.0);
  glRotatef(m_yAngle, 0.0, 1.0, 0.0);
  glRotatef(m_zAngle, 0.0, 0.0, 1.0);
  /* Draw background net */
  glLineWidth(1.0);
  enableEffects();
  // oX, oY, oZ axis
  if (m_isDrawAxis) {
    glBegin(GL_LINES);
    glColor4f(1.0, 0.0, 0.0, 1);
    glVertex3f(-m_netXSize, m_y_offset, 0.0);
    glVertex3f(m_netXSize, m_y_offset, 0.0);

    glColor4f(0.0, 1.0, 0.0, 1);
    glVertex3f(0.0, -m_netYSize, 0.0);
    glVertex3f(0.0, m_netYSize, 0.0);

    glColor4f(0.0, 0.0, 1.0, 1);
    glVertex3f(0.0, m_y_offset, -m_netZSize);
    glVertex3f(0.0, m_y_offset, m_netZSize);
    glEnd();
  }
  // Background net
  if (m_isDrawNet) {
    glColor4f(.25, .25, .25, 1);
    glBegin(GL_LINES);
    for (double x = -m_netXSize; x <= m_netXSize; x += m_delta) {
      glVertex3f(x, 0.0, -m_netZSize);
      glVertex3f(x, 0.0, m_netZSize);
    }
    for (double z = -m_netZSize; z <= m_netZSize; z += m_delta) {
      glVertex3f(-m_netXSize, 0.0, z);
      glVertex3f(m_netXSize, 0.0, z);
    }
    glEnd();
  }
  // Draw points
  for (auto& pixel : m_pixels) {
    auto p = pixel.first;
    auto o = pixel.second;
    glPointSize(o.tickness);
    glBegin(GL_POINTS);
    glColor3d(o.colour.r / 255.0,
              o.colour.g / 255.0,
              o.colour.b / 255.0);
    glVertex3d(p.x, p.y, p.z);
    glEnd();
  }
  // Draw lines
  for (auto& line : m_lines) {
    auto p1 = line.first;
    auto p2 = line.second;
    glPointSize(1);
    glBegin(GL_LINES);
    glColor3d(1.0, 1.0, 1.0);
    glVertex3d(p1.x, p1.y, p1.z);
    glVertex3d(p2.x, p2.y, p2.z);
    glEnd();
  }
  // End of paint
  glPopMatrix();
  glFlush();
  disableEffects();
}
Esempio n. 20
0
/**
 *  First column:  emerald, jade, obsidian, pearl, ruby, turquoise
 *  2nd column:  brass, bronze, chrome, copper, gold, silver
 *  3rd column:  black, cyan, green, red, white, yellow plastic
 *  4th column:  black, cyan, green, red, white, yellow rubber
 */
void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   //display the first column of teapots
   //emerald
   renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215,
      0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6);
   //jade
   renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575,
      0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1);
   //obsidian
   renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625,
      0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3);
   //pearl
   renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725,
      1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088);
   //ruby
   renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175,
      0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6);
   //turqoise
   renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745,
      0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1);

   //display the second column of teapots
   //brass
   renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451,
      0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843,
      0.21794872);
   //bronze
   renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054,
      0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2);
   //chrome
   renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25,
      0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6);
   //copper
   renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225,
      0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1);
   //gold
   renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745,
      0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4);
   //silver
   renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225,
      0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4);

   //display the third column of teapots
   //black plastic
   renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01,
      0.50, 0.50, 0.50, .25);
   //cyan plastic
   renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392,
      0.50196078, 0.50196078, 0.50196078, .25);
   //green plastic
   renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0,
      0.1, 0.35, 0.1, 0.45, 0.55, 0.45, .25);
   //red plastic
   renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
      0.7, 0.6, 0.6, .25);
   //white plastic
   renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55,
      0.70, 0.70, 0.70, .25);
   //yellow plastic
   renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
      0.60, 0.60, 0.50, .25);

   //display the fourth column of teapots
   //black rubber
   renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01,
      0.4, 0.4, 0.4, .078125);
   //cyan rubber
   renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5,
      0.04, 0.7, 0.7, .078125);
   //green rubber
   renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4,
      0.04, 0.7, 0.04, .078125);
   //red rubber
   renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4,
      0.7, 0.04, 0.04, .078125);
   //white rubber
   renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5,
      0.7, 0.7, 0.7, .078125);
   //yellow rubber
   renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4,
      0.7, 0.7, 0.04, .078125);
   glFlush();
}
Esempio n. 21
0
void EuphoriaWidget::paintGL()
{
	int i;
	static double lastTime = timeGetTime();

	// update time
	elapsedTime = timeGetTime() - lastTime;
	lastTime += elapsedTime;

    _ec = this;

	// Update wisps
	for(i=0; i<dWisps; i++)
		_wisps[i].update();
	for(i=0; i<dBackground; i++)
		_backwisps[i].update();


	if(dFeedback)
    {
		float feedbackIntensity = float(dFeedback) / 101.0f;

		// update feedback variables
		for(i=0; i<4; i++)
        {
			fr[i] += elapsedTime * fv[i];
			if(fr[i] > PIx2)
				fr[i] -= PIx2;
		}
		f[0] = 30.0f * cos(fr[0]);
		f[1] = 0.2f * cos(fr[1]);
		f[2] = 0.2f * cos(fr[2]);
		f[3] = 0.8f * cos(fr[3]);
		for(i=0; i<3; i++)
        {
			lr[i] += elapsedTime * lv[i];
			if(lr[i] > PIx2)
				lr[i] -= PIx2;
			l[i] = cos(lr[i]);
			l[i] = l[i] * l[i];
		}

		// Create drawing area for feedback texture
		glViewport(0, 0, feedbacktexsize, feedbacktexsize);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(30.0, aspectRatio, 0.01f, 20.0f);
		glMatrixMode(GL_MODELVIEW);

		// Draw
		glClear(GL_COLOR_BUFFER_BIT);
		glColor3f(feedbackIntensity, feedbackIntensity, feedbackIntensity);
		glBindTexture(GL_TEXTURE_2D, feedbacktex);
		glPushMatrix();
		glTranslatef(f[1] * l[1], f[2] * l[1], f[3] * l[2]);
		glRotatef(f[0] * l[0], 0, 0, 1);
		glBegin(GL_TRIANGLE_STRIP);
			glTexCoord2f(-0.5f, -0.5f);
			glVertex3f(-aspectRatio*2.0f, -2.0f, 1.25f);
			glTexCoord2f(1.5f, -0.5f);
			glVertex3f(aspectRatio*2.0f, -2.0f, 1.25f);
			glTexCoord2f(-0.5f, 1.5f);
			glVertex3f(-aspectRatio*2.0f, 2.0f, 1.25f);
			glTexCoord2f(1.5f, 1.5f);
			glVertex3f(aspectRatio*2.0f, 2.0f, 1.25f);
		glEnd();
		glPopMatrix();
		glBindTexture(GL_TEXTURE_2D, texName);
		for(i=0; i<dBackground; i++)
			_backwisps[i].drawAsBackground();
		for(i=0; i<dWisps; i++)
			_wisps[i].draw();

		// readback feedback texture
		glReadBuffer(GL_BACK);
		glPixelStorei(GL_UNPACK_ROW_LENGTH, feedbacktexsize);
		glBindTexture(GL_TEXTURE_2D, feedbacktex);
		glReadPixels(0, 0, feedbacktexsize, feedbacktexsize, GL_RGB, GL_UNSIGNED_BYTE, feedbackmap);
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, feedbacktexsize, feedbacktexsize, GL_RGB, GL_UNSIGNED_BYTE, feedbackmap);

		// create regular drawing area
		glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(20.0, aspectRatio, 0.01f, 20.0f);
		glMatrixMode(GL_MODELVIEW);

		// Draw again
		glClear(GL_COLOR_BUFFER_BIT);
		glColor3f(feedbackIntensity, feedbackIntensity, feedbackIntensity);
		glPushMatrix();
		glTranslatef(f[1] * l[1], f[2] * l[1], f[3] * l[2]);
		glRotatef(f[0] * l[0], 0, 0, 1);
		glBegin(GL_TRIANGLE_STRIP);
			glTexCoord2f(-0.5f, -0.5f);
			glVertex3f(-aspectRatio*2.0f, -2.0f, 1.25f);
			glTexCoord2f(1.5f, -0.5f);
			glVertex3f(aspectRatio*2.0f, -2.0f, 1.25f);
			glTexCoord2f(-0.5f, 1.5f);
			glVertex3f(-aspectRatio*2.0f, 2.0f, 1.25f);
			glTexCoord2f(1.5f, 1.5f);
			glVertex3f(aspectRatio*2.0f, 2.0f, 1.25f);
		glEnd();
		glPopMatrix();

		glBindTexture(GL_TEXTURE_2D, texName);
	}
	else
		glClear(GL_COLOR_BUFFER_BIT);

	//
	for(i=0; i<dBackground; i++)
		_backwisps[i].drawAsBackground();
	for(i=0; i<dWisps; i++)
		_wisps[i].draw();

	glFlush();
}
//glutDisplayFunc
//notice most of the set up values are not in here but in myInit
void displayMesh(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1,1,1);
    glPushMatrix();
        glTranslated(1.9,0, 0);
        glCallList(cloud);
        glCallList(landscapeWinterTile);
    glPopMatrix();
    glPushMatrix();
        glCallList(landscapeFallTile);
    glPopMatrix();
    glPushMatrix();
        glTranslated(-1.9,0, 0);
        glCallList(landscapeSummerTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(0,0, -1.9);
        glCallList(landscapeFallTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(0,0, 1.9);
        glCallList(landscapeFallTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(1.9,0, 1.9);
        glCallList(landscapeWinterTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(-1.9,0, 1.9);
        glCallList(landscapeSummerTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(-1.9,0, -1.9);
        glCallList(landscapeSummerTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(1.9,0, -1.9);
        glCallList(landscapeWinterTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(-3.6,0, -1.9);
        glCallList(landscapeSpringTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(-3.6,0, 0);
        glCallList(landscapeSpringTile);
    glPopMatrix();

    glPushMatrix();
        glTranslated(-3.6,0, 1.9);
        glCallList(landscapeSpringTile);
    glPopMatrix();

    glPushMatrix();
    glColor4f(0, 0, .8, 0.6);
    glTranslated(0,-0.25, 0);
    glScaled(23, .12, 23);
    glutSolidCube(1.0);
    glPopMatrix();

	glCallList(all_trees);

	drawFallingLeaves();


  processCam();
  glFlush();
  glutPostRedisplay();
}
Esempio n. 23
0
void TestGLContext::DrawRotatedCube(float xangle, float yangle)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -2.0f);
    glRotatef(xangle, 1.0f, 0.0f, 0.0f);
    glRotatef(yangle, 0.0f, 1.0f, 0.0f);

    // draw six faces of a cube of size 1 centered at (0, 0, 0)
    glBindTexture(GL_TEXTURE_2D, m_textures[0]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f, 0.0f, 1.0f);
        glTexCoord2f(0, 0); glVertex3f( 0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 0); glVertex3f(-0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 1); glVertex3f(-0.5f,-0.5f, 0.5f);
        glTexCoord2f(0, 1); glVertex3f( 0.5f,-0.5f, 0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[1]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f, 0.0f,-1.0f);
        glTexCoord2f(0, 0); glVertex3f(-0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 0); glVertex3f(-0.5f, 0.5f,-0.5f);
        glTexCoord2f(1, 1); glVertex3f( 0.5f, 0.5f,-0.5f);
        glTexCoord2f(0, 1); glVertex3f( 0.5f,-0.5f,-0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[2]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f, 1.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f( 0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 0); glVertex3f( 0.5f, 0.5f,-0.5f);
        glTexCoord2f(1, 1); glVertex3f(-0.5f, 0.5f,-0.5f);
        glTexCoord2f(0, 1); glVertex3f(-0.5f, 0.5f, 0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[3]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f,-1.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f(-0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 0); glVertex3f( 0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 1); glVertex3f( 0.5f,-0.5f, 0.5f);
        glTexCoord2f(0, 1); glVertex3f(-0.5f,-0.5f, 0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[4]);
    glBegin(GL_QUADS);
        glNormal3f( 1.0f, 0.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f( 0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 0); glVertex3f( 0.5f,-0.5f, 0.5f);
        glTexCoord2f(1, 1); glVertex3f( 0.5f,-0.5f,-0.5f);
        glTexCoord2f(0, 1); glVertex3f( 0.5f, 0.5f,-0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[5]);
    glBegin(GL_QUADS);
        glNormal3f(-1.0f, 0.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f(-0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 0); glVertex3f(-0.5f,-0.5f, 0.5f);
        glTexCoord2f(1, 1); glVertex3f(-0.5f, 0.5f, 0.5f);
        glTexCoord2f(0, 1); glVertex3f(-0.5f, 0.5f,-0.5f);
    glEnd();

    glFlush();

    CheckGLError();
}
Esempio n. 24
0
void C3DPlotCanvas::OnPaint( wxPaintEvent& event )
{
    /* must always be here */
    wxPaintDC dc(this);

    if (!GetContext()) return;

    SetCurrent();

    /* initialize OpenGL */
    if (isInit == false) {
        InitGL();
        isInit = true;
    }

	begin_redraw();
    RenderScene();
	end_redraw();

	if (bSelect) {
		double world11[3],world12[3], world22[3], world21[3];
		int pixel11[2], pixel12[2], pixel22[2], pixel21[2];

		int small_x=(select_start.x<select_end.x)? select_start.x:select_end.x;
		int large_x=(select_start.x>select_end.x)? select_start.x:select_end.x;
		int small_y=(select_start.y>select_end.y)? select_start.y:select_end.y;
		int large_y=(select_start.y<select_end.y)? select_start.y:select_end.y;

		pixel11[0] = small_x;
		pixel12[0] = small_x;
		pixel21[0] = large_x;
		pixel22[0] = large_x;

		pixel11[1] = small_y;
		pixel21[1] = small_y;
		pixel12[1] = large_y;
		pixel22[1] = large_y;

		unproject_pixel(pixel11, world11, 0.0);	
		unproject_pixel(pixel12, world12, 0.0);
		unproject_pixel(pixel22, world22, 0.0);
		unproject_pixel(pixel21, world21, 0.0);

		glLineWidth(2.0);
		glColor3f(0.75,0.75,0.75);
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_LIGHTING);
		glBegin(GL_LINES);
			glVertex3dv(world11);
			glVertex3dv(world12);
			glVertex3dv(world12);
			glVertex3dv(world22);
			glVertex3dv(world22);
			glVertex3dv(world21);
			glVertex3dv(world21);
			glVertex3dv(world11);
		glEnd();
		glEnable(GL_LIGHTING);
		glEnable(GL_DEPTH_TEST);
	}

    /* flush */
    glFlush();

    /* swap */
    SwapBuffers();
}
Esempio n. 25
0
/*
 * main rendering loop
 */
static void draw(ModeInfo * mi)
{
   boxedstruct *gp = &boxed[MI_SCREEN(mi)];
   int wire = MI_IS_WIREFRAME (mi);
   vectorf v1,v2;
   GLfloat r;
   int dx, dz;
   int i;   
   
   GLfloat dgray[4] = {0.3f, 0.3f, 0.3f, 1.0f};
   GLfloat black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
   GLfloat lblue[4] = {0.4f,0.6f,1.0f };
   
   GLfloat l0_ambient[] =    {0.0, 0.0, 0.0, 1.0};
   GLfloat l0_specular[] =    {1.0, 1.0, 1.0, 1.0};
   GLfloat l0_diffuse[] =    {1.0, 1.0, 1.0, 1.0};
   GLfloat l0_position[] =  {0.0, 0.0, 0.0, 1.0}; /* w != 0 -> positional light */
   GLfloat l1_ambient[] =    {0.0, 0.0, 0.0, 1.0};
   GLfloat l1_specular[] =    {1.0, 1.0, 1.0, 1.0};
   GLfloat l1_diffuse[] =    {0.5, 0.5, 0.5, 1.0};
   GLfloat l1_position[] =  {0.0, 1.0, 0.0, 0.0}; /* w = 0 -> directional light */
   
   mi->polygon_count = 0;

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   
# ifdef HAVE_MOBILE	/* Keep it the same relative size when rotated. */
  {
    GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
    int o = (int) current_device_rotation();
    if (o != 0 && o != 180 && o != -180)
      glScalef (1/h, 1/h, 1/h);
    glRotatef(o, 0, 0, 1);
  }
# endif

   gp->tic += 0.01f;
   gp->camtic += 0.01f + 0.01f * sin(gp->tic * speed);
   
   /* rotate camera around (0,0,0), looking at (0,0,0), up is (0,1,0) */
   r = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->camtic/CAMDISTANCE_SPEED) * speed);
   v1.x = r * sin((gp->camtic/gp->cam_x_speed) * speed);
   v1.z = r * cos((gp->camtic/gp->cam_x_speed) * speed);
   v1.y = CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT;

   v2.x = LOOKAT_R * sin((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed);
   v2.z = LOOKAT_R * cos((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed);
   v2.y = (CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT)/10.0;

   gluLookAt(v1.x,v1.y,v1.z,v2.x,v2.y,v2.x,0.0,1.0,0.0); 

   if (!wire) {
     glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient); 
     glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_diffuse); 
     glLightfv(GL_LIGHT0, GL_SPECULAR, l0_specular); 
     glLightfv(GL_LIGHT0, GL_POSITION, l0_position);
     glLightfv(GL_LIGHT1, GL_AMBIENT, l1_ambient); 
     glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diffuse); 
     glLightfv(GL_LIGHT1, GL_SPECULAR, l1_specular); 
     glLightfv(GL_LIGHT1, GL_POSITION, l1_position);
     glEnable(GL_LIGHT0);
     glEnable(GL_LIGHT1);
   
     glFrontFace(GL_CW);
   
     glMaterialfv(GL_FRONT, GL_SPECULAR, black);
     glMaterialfv(GL_FRONT, GL_EMISSION, lblue);
     glMaterialfv(GL_FRONT,GL_AMBIENT,black);
     glMaterialf(GL_FRONT, GL_SHININESS, 5.0);
   }
   
   
   /* draw ground grid */
   /* glDisable(GL_DEPTH_TEST); */
   glDisable(GL_LIGHTING);
   
   glColor3f(0.1,0.1,0.6);
   for (dx= -2; dx<3; dx++) {
      for (dz= -2; dz<3; dz++) {
	 glPushMatrix();
	 glTranslatef(dx*30.0f, 0.0f, dz*30.0f);
	 drawpattern(gp);
	 glPopMatrix();
      }   
   }
   
   /* Set drawing mode for the boxes */
   glEnable(GL_DEPTH_TEST);
   if (!wire) glEnable(GL_TEXTURE_2D);
   glPushMatrix();
   glColor3f(1.0,1.0,1.0);
   glScalef(20.0,0.25,20.0);
   glTranslatef(0.0,2.0,0.0);
   mi->polygon_count += drawfilledbox(gp, wire);
   glPopMatrix();
   glDisable(GL_TEXTURE_2D);

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(20.0,20.0,0.25);
   glTranslatef(0.0,1.0,81.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(20.0,20.0,0.25);
   glTranslatef(0.0,1.0,-81.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(.25,20.0,20.0);
   glTranslatef(-81.0,1.0,0.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(.25,20.0,20.0);
   glTranslatef(81.0,1.0,0.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   if (!wire) {
     glEnable(GL_LIGHTING);
   
     glMaterialfv(GL_FRONT, GL_DIFFUSE, dgray);
     glMaterialfv(GL_FRONT, GL_EMISSION, black); /* turn it off before painting the balls */
   }

   /* move the balls and shrapnel */
   updateballs(&gp->bman);

   glFrontFace(GL_CCW);
   for (i=0;i<gp->bman.num_balls;i++) {
      if (gp->bman.balls[i].justcreated) {
	 gp->bman.balls[i].justcreated = FALSE;
	 freetris(&gp->tman[i]);
      }
      if (gp->bman.balls[i].bounced) { 
	 if (gp->tman[i].vertices == NULL) {
	    createtrisfromball(&gp->tman[i],gp->spherev,gp->spherei,SPHERE_INDICES,&gp->bman.balls[i]);
	 } else {
	    updatetris(&gp->tman[i]);
	 }
	 glDisable(GL_CULL_FACE);
	 mi->polygon_count += drawtriman(&gp->tman[i], wire);
	 if (!wire) glEnable(GL_CULL_FACE);
      } else {
         mi->polygon_count += drawball(gp, &gp->bman.balls[i], wire);
      }
   }
      
   glFlush();
}
Esempio n. 26
0
void Desenha_predio1 (void)
    {
      glutSolidCube(0.3);
      glFlush();
    }  
Esempio n. 27
0
File: dri3.c Progetto: sarnex/wine
BOOL
PRESENTPixmap(Display *dpy, XID window,
              PRESENTPixmapPriv *present_pixmap_priv, D3DPRESENT_PARAMETERS *pPresentationParameters,
              const RECT *pSourceRect, const RECT *pDestRect, const RGNDATA *pDirtyRegion)
{
    PRESENTpriv *present_priv = present_pixmap_priv->present_priv;
#ifdef D3DADAPTER9_DRI2
    struct DRI2priv *dri2_priv = present_pixmap_priv->dri2_info.dri2_priv;
    EGLenum current_api = 0;
#endif
    xcb_void_cookie_t cookie;
    xcb_generic_error_t *error;
    int64_t target_msc, presentationInterval;
    xcb_xfixes_region_t valid, update;
    int16_t x_off, y_off;
    uint32_t options = XCB_PRESENT_OPTION_NONE;

    pthread_mutex_lock(&present_priv->mutex_present);

    if (window != present_priv->window)
        PRESENTPrivChangeWindow(present_priv, window);

    if (!window) {
        ERR("ERROR: Try to Present a pixmap on a NULL window\n");
        pthread_mutex_unlock(&present_priv->mutex_present);
        return FALSE;
    }

    PRESENTflush_events(present_priv, FALSE);
    if (!present_pixmap_priv->released || present_pixmap_priv->present_complete_pending) {
        ERR("FATAL ERROR: Trying to Present a pixmap not released\n");
        pthread_mutex_unlock(&present_priv->mutex_present);
        return FALSE;
    }
#ifdef D3DADAPTER9_DRI2
    if (present_pixmap_priv->dri2_info.is_dri2) {
        current_api = eglQueryAPI();
        eglBindAPI(EGL_OPENGL_API);
        if(eglMakeCurrent(dri2_priv->display, EGL_NO_SURFACE, EGL_NO_SURFACE, dri2_priv->context)) {
            glBindFramebuffer(GL_READ_FRAMEBUFFER, present_pixmap_priv->dri2_info.fbo_read);
            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, present_pixmap_priv->dri2_info.fbo_write);

            glBlitFramebuffer(0, 0, present_pixmap_priv->width, present_pixmap_priv->height,
                              0, 0, present_pixmap_priv->width, present_pixmap_priv->height,
                              GL_COLOR_BUFFER_BIT, GL_NEAREST);
            glFlush(); /* Perhaps useless */
        } else {
            ERR("eglMakeCurrent failed with 0x%0X\n", eglGetError());
        }
        eglMakeCurrent(dri2_priv->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
        eglBindAPI(current_api);
    }
#endif
    target_msc = present_priv->last_msc;
    switch(pPresentationParameters->PresentationInterval) {
        case D3DPRESENT_INTERVAL_DEFAULT:
        case D3DPRESENT_INTERVAL_ONE:
            presentationInterval = 1;
            break;
        case D3DPRESENT_INTERVAL_TWO:
            presentationInterval = 2;
            break;
        case D3DPRESENT_INTERVAL_THREE:
            presentationInterval = 3;
            break;
        case D3DPRESENT_INTERVAL_FOUR:
            presentationInterval = 4;
            break;
        case D3DPRESENT_INTERVAL_IMMEDIATE:
        default:
            presentationInterval = 0;
            options |= XCB_PRESENT_OPTION_ASYNC;
            break;
    }
    target_msc += presentationInterval * (present_priv->pixmap_present_pending + 1);

    /* Note: PRESENT defines some way to do partial copy:
     * presentproto:
     * 'x-off' and 'y-off' define the location in the window where
     *  the 0,0 location of the pixmap will be presented. valid-area
     *  and update-area are relative to the pixmap.
     */
    if (!pSourceRect && !pDestRect && !pDirtyRegion) {
        valid = 0;
        update = 0;
        x_off = 0;
        y_off = 0;
    } else {
        xcb_rectangle_t rect_update;
        xcb_rectangle_t *rect_updates;
        int i;

        rect_update.x = 0;
        rect_update.y = 0;
        rect_update.width = present_pixmap_priv->width;
        rect_update.height = present_pixmap_priv->height;
        x_off = 0;
        y_off = 0;
        if (pSourceRect) {
            x_off = -pSourceRect->left;
            y_off = -pSourceRect->top;
            rect_update.x = pSourceRect->left;
            rect_update.y = pSourceRect->top;
            rect_update.width = pSourceRect->right - pSourceRect->left;
            rect_update.height = pSourceRect->bottom - pSourceRect->top;
        }
        if (pDestRect) {
            x_off += pDestRect->left;
            y_off += pDestRect->top;
            rect_update.width = pDestRect->right - pDestRect->left;
            rect_update.height = pDestRect->bottom - pDestRect->top;
            /* Note: the size of pDestRect and pSourceRect are supposed to be the same size
             * because the driver would have done things to assure that. */
        }
        valid = xcb_generate_id(present_priv->xcb_connection_bis);
        update = xcb_generate_id(present_priv->xcb_connection_bis);
        xcb_xfixes_create_region(present_priv->xcb_connection_bis, valid, 1, &rect_update);
        if (pDirtyRegion && pDirtyRegion->rdh.nCount) {
            rect_updates = (void *) calloc(pDirtyRegion->rdh.nCount, sizeof(xcb_rectangle_t));
            for (i = 0; i < pDirtyRegion->rdh.nCount; i++)
            {
                RECT rc;
                memcpy(&rc, pDirtyRegion->Buffer + i * sizeof(RECT), sizeof(RECT));
                rect_update.x = rc.left;
                rect_update.y = rc.top;
                rect_update.width = rc.right - rc.left;
                rect_update.height = rc.bottom - rc.top;
                memcpy(rect_updates + i * sizeof(xcb_rectangle_t), &rect_update, sizeof(xcb_rectangle_t));
            }
            xcb_xfixes_create_region(present_priv->xcb_connection_bis, update, pDirtyRegion->rdh.nCount, rect_updates);
            free(rect_updates);
        } else
            xcb_xfixes_create_region(present_priv->xcb_connection_bis, update, 1, &rect_update);
    }
    if (pPresentationParameters->SwapEffect == D3DSWAPEFFECT_COPY)
        options |= XCB_PRESENT_OPTION_COPY;
    cookie = xcb_present_pixmap_checked(present_priv->xcb_connection_bis,
                                        window,
                                        present_pixmap_priv->pixmap,
                                        present_pixmap_priv->serial,
                                        valid, update, x_off, y_off,
                                        None, None, None, options,
                                        target_msc, 0, 0, 0, NULL);
    error = xcb_request_check(present_priv->xcb_connection_bis, cookie); /* performs a flush */

    if (update)
        xcb_xfixes_destroy_region(present_priv->xcb_connection_bis, update);
    if (valid)
        xcb_xfixes_destroy_region(present_priv->xcb_connection_bis, valid);

    if (error) {
        xcb_get_geometry_cookie_t cookie_geom;
        xcb_get_geometry_reply_t *reply;

        cookie_geom = xcb_get_geometry(present_priv->xcb_connection_bis, window);
        reply = xcb_get_geometry_reply(present_priv->xcb_connection_bis, cookie_geom, NULL);

        ERR("Error using PRESENT. Here some debug info\n");
        if (!reply) {
            ERR("Error querying window info. Perhaps it doesn't exist anymore\n");
            pthread_mutex_unlock(&present_priv->mutex_present);
            return FALSE;
        }
        ERR("Pixmap: width=%d, height=%d, depth=%d\n",
            present_pixmap_priv->width, present_pixmap_priv->height,
            present_pixmap_priv->depth);
        ERR("Window: width=%d, height=%d, depth=%d, x=%d, y=%d\n",
            (int) reply->width, (int) reply->height,
            (int) reply->depth, (int) reply->x, (int) reply->y);
        ERR("Present parameter: PresentationInterval=%d, BackBufferCount=%d, Pending presentations=%d\n",
            pPresentationParameters->PresentationInterval,
            pPresentationParameters->BackBufferCount,
            present_priv->pixmap_present_pending
           );
        if (present_pixmap_priv->depth != reply->depth)
            ERR("Depths are different. PRESENT needs the pixmap and the window have same depth\n");
        free(reply);
        pthread_mutex_unlock(&present_priv->mutex_present);
        return FALSE;
    }
    present_priv->last_target = target_msc;
    present_priv->pixmap_present_pending++;
    present_pixmap_priv->present_complete_pending = TRUE;
    present_pixmap_priv->released = FALSE;
    pthread_mutex_unlock(&present_priv->mutex_present);
    return TRUE;
}
Esempio n. 28
0
void PrimaryGLContext::EndDraw() {
    glFlush();

    CheckGLError();
}
Esempio n. 29
0
	//Call this when your program is about to exit
	void OpenGL::Exit()
	{
		glFlush();
		glfwTerminate();
		glfwCloseWindow();
	}
Esempio n. 30
0
void device_flush(device_t device)
{
	glFlush();

	UNUSED_PARAMETER(device);
}