コード例 #1
0
ファイル: MotionBlur.cpp プロジェクト: Ninglin/OpenGLSamples
// Renders the result of the "MotionBlur" sample for comparison purposes.
// NOTE: this cannot show fullscreen motion blur.
void MotionBlur::renderSceneBlurred(const nv::matrix4f& houseXform,
                                    const nv::matrix4f& sailsXform,
                                    const nv::matrix4f& prevSailsXform) const
{    
    // Render to color/depth FBO
    glBindFramebuffer(GL_FRAMEBUFFER, mFboID);
    glViewport(0, 0, NvSampleApp::m_width, NvSampleApp::m_height);

    // Black
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawModelUnblurred(mSailsModel, sailsXform);

    // Pass 2: Render the motion blurred moving geometry over static geometry.
    // Render the Static geometry's depth, Use pass2 (color texture) as motion
    // blur lookup and write onto Pass1 (color texture).
    glBindFramebuffer(GL_FRAMEBUFFER, getMainFBO());
    glViewport(0, 0, NvSampleApp::m_width, NvSampleApp::m_height);

    // Yellow, high-contrast if we're not showing the sky box.
    glClearColor(1.0f, 1.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawModelUnblurred(mHouseModel, houseXform);
    glDepthMask(false);
    drawSkybox();
    drawModelBlurred(mSailsModel, sailsXform, prevSailsXform);
    glDepthMask(true);
}
コード例 #2
0
void GlobalScene::draw()
{

    drawSkybox();
    drawGround();
    drawWalls();
    drawPillarsAndTorches();
    glRotatef(90, 1, 0, 0);
    glTranslatef(15, 5, -15);
    dragon->draw();

}
コード例 #3
0
ファイル: model_viewer.cpp プロジェクト: Knugn/CG-A3
void display(Context &ctx)
{
    glClearColor(ctx.background_color[0], ctx.background_color[1], ctx.background_color[2], 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	drawSkybox(ctx);
	glDepthMask(GL_TRUE);

    glEnable(GL_DEPTH_TEST); // ensures that polygons overlap correctly
    drawMesh(ctx, ctx.program, ctx.meshVAO);
}
コード例 #4
0
ファイル: MotionBlur.cpp プロジェクト: Ninglin/OpenGLSamples
// Renders the color buffer for the scene and skybox
void MotionBlur::renderSceneUnblurred(const nv::matrix4f& houseXform,
                                      const nv::matrix4f& sailsXform) const
{
    // Render to framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, getMainFBO());
    glViewport(0, 0, NvSampleApp::m_width, NvSampleApp::m_height);

    // Yellow, high-contrast if we're not showing the sky box.
    glClearColor(1.0f, 1.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawModelUnblurred(mSailsModel, sailsXform);
    drawModelUnblurred(mHouseModel, houseXform);
    glDepthMask(false);
    drawSkybox();
    glDepthMask(true);
}
コード例 #5
0
/*
Main rendering function. Note how it's essentially the same as the
ones you were writing in OpenGL! We start by clearing the buffer,
render some stuff, then swap the buffers. All that's different is
some slightly different matrix access.

*/
void Renderer::RenderScene()
{
	set_viewport();
	clear_buffer();

	drawSkybox();

	//fillBuffers();
	//drawPointLights();
	//combineBuffers();
	
	simpleLighting();
	
	swap_buffers();

	//std::cout << "Not crashed!!" << std::endl;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: tuzz/come_fly_with_me
//Main display loop.
void display() {
  //Clear buffers.
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  //Augment camera, draw skybox.
  updateCamera();
  drawSkybox();

  //Scale the world and reset light positions.
  glScalef(SCALE_FACTOR, SCALE_FACTOR, SCALE_FACTOR);
  augmentLights();

  //Draw the plane containing clouds and the main scene.
  drawCloudPlane();
  drawScene();

  //Swap buffers.
  glutSwapBuffers();
}
コード例 #7
0
ファイル: RollerCoaster.c プロジェクト: RyGuyM/Roller-Coaster
/* Initialize anything necessary to set up the scene for the roller coaster simulation. */
void init(void){
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    
    // Read in the control points from a file, first lets test without that feature.
    leftRail = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    rightRail = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    centerRail = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    columnTopRight = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    columnTopLeft = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    qValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    dqValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    ddqValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    uValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    vValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    nValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    calculateVectors();
    
    // Generate a display list that will hold the scene.
    scene = glGenLists(1);
    glNewList(scene, GL_COMPILE);
        // Draw the ground and colour it green.
        drawGround();
    
        // Draw the sky and colour it blue.
        drawSkybox();
        // Draw the coaster.
        drawCurve();
    
        // Draw the connection pieces for the rails.
        drawConnectors();
    
        // Draw the columnst that support the rails.
        drawColumns();
    glEndList();
}
コード例 #8
0
ファイル: glutwidget.cpp プロジェクト: Kurispy/city
/*
    Redraws window contents
 */
void glutWidget::render()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     //clears color and depth bits of framebuffer
    
    //Convenience variables
    float t = (float) ((int) (((float) clock()) * 50.0 / CLOCKS_PER_SEC) % 30) / 30.0;
    int t2 = ((int) (((float) clock()) * 50.0 / CLOCKS_PER_SEC) % 240) / 30;
    float t3 = (float) clock() * 5.0 / CLOCKS_PER_SEC;
    
    //These are the control points for the bezier curves
    GLfloat curves[8][4][3] =
    {
        {
            {-8, 0, -8.5},
            {-7, 0, -8.5},
            {-5, 0, -8.5},
            {-4, 0, -8.5}
        },
        {
            {-4, 0, -8.5},
            {-3.5, 0, -8.5},
            {-3.5, 0, -8.5},
            {-3.5, 0, -8}
        },
        {
            {-3.5, 0, -8},
            {-3.5, 0, -7},
            {-3.5, 0, -5},
            {-3.5, 0, -4}
        },
        {
            {-3.5, 0, -4},
            {-3.5, 0, -3.5},
            {-3.5, 0, -3.5},
            {-4, 0, -3.5}
        },
        {
            {-4, 0, -3.5},
            {-5, 0, -3.5},
            {-7, 0, -3.5},
            {-8, 0, -3.5}
        },
        {
            {-8, 0, -3.5},
            {-8.5, 0, -3.5},
            {-8.5, 0, -3.5},
            {-8.5, 0, -4}
        },
        {
            {-8.5, 0, -4},
            {-8.5, 0, -5},
            {-8.5, 0, -7},
            {-8.5, 0, -8}
        },
        {
            {-8.5, 0, -8},
            {-8.5, 0, -8.5},
            {-8.5, 0, -8.5},
            {-8, 0, -8.5}
        }
    };
    
    
    //Manually evaluate the bezier curves
    float s = 1 - t;
    float AB[2] = {curves[t2][0][0]*s + curves[t2][1][0]*t, curves[t2][0][2]*s + curves[t2][1][2]*t};
    float BC[2] = {curves[t2][1][0]*s + curves[t2][2][0]*t, curves[t2][1][2]*s + curves[t2][2][2]*t};
    float CD[2] = {curves[t2][2][0]*s + curves[t2][3][0]*t, curves[t2][2][2]*s + curves[t2][3][2]*t};
    float ABC[2] = {AB[0]*s + BC[0]*t, AB[1]*s + BC[1]*t};
    float BCD[2] = {BC[0]*s + CD[0]*t, BC[1]*s + CD[1]*t};
    float pos[2] = {ABC[0]*s + BCD[0]*t, ABC[1]*s + BCD[1]*t};
    float slope = (ABC[1] - BCD[1]) / (ABC[0] - BCD[0]);
    float theta = atan(slope);
    
    //Rotation/translation matrix
    float matrix[4][4] = 
    {
        {cos(theta), 0, -sin(theta), 0},
        {0, 1, 0, 0},
        {sin(theta), 0, cos(theta), 0},
        {pos[0], 0.01, pos[1], 1}
    };
    
    //Keep the texture pointing in the right direction throughout the loop
    if((ABC[0] - BCD[0]) < 0)
    {
        matrix[0][2] = -(matrix[0][2]);
        matrix[2][0] = -(matrix[2][0]);
    }
    else if((ABC[0] - BCD[0]) > 0)
    {
        matrix[0][0] = -(matrix[0][0]);
        matrix[2][2] = -(matrix[2][2]);
    }
    
    
    
    //Draw streets
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, street_texture);
    glUseProgram(m_program);
    glBegin(GL_TRIANGLE_STRIP);
    
    glTexCoord2f(0,1);
    glNormal3f(0,1,0);
    glVertex3f(-10,0,-10);
    
    glTexCoord2f(0,0);
    glNormal3f(0,1,0);
    glVertex3f(-10,0,10);
    
    glTexCoord2f(1,1);
    glNormal3f(0,1,0);
    glVertex3f(10,0,-10);
    
    glTexCoord2f(1,0);
    glNormal3f(0,1,0);
    glVertex3f(10,0,10);
    
    glEnd();
    glUseProgram(0);
    glDisable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);
    //
    
    //Draw cars
    for (int i = 0; i < 9; i++) {
        matrix[3][0] = pos[0] + ((i % 3) * 6);
        matrix[3][2] = pos[1] + ((i / 3) * 6);
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glMultMatrixf(matrix[0]);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, car_texture);
        glUseProgram(m_program);

        drawCar();

        glUseProgram(0);
        glDisable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 0);
        glPopMatrix();
        
        if (i+1 == camera) {
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            gluLookAt(matrix[3][0],0.5,matrix[3][2],sin(roty)+matrix[3][0],sin(rotx)+0.2,-cos(roty)+matrix[3][2],0,1,0); //Camera rotation/translation is done here
        }
    }
    //
    
    //Draw structures
    for (int i = 0; i < 9; i++) {
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glTranslatef((i % 3) * 6, 0, (i / 3) * 6);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, structure_texture);
        glUseProgram(m_program);
        
        drawStructure();
        
        glUseProgram(0);
        glDisable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 0);
        glPopMatrix();
    }
    //
    
    //Draw skybox
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, skybox_texture);
    glUseProgram(m_program);
    
    drawSkybox();
    
    glUseProgram(0);
    glDisable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);
    //
    
    //Draw walls
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, wall_texture);
    glUseProgram(m_program);
    
    drawWalls();
    
    glUseProgram(0);
    glDisable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);
    //
    
    if (!camera) {
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(cposx,0.25,cposz,sin(roty)+cposx,sin(rotx)+cposy,-cos(roty)+cposz,0,1,0); //Camera rotation/translation is done here
    }
    
    glutSwapBuffers();  //swaps front and back buffer for double buffering
}
コード例 #9
0
void display()
{
	displayPrev = displayCurrent;
	displayCurrent = clock();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


	if (drawHeightmapFlag){

		drawHeightmap();
		glutSwapBuffers();
		return;
	}


	if (drawFogFlag){
		glEnable(GL_FOG);
		glFogf(GL_FOG_MODE, GL_EXP);
		glFogf(GL_FOG_DENSITY, 0.008);
		GLfloat fogColor[4] = { 0.3f, 0.3f, 0.3f, 1.0f };      // Fog Color
		glFogfv(GL_FOG_COLOR, fogColor);
	}
	else{
		glDisable(GL_FOG);
	}




	//Vale tin kamera
	glLoadIdentity();
	gluLookAt(cameraPosition[0], cameraPosition[1], cameraPosition[2],
		0, 0, 0,
		0, 1, 0);


	

	//Draw Skybox
	if (drawSkyboxFlag){
		drawSkybox();
	}

	// Draw Terrain
	drawTerrain();

	//Draw Sea
	if (drawSeaFlag){
		drawSea();
	}

	drawSun();





	//Add Light
	glEnable(GL_NORMALIZE);
	glEnable(GL_LINEAR_ATTENUATION);
	glShadeModel(GL_SMOOTH);
	float zeros[3] = { 0, 0, 0 };

	glMaterialfv(GL_FRONT, GL_EMISSION, zeros);
	GLfloat lightPos[] = { lightPosition[0], lightPosition[1], lightPosition[2], 1 };
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);


	glutSwapBuffers();
}
コード例 #10
0
ファイル: lab2-8.c プロジェクト: lulzmachine/OpenGLHF
void display()
{
  // This function is called whenever it is time to render
  //  a new frame; due to the idle()-function below, this
  //  function will get called several times per second

  // Clear framebuffer & zbuffer
  glClearColor(0.3, 0, 0, 1);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Position light 0
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  GLfloat light_position[] = { 0.0, 0.0, -1.0, 0.0 };
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  //glLoadMatrixd(getCameraMatrix());
  GLfloat light_position1[] = { -10.0, 10.0, 20.0, 1.0 };
  glLightfv(GL_LIGHT1, GL_POSITION, light_position1);

  GLfloat ambientColor [] = { 0.0, 0.0, 0.0, 0.0 };
  GLfloat diffuseColor[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat specularColor[] = { 1.0, 1.0, 1.0, 1.0 };
  glLightfv(GL_LIGHT1, GL_AMBIENT, ambientColor);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseColor);
  glLightfv(GL_LIGHT1, GL_SPECULAR, specularColor);

  //Enable lighting and light 0
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_NORMALIZE);

  // Set default material properties
  GLfloat mat_shininess[] = { 50.0 };
  GLfloat mat_diffuseColor[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat mat_specularColor[] = { 1.0, 1.0, 1.0, 1.0 };

  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuseColor);
  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specularColor);

  // Setup projection matrix
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(90, 1, 0.01, 500);

  // Setup object matrix
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glLoadMatrixd(getCameraMatrix());

  // Enable Z-buffering
  glEnable(GL_DEPTH_TEST);

  // Enable Gouraud shading
  glShadeModel(GL_SMOOTH);

  // Enable texturing
  glEnable(GL_TEXTURE_2D);


  // Enable backface culling
  glEnable(GL_CULL_FACE);
  glCullFace(GL_BACK);
  drawSkybox();

