コード例 #1
0
ファイル: Window-018.cpp プロジェクト: Haynesy/Swiftless
/*
    Function: Runs the application display
    Flow:
        - Check key operations as they may have adverse effects on the
            display state e.g may require the display matrix to move forward
        - Set Clear color ( RED in this case )
        - Clear the color buffer ( Using GL_COLOR_BUFFER_BIT )
            information in other buffers will come later
        - Load the Identity Matrix ( Poorly named me thinks )
            to reset our drawing locations
        - Move the camera to look in the required direction
        - Render object to screen ( Will render at location: 0, 0, -5 )
        - Swap buffers
        - Calcualte transofrmations for object
    End State:
        Rendering of picture to the the window of the application

*/
void display(void)
{
    /*
        Check any keyboard operations that may alter the display of the
        next frame
    */
    keyOperations();
    keySpecialOperations();

	texture = LoadTexture("texture.raw", 256, 256);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture);

    // Clear color is set to RED
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // Clear the color buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();

    // Set lights up
    GLfloat DiffuseLight[] = { diffuseLightRed, diffuseLightGreen, diffuseLightBlue };
    GLfloat AmbientLight[] = { ambientLightRed, ambientLightGreen, ambientLightBlue };
    glLightfv (GL_LIGHT0, GL_DIFFUSE, DiffuseLight); //change the light accordingly
    glLightfv (GL_LIGHT1, GL_AMBIENT, AmbientLight); //change the light accordingly

    // Set light position
    GLfloat LightPosition[] = {lightX, lightY, lightZ, lightW}; // lightW indicates if it is a point light
    glLightfv (GL_LIGHT0, GL_POSITION, LightPosition); //change the light accordingly



    // Reset Identity Matrix
    //glLoadIdentity();
    
    // Light the scene
    //light();

    // Look at a point
    gluLookAt (ViewPositionX, ViewPositionY, ViewPositionZ - 10.0, 
	 	ViewPositionX, ViewPositionY, ViewPositionZ, 0.0, 1.0, 0.0);

    // Render objects
    //renderPrimitive();
	 glTranslatef(0, 0, -5);
	 glCallList(cubelist);

	// Swap the old buffer out for the new rendered image
    glutSwapBuffers();

    // Increase angle
    angle += 0.1;
}
コード例 #2
0
ファイル: Window-007.cpp プロジェクト: Haynesy/Swiftless
/*
    Function: Runs the application display
    Flow:
        - Check key operations as they may have adverse effects on the 
            display state e.g may require the display matrix to move forward
        - Set Clear color ( RED in this case )
        - Clear the color buffer ( Using GL_COLOR_BUFFER_BIT )
            information in other buffers will come later
        - Load the Identity Matrix ( Poorly named me thinks )
            to reset our drawing locations
        - Move the scene back 5 units as the camera is located at ( 0, 0, 0 )
        - Render object to screen ( Will render at location: 0, 0, -5 )
        - Flush all calls from OpenGL to the window
    End State:
        Rendering of picture to the the window of the application

*/
void display(void)
{
    /*  
        Check any keyboard operations that may alter the display of the
        next frame 
    */
    keyOperations();
    keySpecialOperations();
    
    // Clear color is set to RED
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

    // Clear the color buffer
    glClear(GL_COLOR_BUFFER_BIT);

    // Reset Identity Matrix
    glLoadIdentity();

    // Move the scene 5 units back as the camera will be located at ( 0, 0, 0 )
    glTranslatef(0.0f, 0.0f, -5.0f);
    
    // Transformation and Rotation code
    glTranslatef(0.0f, yLocation, 0.0f);
    glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f);
    
    // Render our objects
    //renderPrimitive();
    glutWireCube(2.0f);
    
    // Flush all commands to the window
    glFlush();


    // Update object position ( Rotation and Translation)
    if ( movingUp )
        yLocation -= 0.005f;
    else
        yLocation += 0.005f;

    if ( yLocation < -3.0f )
        movingUp = false;
    else if ( yLocation > 3.0f )
        movingUp = true;
    
    yRotationAngle += 0.005f;
    if ( yRotationAngle > 360.0f )
        yRotationAngle -= 360.0f;
}
コード例 #3
0
ファイル: main2.cpp プロジェクト: 9036356186/3D-Game
void drawScene()
{
    GLfloat x,y,z;
        
    glColor3f(1.0f,1.0f,1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glPushMatrix();
    keySpecialOperations();/*
    if(keyStates['w'])
    {
         fprintf(stdout,"* cameraz=%f\nreferencez=%f\n",cameraz,referencez);
    }*/
    //gluLookAt(-5*TRACK_WIDTH-13.5,12,18,-TRACK_WIDTH-13.5,2,-1,0,1,0);
    gluLookAt(camerax,cameray,cameraz,referencex,referencey,referencez,upx,upy,upz);
    // tack draw
    trackStraight(-(TRACK_WIDTH/2.0f),(TRACK_WIDTH/2.0f),-(6*TorusRadius),0);
    trackStraight(-(TRACK_WIDTH/2.0f),(TRACK_WIDTH/2.0f),0,3*CAR_LENGTH);
    bumpdraw(-(TRACK_WIDTH/2.0f)-1.5,CAR_LENGTH,1);
    BumpyTrack(-(TRACK_WIDTH/2.0f),(TRACK_WIDTH/2.0f),3*CAR_LENGTH,6*CAR_LENGTH,(TorusRadius/2.0f));
    trackStraight(-(TRACK_WIDTH/2.0f),(TRACK_WIDTH/2.0f),6*CAR_LENGTH,9*CAR_LENGTH);
    bumpdraw((TRACK_WIDTH/2.0f),6*CAR_LENGTH,0);
    for(GLint i=0;i<=3*GRASS_WIDTH;i+=GRASS_WIDTH)
    {
          grass(-(TRACK_WIDTH/2.0f)-i,(TRACK_WIDTH/2.0f)-i,-(6*TorusRadius),0);
          grass(-(TRACK_WIDTH/2.0f)-i,(TRACK_WIDTH/2.0f)-i,1,3*CAR_LENGTH);
          grass(-(TRACK_WIDTH/2.0f)-i,(TRACK_WIDTH/2.0f)-i,3*CAR_LENGTH+1,6*CAR_LENGTH);
          grass(-(TRACK_WIDTH/2.0f)-i,(TRACK_WIDTH/2.0f)-i,6*CAR_LENGTH+1,9*CAR_LENGTH-1);
    }
    turnleft(-(TRACK_WIDTH/2.0f)-1,6*CAR_LENGTH,1);
    trackTurnLeft(-(TRACK_WIDTH/2.0f),(TRACK_WIDTH/2.0f),9*CAR_LENGTH,13*CAR_LENGTH,0,180.0f);
    trackStraight(-5*TRACK_WIDTH-2.25,-4*TRACK_WIDTH-2.25,6*CAR_LENGTH,9*CAR_LENGTH);
    BumpyTrack(-5*TRACK_WIDTH-2.25,-4*TRACK_WIDTH-2.25,3*CAR_LENGTH,6*CAR_LENGTH,(TorusRadius/2.0f));
    trackStraight(-5*TRACK_WIDTH-2.25,-4*TRACK_WIDTH-2.25,0,3*CAR_LENGTH);
    trackStraight(-5*TRACK_WIDTH-2.25,-4*TRACK_WIDTH-2.25,-(6*TorusRadius),0);
    trackTurnLeft(-(TRACK_WIDTH/2.0f),(TRACK_WIDTH/2.0f),-1.2*CAR_LENGTH,2.8*CAR_LENGTH,180.0f,355.5f);
    //trackTurnRight(-(int)(TRACK_WIDTH/2.0f)-1,(int)(TRACK_WIDTH/2.0f),8*CAR_LENGTH,12*CAR_LENGTH,180.0f);
    glTranslatef(0.0f,TorusRadius-(TorusRadius/2.75),0.0f);
    glScalef(0.5f,0.5f,0.5f);
    assembly();
    glScalef(2.0f,2.0f,2.0f);
    glTranslatef(0.0f,-TorusRadius+(TorusRadius/2.75),0.0f);
    glFlush();
    glPopMatrix();   
}