// the floooor  
glBindTexture(GL_TEXTURE_2D, textureId);
  int more_floor = 200;
  int mf = more_floor;
  glBegin(GL_POLYGON);
  glNormal3f(0,1,0);
  glTexCoord2f(0, 0);
  glVertex3f(-mf,0, -mf);
  glTexCoord2f(0, 1);
  glVertex3f(-mf,0, mf);
  glTexCoord2f(1, 1);
  glVertex3f(mf,0, mf);
  glTexCoord2f(1,0);
  glVertex3f(mf, 0, -mf);
  glEnd();
  glDisable(GL_TEXTURE_2D);

 
  glPushMatrix();
  drawWindmill();
  glTranslatef(25,0,0);
  drawWindmill();
  glTranslatef(-50,0,40);
  drawWindmill();
  glPopMatrix();
  // Draw cube using array-based API

  glPushMatrix();
  //glRotatef(-56, 0, 0, 1);
  glTranslatef(0, 10*fabs(sin(3.14*getElapsedTime()))+2.5, 30);
  glRotatef((360*getElapsedTime()) / 6, 0, 1, 0);
  glTranslatef(-80, 0, -80);
  glRotatef(-45, 0, 1, 0);
  glScalef(5, 5, 5);
  //glRotatef(0, 1, 0, to_draw * 90);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);
  glVertexPointer(3, GL_FLOAT, 0, bunny->vertexArray);
  glNormalPointer(GL_FLOAT, 0, bunny->normalArray);
  glDrawElements(GL_TRIANGLES, bunny->numIndices, GL_UNSIGNED_INT, bunny->indexArray);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(50, 0, 75);
  glRotatef(-56, 1, 1, 0);
  glScalef(30, 30, 30);
  //glRotatef(0, 1, 0, to_draw * 90);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);
  glVertexPointer(3, GL_FLOAT, 0, klingoff->vertexArray);
  glNormalPointer(GL_FLOAT, 0, klingoff->normalArray);
  glDrawElements(GL_TRIANGLES, klingoff->numIndices, GL_UNSIGNED_INT, klingoff->indexArray);
  glPopMatrix();

  // Swap front- and backbuffers
  glutSwapBuffers();
}
コード例 #11
0
ファイル: quiddiards.cpp プロジェクト: silencious/Quiddiards
void Quiddiards::paintGL(){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glClear(GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	/* set camera */
	QMatrix4x4 mat;				// identity matrix
	mat.rotate(phi, 0, 0, 1);	// rotate phi around z axis
	mat.rotate(theta, 1, 0, 0);	// rotate around x axis
	mat.rotate(theta, 0, 1, 0);	// rotate around y axis
	eye = mat * QVector3D(0, 0, radius);
	QVector3D up = QVector3D::crossProduct(eye, { -eye.y(), eye.x(), 0.0f });	// note: coord system is left-handwise
	switch (camera){
	case FOLLOW:
		center = cueball.getCenter();
		break;
	case OVER:
		center = { 0, 0, table.getDamHgt() };
		break;
	case FREE:
		break;
	default:
		break;
	}

	gluLookAt(eye.x() + center.x(), eye.y() + center.y(), eye.z() + center.z(), center.x(), center.y(), center.z(), up.x(), up.y(), up.z());

	/* enable or disable lights based on setting */
	if (ambLight){
		static GLfloat modAmb[] = { 0.4f, 0.4f, 0.4f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modAmb);
	}
	else{
		static GLfloat modAmb[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modAmb);
	}
	if (sunLight){
		static GLfloat sunPos[] = { 1.0f, 1.0f, 1.0f, 0.0f };
		glLightfv(GL_LIGHT0, GL_POSITION, sunPos);
		glEnable(GL_LIGHT0);
	}
	else{
		glDisable(GL_LIGHT0);
	}
	if (spotLight){
		spotPos = { cueball.getX(), cueball.getY(), cueball.getZ() + 5.0f, 1.0f };
		QVector3D dir = cueball.getCenter() - spotPos.toVector3D();
		glLightfv(GL_LIGHT1, GL_POSITION, (float*)&spotPos);
		glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, (float*)&dir);
		glEnable(GL_LIGHT1);
	}
	else{
		glDisable(GL_LIGHT1);
	}

	/* start drawing */
	glEnable(GL_TEXTURE_2D);
	/* draw scene */
	drawSkybox();
	drawGround();
	//drawTable();
	/* draw quaffles */
	for (unsigned i = 0; i < QUAFNUM; i++){
		drawBall(quaffles[i]);
	}
	/* draw bludgers */
	for (unsigned i = 0; i < BLUGNUM; i++){
		drawBall(bludgers[i]);
	}
	/* draw snitch */
	drawBall(snitch);
	/* draw cueball */
	drawBall(cueball);
	//if (operable){
	//	drawCueBroom();
	//}
	for (int i = 0; i < FLAGNUM; i++){
		drawFlag(flags[i]);
	}
	glDisable(GL_TEXTURE_2D);
	if (ps->isActive()){
		renderPS();
	}
}
コード例 #12
0
ファイル: lab3-4.c プロジェクト: Nicsi918/Labs
void display(void)
{
	checkKeyDowns();
	printError("pre display");
	
	GLfloat t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);
	
    mat4 projection = frustum(left, right, bottom, top, near, far);
        
    mat4 view = lookAtv(p, l, v);
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    vec3 nollV = SetVector(0.0f, 0.0f, 0.0f);
    
    drawSkybox(view, projection);
    
   glUseProgram(program);

	int j;
	for (j = 0; j < nrOfMills * nrOfMills; j++)
	{
   	 	UploadObjectMatricesVec(windmills[j].pos, 0.0f, view, projection, program);       
  	 	DrawModel(m, program, "in_Position", "in_Normal", "inTexCoord");
   	
   		UploadObjectMatricesVec(windmills[j].pos, 0.0f, view, projection, program);    
  		DrawModel(m2, program, "in_Position", "in_Normal", "inTexCoord");
   
   		UploadObjectMatricesVec(windmills[j].pos, 0.0f, view, projection, program);    
   		DrawModel(m3, program, "in_Position", "in_Normal", "inTexCoord");

   
   		vec3 rAxis = SetVector(1.0f, 0.0f, 0.0f);
   
   		int i;
   		for (i = 0; i < 4; i++)
   		{
   			float x = windmills[j].pos.x;
   			float y = windmills[j].pos.y;
   			float z = windmills[j].pos.z;
   			UploadObjectMatricesArbRot(x + 5.0f, y + 9.0f, z + 0.0f, rAxis, 1.6f * i + t / 720, view, projection, program);    
   			DrawModel(blade, program, "in_Position", "in_Normal", NULL);
   		}
   
	}
    
   glUseProgram(terrainProgram);
   mat4 totMatrix = T(0.0, 0.0, 0.0);
   totMatrix = Mult(view, totMatrix);
   totMatrix = Mult(projection, totMatrix);
   glUniformMatrix4fv(glGetUniformLocation(terrainProgram, "totMatrix"), 1, GL_TRUE, totMatrix.m);

   glBindVertexArray(vertexArrayObjID);	// Select VAO
	glDrawArrays(GL_TRIANGLES, 0, 6*3);	// draw object
	
   //mat4 totMatrix = Mult(view, transMatrix);
   //totMatrix = Mult(projection, totMatrix);
   //glUniformMatrix4fv(glGetUniformLocation(terrainProgram, "totMatrix"), 1, GL_TRUE, totMatrix.m);
   
	printError("display");
	glutSwapBuffers();
}
コード例 #13
0
ファイル: Main.c プロジェクト: TJGreen0211/OpenGLSolar
int main(int argc, char *argv[])
{
	chdir("/Users/tjgreen/Documents/OpenGL/Sol");
	
	GLFWwindow *window = setupGLFW();
	GLuint skyboxTexture = initCubemap();
	
	//GLFWwindow* window2 = glfwCreateWindow(500, 500, "SolarSystem", NULL, NULL);
	//glfwMakeContextCurrent(window2);
	
	/*Cross platform compatibility stuff uncomment if not on mac
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
  		printf(stderr, "Error: %s\n", glewGetErrorString(err));
	}*/
	
	sunTexture = loadTexture("include/textures/Planets/sun2.jpg");
	sunNormal = loadTexture("include/textures/Planets/sunNormal.png");
	planetBuilder();
	init();
	createPerspectiveMatrix();
	
	initializePlanetButtons();
	
	glEnable(GL_CULL_FACE);
	glEnable(GL_MULTISAMPLE);
	glCullFace(GL_BACK);
	attachGUIShaders();
	
	float fpsFrames= 0;
	float lastTime = 0;
	while(!glfwWindowShouldClose(window))
	{
		GLfloat currentFrame = glfwGetTime();
        deltaTime = currentFrame - lastFrame;
        lastFrame = currentFrame;
        
        fpsFrames++;
		if(currentFrame - lastTime >= 1.0)
		{
			//printf("%f\n", 1000/fpsFrames);
			fpsFrames = 0;
			lastTime += 1.0;
		}
        
		glfwPollEvents();
		doMovement();
		
		glfwPollEvents();
		glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, WIDTH, HEIGHT);

		drawSkybox(skyboxTexture);
		drawSun();
		drawPlanet();
		//glFrontFace(GL_CW);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		drawAtmosphere();
		glDisable(GL_BLEND);
		//glFrontFace(GL_CCW);
		drawObj();
		drawMoon();
		
		//drawButton(button1);
		//drawPlanetButtons();
		
		if(stopRotation == 0){
			for(int i = 0; i < 11; i++)
			{
				orbitSpeedArray[i] += 0.1/planetInstanceArray[i].orbit;
			}
			for(int i = 0; i < 11; i++)
			{
				rotationSpeedArray[i] += 0.1/planetInstanceArray[i].day;
			}
			thetaY += 0.1;
		}
		
		glfwSwapBuffers(window);
	}
	
	glDeleteVertexArrays(1, &planetVAO);
    glDeleteBuffers(1, &planetVBO);
	
	glfwTerminate();
	return 0;
}
コード例 #14
0
void drawCam(int player) {
	int i;
	float up[3] = { 0, 0, 1 };
	Visual *d = & gPlayerVisuals[player].display;
	
	float reflectivity = getReflectivity();
	// compute shadow color based on glocal constant & reflectivity
	for(i = 0; i < 4; i++) 
		gCurrentShadowColor[i] = gShadowColor[i] * (1 - reflectivity);

	glColor3f(0.0, 1.0, 0.0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	doPerspective(gSettingsCache.fov, (float) d->vp_w / (float) d->vp_h,
		gSettingsCache.znear, box2_Diameter(& game2->level->boundingBox) * 6.5f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	{
		vec3 vLookAt;
		vec3 vTarget;
		matrix matRotate;

		vec3_Sub(&vLookAt, (vec3*)gPlayerVisuals[player].camera.target, (vec3*)gPlayerVisuals[player].camera.cam);
		vec3_Normalize(&vLookAt, &vLookAt);
		matrixRotationAxis(&matRotate, 90.0f * (float) gPlayerVisuals[player].camera.bIsGlancing, (vec3*)up);
		vec3_Transform(&vLookAt, &vLookAt, &matRotate);
		vec3_Add(&vTarget, (vec3*)gPlayerVisuals[player].camera.cam, &vLookAt);
		doLookAt(gPlayerVisuals[player].camera.cam, (float*)&vTarget, up);
	}

	glDisable(GL_LIGHTING); // initial config at frame start
	glDisable(GL_BLEND); // initial config at frame start

	// disable writes to alpha
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

	/* skybox */
	glDepthMask(GL_FALSE);
	glDisable(GL_DEPTH_TEST);

	drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );

	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	/* skybox done */

	/* floor */ 
	if(reflectivity == 0) {
		// draw floor to fb and stencil (set to 1),
		// using alpha-blending
		// TODO: draw floor alpha to fb
		video_Shader_Setup(& gWorld->floor_shader);
		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
		glStencilFunc(GL_ALWAYS, 1, 255);
		glEnable(GL_STENCIL_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		nebu_Mesh_DrawGeometry( gWorld->floor );
		glDisable(GL_BLEND);
		glDisable(GL_STENCIL_TEST);
		video_Shader_Cleanup(& gWorld->floor_shader);
	} else {
		/* reflections */
		/* first draw reflector to stencil */
		/* and reflector alpha to fb */

		video_Shader_Setup(& gWorld->floor_shader);

		// store only reflector alpha in framebuffer
		glDepthMask(GL_FALSE);
		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
		glStencilFunc(GL_ALWAYS, 1, 255);
		glEnable(GL_STENCIL_TEST);
		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
		// glEnable(GL_ALPHA_TEST);
		// glAlphaFunc(GL_GREATER, 0.1f);

		nebu_Mesh_DrawGeometry( gWorld->floor );
		
		// glDisable(GL_ALPHA_TEST);
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		glDepthMask(GL_TRUE);
		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
		glStencilFunc(GL_EQUAL, 1, 255);

		video_Shader_Cleanup(& gWorld->floor_shader);
		
		/* then draw world & skybox reflected, where stencil is set */
		/* protect the alpha buffer */
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

		isRenderingReflection = 1; // hack: reverse lighting
		glPushMatrix();
		glScalef(1,1,-1);
		glCullFace(GL_FRONT); // reverse culling
		// clip skybox & world to floor plane
		glEnable(GL_CLIP_PLANE0);
		{
			double plane[] = { 0, 0, 1, 0 };
			glClipPlane(GL_CLIP_PLANE0, plane);
		}

		drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );
		drawWorld(player);

		glDisable(GL_CLIP_PLANE0);
		glCullFace(GL_BACK);
		glPopMatrix();
		isRenderingReflection = 0; // hack: normal lighting

		/* then blend the skybox into the scene, where stencil is set */
		/* modulate with the destination alpha */
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
		drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );
		glDisable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
		
		/* then blend reflector into the scene */
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glColor4f(1, 1, 1, 1 - reflectivity);

		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
		glStencilFunc(GL_ALWAYS, 1, 255);

		video_Shader_Setup(& gWorld->floor_shader);
		nebu_Mesh_DrawGeometry( gWorld->floor );
		video_Shader_Cleanup(& gWorld->floor_shader);

		glDisable(GL_STENCIL_TEST);
		glDisable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
	}
	/* floor done */

	/* planar shadows */
	glDepthMask(GL_FALSE);
	glDisable(GL_DEPTH_TEST);

	if(reflectivity != 1) // there are no shadows on perfect mirrors
		drawPlanarShadows(player);

	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	/* planar shadows done */

	drawWorld(player);

	/* transparent stuff */
	/* draw the glow around the other players: */
	if (gSettingsCache.show_glow == 1) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		for (i = 0; i < game->players; i++)
		{
			if (i != player && PLAYER_IS_ACTIVE(game->player + i))
			{
				drawGlow(&gPlayerVisuals[player].camera, game->player + i, gPlayerVisuals + i,
					d, TRAIL_HEIGHT * 4);
			}
		}
		glDisable(GL_BLEND);
	}
}
コード例 #15
0
ファイル: system.cpp プロジェクト: ShawnCramp/Solar_System
//<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void) {
	glEnable(GL_LIGHTING);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0, WIDTH / HEIGHT, 0.2, 4000.0);
	// Clear the rendering window
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//if followPlanet was selected, focus on that planet
	if (followPlanet) {
		position::Position p = solarSystem[planetNum].getPosition();
		gluLookAt(
				camera[0]
						+ ((solarSystem[planetNum].p_distance + viewerDistance)
								* cos(p.angle)), camera[1],
				camera[2]
						- ((solarSystem[planetNum].p_distance + viewerDistance)
								* sin(p.angle)), lookAtPosition[0],
				lookAtPosition[1], lookAtPosition[2], 0.0, 1.0, 0);
	}
	//default camera view
	else {
		gluLookAt(
				lookAtPosition[0]
						+ viewerDistance * sin(viewerZenith)
								* sin(viewerAzimuth),
				lookAtPosition[1] + viewerDistance * cos(viewerZenith),
				lookAtPosition[2]
						+ viewerDistance * sin(viewerZenith)
								* cos(viewerAzimuth), lookAtPosition[0],
				lookAtPosition[1], lookAtPosition[2], 0.0, 1.0, 0.020);
	}

	glRotatef(0.0, 1.0, 0.0, 0.0);

	//loop through the solar system and render it
	for (size_t t = 0; t < solarSystem.size(); ++t) {
		glEnable(GL_TEXTURE_2D);
		if (t == 0) {
			solarSystem[t].drawSun();
		} else {
			glPushMatrix();
			solarSystem[t].draw();
			glPopMatrix();
		}
		glDisable(GL_TEXTURE_2D);
	}

	// Draw Skybox
	glEnable(GL_TEXTURE_2D);
	drawSkybox();
	glDisable(GL_TEXTURE_2D);

	glDisable(GL_LIGHTING);
	glFlush();
	glutSwapBuffers();

	glutPostRedisplay(); // Request a re-draw for animation purposes

}
コード例 #16
0
ファイル: main.cpp プロジェクト: licnep/RangoShooter
void Render_Gioco(void){

	float tmp;
	
	pointer_pos=cursor_position();

	glutSetCursor(GLUT_CURSOR_NONE);
  
	glDisable(GL_FOG);

    drawSkybox();
	drawGun();
	drawBullet();
    drawScore();
	
    glPushMatrix();
    gluLookAt(0.f,0.f,3.f,0.f,0.f,-5.f,0.f,1.f,0.f);

	tmp = 0.0536414;
	glScalef(tmp, tmp, tmp);
    
	glTranslated(-xpos,0.0f,0.0f);
	
	//SPOSTAMENTO DELLA CAMERA:
	float xx=9,yy=0,zz=42;
	glTranslatef(xx,yy,zz);
	glRotatef(main_camera.getLocRot().y_rot,0.0f,1.0f,0.0f);

	glTranslatef(-xx,-yy,-zz);
	//translo la camera (in realta' translo tutto il resto)
	glTranslatef(main_camera.getLocRot().x, main_camera.getLocRot().y, main_camera.getLocRot().z);


	//Fog----------------------

	glFogi(GL_FOG_MODE, GL_LINEAR);					// Fog Mode
	GLfloat fogColor[4]= {0.6f, 0.5f, 0.3f, 1.0f};
	glFogfv(GL_FOG_COLOR, fogColor);				// Set Fog Color
	glFogf(GL_FOG_DENSITY, 0.45f);					// How Dense Will The Fog Be
	glHint(GL_FOG_HINT, GL_DONT_CARE);				// Fog Hint Value
	glFogf(GL_FOG_START, 3.5f);						// Fog Start Depth
	glFogf(GL_FOG_END, 6.0f);						// Fog End Depth
	glEnable(GL_FOG);								// Enables GL_FOG
	
	//-------------------------

	if(first == TRUE){
		scene_list_case=glGenLists(4);
		scene_list_target=glGenLists(10);
		lista_case(scene_list_case,level1_scene.scene,level2_scene.scene,level3_scene.scene,terreno_scene.scene);
		lista_target(scene_list_target,target_scene.scene);
		pos=scegli_pos(livello,livelli);
		first = FALSE;
	}

	if(m[pos].stato==2){
        m[pos]=reset_motion(m[pos]);
        pos=scegli_pos(livello,livelli);
    }
       
	ch=render_target(livello,scene_list_target,pos,livelli,m[pos],ch,t.v);
	render_case(livello,scene_list_case);

	if(!pause)t=count_time(t);

	m[pos]=scegli_mov(m[pos],livelli,pos,t.tempoi, t.v, ch_index,ch);
    
    glPopMatrix();

	drawPointer(pointer_pos);

	if(pause) DrawMenu(0,0,menuArray[5],true);

}