예제 #1
0
파일: lab3-1.c 프로젝트: simplerr/TSBK07
void render_windmill(struct Windmill* windmill, GLuint program, float time)
{
	mat4 rot, trans, scale, total;

	scale = S(1, 1, 1);
	rot = Rx(-time * 4);
	rot = IdentityMatrix();
	trans = T(windmill->position.x, windmill->position.y, windmill->position.z);
	total = Mult(scale, rot);
	total = Mult(trans, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix

	// Draw the windmill
	DrawModel(windmill->balcony, program, "in_Position", "in_Normal", "inTexCoord");
	DrawModel(windmill->walls, program, "in_Position", "in_Normal", "inTexCoord");
	DrawModel(windmill->roof, program, "in_Position", "in_Normal", "inTexCoord");

	// Draw the blades
	trans = T(windmill->position.x+5, windmill->position.y+10, windmill->position.z);

	// 1
	rot = Rx(0 + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 2
	rot = Rx(3.14f/2.0f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 3
	rot = Rx(3.14f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 3
	rot = Rx(-3.14f/2.0f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

}
예제 #2
0
파일: skinning2.c 프로젝트: Grodaaa/TSBK03
///////////////////////////////////////////////
//		 D R A W  C Y L I N D E R
// Desc:	sätter bone positionen i vertex shadern
void DrawCylinder()
{
  animateBones();

  // ---------=========  UPG 2 (extra) ===========---------
  // ersätt DeformCylinder med en vertex shader som gör vad DeformCylinder gör.
  // begynelsen till shader koden ligger i filen "ShaderCode.vert" ...
  // 
	
  DeformCylinder();
	
  // setBoneLocation();
  // setBoneRotation();

// update cylinder vertices:
	glBindVertexArray(cylinderModel->vao);
	glBindBuffer(GL_ARRAY_BUFFER, cylinderModel->vb);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vec3)*kMaxRow*kMaxCorners, g_vertsRes, GL_DYNAMIC_DRAW);
	
	DrawModel(cylinderModel, g_shader, "in_Position", "in_Normal", "in_TexCoord");
}
예제 #3
0
void DrawBillboard(Model* bm, int inx, int inz, mat4 view)
{
	GLfloat x = (GLfloat) inx;
	GLfloat z = (GLfloat) inz;

	if(randXZ->xz[inx][(int)z].x == -9999.0)
	{
		GLfloat randX;
		GLfloat randZ;
		TreeRandomNumberGen(&randX, &randZ, inx, inz);
		randXZ->xz[inx][(int)z].x = randX;
		randXZ->xz[inx][(int)z].z = randZ;
	}
	
	
	x = x + randXZ->xz[inx][inz].x;
	z = z + randXZ->xz[inx][inz].z;

	vec3 billVec = VectorSub(player->getPos(),vec3(x,0,z));
	vec3 playerLookAt = VectorSub(player->getPos(),player->getLook());
	billVec.y = 0;	
	playerLookAt.y = 0;
	if(Norm(billVec) < treeRenderingDistance && DotProduct(playerLookAt,billVec) > 0)
	{
		billVec = Normalize(billVec);		
		playerLookAt.y = 0.0;
		mat4 translate=  T(x, world->findHeight(x, z), z);
		view = Mult(view, translate);
		vec3 billNorm = vec3(0,0,1);
		vec3 upVec = CrossProduct(billNorm, billVec);
		GLfloat cosAngle = DotProduct(billNorm, billVec);		
		GLfloat angle = acos(cosAngle);		
		mat4 billRotMat = ArbRotate(upVec, angle);

		view = Mult(view,billRotMat);	
		glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "camMatrix"), 1, GL_TRUE, player->getCamMatrix().m);
		glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "mdlMatrix"), 1, GL_TRUE, view.m);
		DrawModel(bm, billBoardProgram, "inPosition",  NULL, "inTexCoord"); 
	}
}
예제 #4
0
void punshControl(Model* map, mat4 view)
{
		
		vec3 mapNorm = vec3(0,0,1);
		vec3 camPos = VectorAdd(player->getPos(),vec3(0,2.0,0));
		vec3 mapToCam = VectorSub(player->getPos(),player->getLook());

		//Put text in front of the cam
		vec3 mapPos = VectorSub(camPos,mapToCam);
		mat4 translate=  T(mapPos.x,mapPos.y,mapPos.z);
		view = Mult(view, translate);

		//Rotate in around Y-axis
		vec3 mapToCamXZ = mapToCam;
		mapToCamXZ.y = 0;
		mapToCamXZ = Normalize(mapToCamXZ);
		vec3 upVec = CrossProduct(mapNorm, mapToCamXZ);
		GLfloat angle = acos(DotProduct(mapNorm, mapToCamXZ));
		mat4 billRotMat = ArbRotate(upVec, angle);

		view = Mult(view,billRotMat);

		//Rotate in around XZ-axis
		mapToCam = Normalize(mapToCam);
		angle = acos(DotProduct(mapToCamXZ,mapToCam));
		
		if (mapToCam.y < 0)
			billRotMat = ArbRotate(vec3(1,0,0), angle);	
		else
			billRotMat = ArbRotate(vec3(-1,0,0), angle);

		view = Mult(view,billRotMat);		
		
		mat4 viewCompass = view;
		view = Mult(view,T(0,0,-0.1));
		glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "camMatrix"), 1, GL_TRUE, player->getCamMatrix().m);
		glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "mdlMatrix"), 1, GL_TRUE, view.m);
		DrawModel(map, billBoardProgram, "inPosition",  NULL, "inTexCoord"); 

}
예제 #5
0
// ------------------------------------------------------------------------
// Draw
// use gl to draw the model
// ------------------------------------------------------------------------
void CRenderWnd::Draw()
{
	static LTMatrix IdMat;
	IdMat.Identity();

	DrawStruct *pStruct;

	pStruct = &m_DrawStruct;

	// Setup with 2 lights.
	pStruct->m_ViewerPos = m_Camera.m_Position;
	pStruct->m_LookAt = m_Camera.m_LookAt;
	pStruct->m_LightPositions[0] = m_LightLocators[0].m_Location;
	pStruct->m_LightPositions[1] = m_LightLocators[1].m_Location;
	pStruct->m_LightColors[0].Init(255.0f, 255.0f, 255.0f);
	pStruct->m_LightColors[1].Init(128.0f, 128.0f, 128.0f);
	pStruct->m_nLights = 2;

	SetupViewingParameters((GLMContext*)m_hContext, pStruct );

 	DrawWorldCoordSys();
	
	// if the model exists 
	if (GetModel()  )
	{
		pStruct->m_SelectedPieces = m_SelectedPieces.GetArray();
		pStruct->m_SelectedNodes = m_SelectedNodes.GetArray();

		pStruct->m_bCalcRadius = m_bCalcRadius;
		pStruct->m_fModelRadius = 0.0f;
		pStruct->m_bCalcAndDraw = m_bCalcAndDraw;

		DrawModel (m_hContext, pStruct);

		m_fCurRadius = pStruct->m_fModelRadius;
	}
		
	SwapBuffers( (( GLMContext*)m_hContext)->m_hDC);

}
예제 #6
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occurred
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevant OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2Shaders::RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Keyboard input (cursor to change shaders and meshes)
	if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_nCurrentShader--;
		if(m_nCurrentShader<0) m_nCurrentShader=(g_numShaders-1);
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_nCurrentShader++;
		if(m_nCurrentShader>(g_numShaders-1)) m_nCurrentShader=0;
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_nCurrentSurface--;
		if(m_nCurrentSurface<0) m_nCurrentSurface=(g_numSurfaces-1);
		ComputeSurface(m_nCurrentSurface);
	}
	if (PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_nCurrentSurface++;
		if(m_nCurrentSurface>(g_numSurfaces-1)) m_nCurrentSurface=0;
		ComputeSurface(m_nCurrentSurface);
	}

	// Draw the mesh
	ComputeViewMatrix();
	DrawModel();

	// Display screen info
	m_Print3D.DisplayDefaultTitle("Shaders", NULL, ePVRTPrint3DSDKLogo);
	m_Print3D.Print3D(0.3f, 7.5f, 0.75f, 0xFFFFFFFF, "Shader: %s\nMesh: %s", g_ShaderList[m_nCurrentShader], g_SurfacesList[m_nCurrentSurface]);
	m_Print3D.Flush();

	return true;
}
예제 #7
0
	void GraphicsEngine::DrawOpaqueObjects(Engine::World* world)
	{
		auto models = world->GetModels();
		for (auto* model : *models)
		{
			auto shaderProgramId = model->m_Material->m_ShaderProgram;

			GraphicsCore::GPUAPI::UseShader(shaderProgramId);
			BindViewProjMatrices(shaderProgramId, world);

			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, g_LightBufferSSBO.SSBO);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, g_OpaqueLightGridSSBO.SSBO);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, g_OpaqueLightIndexListSSBO.SSBO);

			int workGroupsX = (SCREEN_SIZE_X + (SCREEN_SIZE_X % GRID_SIZE)) / GRID_SIZE;
			glUniform1i(glGetUniformLocation(shaderProgramId, "workGroupsX"), workGroupsX);

			DrawModel(model);
		}

		// DEBUGGING LIGHTS
		DrawDebugLights(world);
	}
예제 #8
0
파일: game.cpp 프로젝트: CarlHuff/kgui
void GameBase::DrawString(const char *string,double scale,double x,double y,GameColor color)
{
	double size=16.0f*scale;
	double gap=5.0f*scale;

	GameModel *model;

	while(string[0])
	{
		if(string[0]==' ')
			x+=(gap+gap);
		else
		{
			model=m_fontmodel[(unsigned int)string[0]];
			if(model)
				DrawModel(x,y,0.0f,color,model,scale,scale);
			else
				DrawRect(x,y,x+size,y+size,color);
			x+=(size+gap);
		}
		++string;
	}
}
예제 #9
0
void draw_skybox(void)
{
	// Send in additional params
	glUseProgram(programs[SKYBOX_PROGRAM]);
    printError("draw skybox0");

	// Send in additional params
	glUniformMatrix4fv(glGetUniformLocation(programs[SKYBOX_PROGRAM], "projectionMatrix"), 1, GL_TRUE, projectionMatrix);
	glUniformMatrix4fv(glGetUniformLocation(programs[SKYBOX_PROGRAM], "camMatrix"), 1, GL_TRUE, camMatrix);

    printError("draw skybox1");
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, billboards[SKYBOX_TEXTURE]);
    printError("draw skybox2");
   	glUniform1i(glGetUniformLocation(programs[SKYBOX_PROGRAM], "texUnit"), 0); // Texture unit 0
    printError("draw skybox3");
   	glDisable(GL_DEPTH_TEST);
   	glDisable(GL_CULL_FACE);
	DrawModel(skybox);
    printError("draw skybox4");
	glEnable(GL_DEPTH_TEST);
    printError("draw skybox5");
}
예제 #10
0
void HUDDrawer::Draw(const CUnit* unit)
{
	if (unit == 0 || !draw) {
		return;
	}

	PushState();
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glPushMatrix();
			DrawUnitDirectionArrow(unit);
			DrawCameraDirectionArrow(unit);
		glPopMatrix();

		glEnable(GL_DEPTH_TEST);
		DrawModel(unit);

		DrawWeaponStates(unit);
		DrawTargetReticle(unit);
	PopState();
}
예제 #11
0
	void RenderCommand::Execute( void ) const {
		switch ( type ) {

		case CommandType::DrawQuad: {
			DrawQuad( drawQuad );
		} break;

		case CommandType::DrawModel: {
			DrawModel( drawModel );
		} break;

		case CommandType::DrawParticles: {
			DrawParticles( drawParticles );
		} break;

		case CommandType::Screenshot: {
			Screenshot( screenshot );
		} break;

		default: {
		} break;

		}
	}
예제 #12
0
void DrawScene(float angle, bool drawHairball)
{
	if (drawHairball) { DrawModel(hairball); }
	else { DrawModel(bunny); }

	glPushMatrix();

	glTranslatef(0.0f, 1.0f, 2.0f);
	glRotatef(90, 1, 0.0f, 0.0f);
	glScalef(6.0f, 1.0f, 6.0f);
	glutSolidCube(0.5f);

	glPopMatrix();

	//Display lists for objects
	static GLuint spheresList=0, torusList=0, baseList=0;

	//Create spheres list if necessary
	if(!spheresList)
	{
		spheresList=glGenLists(1);
		glNewList(spheresList, GL_COMPILE);
		{
			glColor3f(0.0f, 1.0f, 0.0f);
			glPushMatrix();

			glTranslatef(0.45f, 1.0f, 0.45f);
			glutSolidSphere(0.2, 24, 24);

			glTranslatef(-0.9f, 0.0f, 0.0f);
			glutSolidSphere(0.2, 24, 24);

			glTranslatef(0.0f, 0.0f,-0.9f);
			glutSolidSphere(0.2, 24, 24);

			glTranslatef(0.9f, 0.0f, 0.0f);
			glutSolidSphere(0.2, 24, 24);

			glPopMatrix();
		}
		glEndList();
	}

	//Create torus if necessary
	if(!torusList)
	{
		torusList=glGenLists(1);
		glNewList(torusList, GL_COMPILE);
		{
	//		glColor3f(1.0f, 0.0f, 0.0f);
	//		glPushMatrix();

	//		glTranslatef(0.0f, 0.5f, 0.0f);
	//		glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
			//glutSolidTorus(0.2, 0.5, 24, 48);
			
	

			glPopMatrix();
		}
		glEndList();
	}

	//Create base if necessary
	if(!baseList)
	{
		baseList=glGenLists(1);
		glNewList(baseList, GL_COMPILE);
		{
			glColor3f(0.0f, 0.0f, 1.0f);
			glPushMatrix();

			glScalef(1.0f, 0.05f, 1.0f);
			glutSolidCube(3.0f);

			glPopMatrix();
		}
		glEndList();
	}


	//Draw objects
	glCallList(baseList);
	glCallList(torusList);
	
	glPushMatrix();
	glRotatef(angle, 0.0f, 1.0f, 0.0f);
	glCallList(spheresList);
	glPopMatrix();
}
예제 #13
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");

    // Define our custom camera to look into our 3d world
    Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };

    Image image = LoadImage("resources/heightmap.png");         // Load heightmap image (RAM)
    Texture2D texture = LoadTextureFromImage(image);            // Convert image to texture (VRAM)
    Model map = LoadHeightmap(image, (Vector3) {
        16, 8, 16
    });   // Load heightmap model with defined size
    map.material.texDiffuse = texture;                          // Set map diffuse texture
    Vector3 mapPosition = { -8.0f, 0.0f, -8.0f };               // Set model position (depends on model scaling!)

    UnloadImage(image);                     // Unload heightmap image from RAM, already uploaded to VRAM

    SetCameraMode(camera, CAMERA_ORBITAL);  // Set an orbital camera mode

    SetTargetFPS(60);                       // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())            // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        UpdateCamera(&camera);              // Update camera
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

        ClearBackground(RAYWHITE);

        Begin3dMode(camera);

        // NOTE: Model is scaled to 1/4 of its original size (128x128 units)
        DrawModel(map, mapPosition, 1.0f, RED);

        DrawGrid(20, 1.0f);

        End3dMode();

        DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
        DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);

        DrawFPS(10, 10);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadTexture(texture);     // Unload texture
    UnloadModel(map);           // Unload model

    CloseWindow();              // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
예제 #14
0
파일: main.cpp 프로젝트: PONT-MAX/TSBK07
void display(void)
{
    //std::cout << "time boost = " << time_boost << std::endl;
    if (time_boost >= 1) {
        time_boost -= 1;
        if (time_boost < 1) {
            std::cout << "BOOST OFF!" << std::endl;
            game_->ball_speed = game_->ball_speed_global;
            game_->imortality = false;
        }
    }
    
    
    //printf("d1 \n");

    
    t += 0.005;
    game_->world_dir();
    // clear the screen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    
    mat4 total, modelView, camMatrix;
    
    printError("pre display");
    
    glUseProgram(program);
    // Build matrix

    vec3 cam = vec3(0, 5, 8);
    vec3 lookAtPoint = vec3(2, 0, 2);
    camMatrix = lookAt(cam.x, cam.y, cam.z,
                       lookAtPoint.x, lookAtPoint.y, lookAtPoint.z,
                       0.0, 1.0, 0.0);
    modelView = IdentityMatrix();
    total = Mult(camMatrix, modelView);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    glUniformMatrix4fv(glGetUniformLocation(program, "Camera"), 1, GL_TRUE, camera.m);
    
    // skybox
    
    // Disable Z-buffer to draw sky
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    
    // Use skytex as texture and switch to skyprogram
    glUseProgram(skyprogram);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, skytex);
    
    
    // Sky
    mat4 skylookAT = camera;
    skylookAT.m[3] = 0;
    skylookAT.m[7] = 0;
    skylookAT.m[11] = 0;
    
    skylookAT = Mult(T(-0.2,0,0), skylookAT);
    mat4 skyrot = Ry(game_->turn_angle*game_->pol_dir);
    skytot = Mult(skytot, skyrot);

    glUniformMatrix4fv(glGetUniformLocation(skyprogram, "lookAT"), 1, GL_TRUE, skylookAT.m);
    
    glUniformMatrix4fv(glGetUniformLocation(skyprogram, "mdlMatrix"),1, GL_TRUE, skytot.m);
    DrawModel(skybox, skyprogram, "in_Position", NULL, "in_TexCoord");
    printError("sky shader");
    
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glUseProgram(program);

    
    glBindTexture(GL_TEXTURE_2D, tex1);		// Bind Our Texture tex1
    glActiveTexture(GL_TEXTURE0);
    
    
    // game clock
    if (!game_->dead) {
        // game clock
        time_count += 0.02;
        snprintf(buffer, 50, "%f", time_count);
        sfDrawString(30, 30, "Elapsed Time:");
        sfDrawString(170, 30, buffer);
        if (game_->ball_speed_global < 5) {
            game_->ball_speed_global += 0.0002;
        }
        
    }
    
    
    
    //Current
    total = game_->maze->get_total();
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(game_->maze->track, program, "inPosition", "inNormal", "inTexCoord");
    
    //left
    total = game_->maze->left->get_total();
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(game_->maze->left->track, program, "inPosition", "inNormal", "inTexCoord");
    
    //left->left
    total = game_->maze->left->left->get_total();
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(game_->maze->left->left->track, program, "inPosition", "inNormal", "inTexCoord");
    
    //left->right
    total = game_->maze->left->right->get_total();
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(game_->maze->left->right->track, program, "inPosition", "inNormal", "inTexCoord");
    
    
    //right
    total = game_->maze->right->get_total();
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(game_->maze->right->track, program, "inPosition", "inNormal", "inTexCoord");
    //right->left
    total = game_->maze->right->left->get_total();
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(game_->maze->right->left->track, program, "inPosition", "inNormal", "inTexCoord");
    //right->right
    total = game_->maze->right->right->get_total();
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(game_->maze->right->right->track, program, "inPosition", "inNormal", "inTexCoord");
    
    
    


    //sphere
    glBindTexture(GL_TEXTURE_2D, tex2);
    glActiveTexture(GL_TEXTURE0);

    //    GLfloat y_pos_des = height_controll(x_pos, z_pos,&ttex,tm)+0.1;
    //    y_pos -= (y_pos - y_pos_des)/1*0.5;
    game_->update();
    if (game_->generate_terrain_bool) {
        NewTerrain(game_->x_pos);
        game_->generate_terrain_bool = false;
    }

    //trans = T(0,0,0); // <<< --  Vart spheren är
    //rot = Rx(0);
    //rot = Ry(M_PI_2/4);
    //total = game_->player_->total_pos();//Mult(game_->strans, rot);

    camera = game_->update_camera();
    
    //Body
    total = game_->player_->body_total;
    
    glBindTexture(GL_TEXTURE_2D, tex_body);
    glActiveTexture(GL_TEXTURE0);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(Body,program,"inPosition","inNormal","inTexCoord");
    
    //Rest of player init tex
    glBindTexture(GL_TEXTURE_2D, tex_head);
    glActiveTexture(GL_TEXTURE0);
    
    total = game_->player_->head_total;
    
    //head
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(Body,program,"inPosition","inNormal","inTexCoord");
    
    //arms
    total = game_->player_->arm_total_l;
    //lsft
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(ArmL,program,"inPosition","inNormal","inTexCoord");
    
    total = game_->player_->arm_total_r;
    //right
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(ArmR,program,"inPosition","inNormal","inTexCoord");
    
    //legs
    total = game_->player_->leg_total_l;
    //Left
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(LegL,program,"inPosition","inNormal","inTexCoord");
    
    total = game_->player_->leg_total_r;
    //Right
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
    DrawModel(LegR,program,"inPosition","inNormal","inTexCoord");
    
    
    //Lava
    glBindTexture(GL_TEXTURE_2D, lavatex);
    glActiveTexture(GL_TEXTURE0);
    
    lavatot = Mult(T(0.0,(game_->y_pos_t),0.0),lavatot);
    lavatot = Mult(lavatot, skyrot);
    
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, lavatot.m);
    DrawModel(Lava,program,"inPosition","inNormal","inTexCoord");
    
    
    
    //BOOSTERS
    // ---------------------- ______________------------------
    //printf("b1 \n");
    
    bool b_col = game_->maze->b_collision;
    // printf("bool b_collision: %d \n", b_col );
    
    if (b_col == false){
        
        game_->boost_collision();
        draw_boost(game_->maze);
        b_col = game_->maze->b_collision;
        if (b_col == true) { // if collision give points
            time_count += 100;
            time_boost = (3*(1+game_->ball_speed))*(1/0.02);
            std::cout << "tB = " << time_boost << std::endl;
            if (game_->maze->boost == 1) { //if speed
                game_->ball_speed += 1;
            }
            else{ // if imortality
                game_->imortality = true;
            }
        }
        
    }

    draw_boost(game_->maze->right);
    draw_boost(game_->maze->left);
    
    

    
    //  printf("obstacle main%d \n", obstacle );
    //  printf("obstaclex main %d \n", obstacle_x_pos );

    draw_obsticle(game_->maze);
        draw_obsticle(game_->maze->left);
        draw_obsticle(game_->maze->right);
    
    
    if (game_->dead) {
        sfSetRasterSize(600, 200);
        sfDrawString(250, 90, "GAME OVER");
        
        GLfloat time_score = time_count;
        snprintf(buffer, 50, "%f", time_score);
        sfDrawString(220, 110, "Score: ");
        sfDrawString(290, 110, buffer);
    }

   
    printError("display 2");
    
    glutSwapBuffers();
}
예제 #15
0
파일: lab3-2.c 프로젝트: Seanberite/CG
void display(void)
{ 
	if (glutKeyIsDown('a')) { 
	 x=x-0.3;
	}
	if (glutKeyIsDown('d')) { 
	 x=x+0.3;
	}
	if (glutKeyIsDown('w')) { 
	 y=y+0.3;
	}
	if (glutKeyIsDown('s')) { 
	 y=y-0.3;
	}
	if (glutKeyIsDown('l')) { 
	 ry=ry-0.3;
	}
	if (glutKeyIsDown('j')) { 
	 ry=ry+0.3;
	}
	if (glutKeyIsDown('i')) { 
	 rx=rx-0.3;
	}
	if (glutKeyIsDown('k')) { 
	 rx=rx+0.3;
	}


        
 	a += 0.1;
	mat4 rot, trans, trans2, transCam, transCam2, rot2, rotTot, totCam, total, bladeRotMat, windMillPos;

	//clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	rot = Ry(ry/10);
	transCam = T(0, 0, 16);
	transCam2 = T(0,0,-16);
	totCam = Mult(rot, transCam); 
	totCam = Mult(transCam2, totCam); 

	vec3 p = SetVector(x, y+8, 10);
	vec4 s = vec3tovec4(p);
	vec4 d = MultVec4(totCam, s);
	vec3 q = vec4tovec3(d);
	vec3 l = SetVector(0,8,-16);
	vec3 v = SetVector(0,1,0);
	 
	camera = lookAtv(q,l,v);
	glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, camera.m);

	// walls
rot = Ry(0);
	windMillPos = T(0,0,-16);
	total = Mult(windMillPos, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
	DrawModel(walls, program,"in_Position" , "in_Normal", "inTexCoord");

	// Blade rotation matrix
	trans = T(0, -9, 16);
	trans2 = T(0, 9, -16);
	rot = Rz(a/6);
	bladeRotMat = Mult(rot, trans);
	bladeRotMat = Mult(trans2, bladeRotMat);

	// Bladener
	rot = Ry(1.57);
	trans = T(0, 9, -11);
	total = Mult(trans, rot);
	total = Mult(bladeRotMat, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
	DrawModel(blade, program,"in_Position" , "in_Normal", "inTexCoord");
	// Bladupp
	rot = Ry(1.57);
	rot2 = Rz(3.14);
	rotTot = Mult(rot2, rot);
	trans = T(0, 9, -11);
	total = Mult(trans, rotTot);
	total = Mult(bladeRotMat, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
	DrawModel(blade, program,"in_Position" , "in_Normal", "inTexCoord");
	// BladeV
	rot = Ry(1.57);
	rot2 = Rz(1.57);
	rotTot = Mult(rot2, rot);
	trans = T(0, 9, -11);
	total = Mult(trans, rotTot);
	total = Mult(bladeRotMat, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
	DrawModel(blade, program,"in_Position" , "in_Normal", "inTexCoord");
	// BladeH
	rot = Ry(1.57);
	rot2 = Rz(-1.57);
	rotTot = Mult(rot2, rot);
	trans = T(0, 9, -11);
	total = Mult(trans, rotTot);
	total = Mult(bladeRotMat, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
	DrawModel(blade, program,"in_Position" , "in_Normal", "inTexCoord");
	
	

	//roof model
	rot  = Ry(0/6);
	trans = T(0,0,-16);
	total = Mult(trans, rot);

	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
	DrawModel(roof, program,"in_Position" , "in_Normal", "inTexCoord");


	printError("display");
	glutSwapBuffers();
}
예제 #16
0
void display(void)
{
	if(wIsDown) 
	{
		if(nearTree()) player->playerHitTree();
		player->goForward();
		
	}
	else
		player->stop();
	if(sIsDown)
	{
			player->goBackwards();
	}
	if(qIsDown) 
	{
		mapAngle-=0.02;	
	}
	if(eIsDown)
	{
			mapAngle+=0.02;
	}
	if(jumping)
	{
			player->jump();
	}
	player->heightUpdate();
	if(player->isNextControl())
	{
		
		//punshControl(map);
		controlIsFound = true;
			
		player->setNextControl(world->getControlPos(player->getPunshedControls()));		

	}
	

	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	
	printError("pre display");

	mat4 total, modelView, translate;
	modelView= IdentityMatrix();


	//Draw Sky box

	glUseProgram(skyProgram);
	glDisable(GL_DEPTH_TEST);
	mat4 camMatrix2 = player->getCamMatrix();

	camMatrix2.m[3] = 0;
	camMatrix2.m[7] = 0;
	camMatrix2.m[11] = 0;	

	mat4 modelView2 = modelView;

	mat4 translate2 = T(0,-0.5,0);
	modelView2 = Mult(modelView2,translate2);

	glUniformMatrix4fv(glGetUniformLocation(skyProgram, "mdlMatrix"), 1, GL_TRUE, modelView2.m);
	glUniformMatrix4fv(glGetUniformLocation(skyProgram, "camMatrix"), 1, GL_TRUE, camMatrix2.m);

	glActiveTexture(GL_TEXTURE5);
	glBindTexture(GL_TEXTURE_2D, skyTex);
	glUniform1i(glGetUniformLocation(skyProgram, "tex1"), 5);

	DrawModel(sky, skyProgram, "inPosition", NULL, "inTexCoord");
	
	glEnable(GL_DEPTH_TEST);
	
	glUseProgram(program);


	//Draw world
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, modelView.m);
	glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, player->getCamMatrix().m);
	
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, tex1);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, tex2);
	glActiveTexture(GL_TEXTURE3);
	glBindTexture(GL_TEXTURE_2D, tex4);
	glUniform1i(glGetUniformLocation(program, "tex1"), 1);
	glUniform1i(glGetUniformLocation(program, "tex2"), 2);
	glUniform1i(glGetUniformLocation(program, "tex3"), 3);
	DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord");


	//Draw trees
	glUseProgram(billBoardProgram);
	glEnable(GL_ALPHA_TEST);
	glActiveTexture(GL_TEXTURE4);
	glBindTexture(GL_TEXTURE_2D, treeTex);
	glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 4);

	for(int x=2; x<254; x=x+3)
	{
		for(int z=2; z<254; z=z+3)
		{
			if(posIsTree[x][z]){
				DrawBillboard(bill,x,z,modelView);
			}
		}
	}	

	//Draw controls
	glDisable(GL_CULL_FACE);
	drawControl(110,72);
	drawControl(50,151);
	drawControl(106,233);
	drawControl(179,103);
	drawControl(226,111);
	glEnable(GL_CULL_FACE);
	//Draw map
	glActiveTexture(GL_TEXTURE6);
	glBindTexture(GL_TEXTURE_2D, mapTex);
	glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 6);

	if(showMap)
	{
			DrawMap(map,compass,modelView); 
	}

	//Check if near control
	if(player->getPunshedControls() <=4){
		glActiveTexture(GL_TEXTURE7);
		glBindTexture(GL_TEXTURE_2D, punshTex);
		glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 7);
	
		if(controlIsFound)
		{
				punshControl(punsh, modelView);
				controlPunshedFor++;
		}
		if(controlPunshedFor>100){
			controlIsFound = false;
			controlPunshedFor = 0;
		}
	}
	else
	{
		glActiveTexture(GL_TEXTURE7);
		glBindTexture(GL_TEXTURE_2D, goalTex);
		glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 7);
		punshControl(punsh, modelView);

	}
	glDisable(GL_ALPHA_TEST);
	
	glutSwapBuffers();
	
}
예제 #17
0
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib example - obj viewer");

    // Define the camera to look into our 3d world
    Camera camera = { { 30.0f, 30.0f, 30.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };

    Model model = LoadModel("resources/models/turret.obj");                     // Load default model obj
    Texture2D texture = LoadTexture("resources/models/turret_diffuse.png");     // Load default model texture
    model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model

    Vector3 position = { 0.0, 0.0, 0.0 };                   // Set model position
    BoundingBox bounds = MeshBoundingBox(model.meshes[0]);  // Set model bounds
    bool selected = false;                                  // Selected object flag

    SetCameraMode(camera, CAMERA_FREE);     // Set a free camera mode

    char objFilename[64] = "turret.obj";

    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        if (IsFileDropped())
        {
            int count = 0;
            char **droppedFiles = GetDroppedFiles(&count);

            if (count == 1)
            {
                if (IsFileExtension(droppedFiles[0], ".obj"))
                {
                    for (int i = 0; i < model.meshCount; i++) UnloadMesh(&model.meshes[i]);
                    model.meshes = LoadMeshes(droppedFiles[0], &model.meshCount);
                    bounds = MeshBoundingBox(model.meshes[0]);
                }
                else if (IsFileExtension(droppedFiles[0], ".png"))
                {
                    UnloadTexture(texture);
                    texture = LoadTexture(droppedFiles[0]);
                    model.materials[0].maps[MAP_DIFFUSE].texture = texture;
                }

                strcpy(objFilename, GetFileName(droppedFiles[0]));
            }

            ClearDroppedFiles();    // Clear internal buffers
        }

        UpdateCamera(&camera);

        // Select model on mouse click
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
        {
            // Check collision between ray and box
            if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected;
            else selected = false;
        }
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            BeginMode3D(camera);

                DrawModel(model, position, 1.0f, WHITE);   // Draw 3d model with texture

                DrawGrid(20.0, 10.0);        // Draw a grid

                if (selected) DrawBoundingBox(bounds, GREEN);

            EndMode3D();

            DrawText("Free camera default controls:", 10, 20, 10, DARKGRAY);
            DrawText("- Mouse Wheel to Zoom in-out", 20, 40, 10, GRAY);
            DrawText("- Mouse Wheel Pressed to Pan", 20, 60, 10, GRAY);
            DrawText("- Alt + Mouse Wheel Pressed to Rotate", 20, 80, 10, GRAY);
            DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 20, 100, 10, GRAY);

            DrawText("Drag & drop .obj/.png to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
            DrawText(FormatText("Current file: %s", objFilename), 250, GetScreenHeight() - 20, 10, GRAY);
            if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);

            DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadModel(model);         // Unload model

    ClearDroppedFiles();        // Clear internal buffers

    CloseWindow();              // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
예제 #18
0
void OpenGLDraw( HWND hWnd, const PorousModel& model, float zoom, float h_angle, float v_angle )
{
  //GLfloat trf[4][4];
  //
  //memset( trf, 0, sizeof(trf) );
  //
  //for( int i = 0; i < 3; ++i )
  //  trf[i][i] = 1.0f;
  //
  //for( int i = 0; i < 3; ++i )
  //{
  //   trf[0][i] = TrfMatrix[0][i];
  //   trf[1][i] = TrfMatrix[1][i];
  //   trf[2][i] = TrfMatrix[2][i];
  //   trf[i][3] = 0.0;
  //}
  //
  //// Coordinates of the center
  //trf[3][0] = 0.0;
  //trf[3][1] = 0.0;
  //trf[3][2] = 0.0;
  //trf[3][3] = 1.0;
  //
  //trf_x_pnt( trf, trf[3], trf[3] );
  //glMultMatrixf( (const GLfloat*)trf );

  SetOpenGLPerspective( hWnd, model );

  // как обычно указываем какие буферы будем чистить
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // обнуляем текущую матрицу
  glLoadIdentity();

  float r = Length( model.GetSize() );
  float cos_vert = cos(v_angle);

  //FPoint eye( r*sin(h_angle)*cos_vert, r*sin(v_angle), r*cos(h_angle)*cos_vert );
  //FPoint up( 0.0f, cos_vert > 0 ? 1.0f : -1.0f, 0.0f );
  FPoint eye( 0, 0, r );
  FPoint up( 0.0f, 1.0f, 0.0f );
  FPoint center( 0.0f, 0.0f, 0.0f );
  gluLookAt( eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z );

  glScalef( zoom, zoom, zoom );

  SetLighting( model );

  static const float koeff = (const float)(180.0f/M_PI);
  glRotatef( koeff*v_angle, 1.0f, 0.0f, 0.0f );
  glRotatef( -koeff*(M_PI/2+h_angle), 0.0f, 1.0f, 0.0f );

  glPushMatrix();

  DrawBounds( model );

  glPopMatrix();
  DrawModel( model );

  SwapBuffers(hDC);
}
예제 #19
0
bool
D3DOverdrawWindow::
NormalizedLoop(float& fOverdraw, float& fOverdrawMax)
{
    int nOverdraw = 0;
    int nOverdrawPix = 0;
    fOverdrawMax = 0;
    DWORD numberOfPixelsDrawn;
    DWORD numberOfPixelsDrawnPix;
    SetupDraw(0);

    for (unsigned int iViewpoint = 0; iViewpoint < m_nViewpointCount; iViewpoint += NUM_QUERIES)
    {
        for (unsigned int j = 0; j < NUM_QUERIES && iViewpoint + j < m_nViewpointCount; j++)
        {
            SetupView(iViewpoint + j);
            SetupTransforms();
            d3d->Clear(0, NULL,  D3DCLEAR_ZBUFFER,
                       D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
            // Add an end marker to the command buffer queue.
            m_pOcclusionQuery[j]->Issue(D3DISSUE_BEGIN);

            // Draw scene
            if (FAILED(DrawModel()))
            {
                return false;
            }

            // Add an end marker to the command buffer queue.
            m_pOcclusionQuery[j]->Issue(D3DISSUE_END);

            // Add an end marker to the command buffer queue.
            d3d->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);
            m_pOcclusionQueryPix[j]->Issue(D3DISSUE_BEGIN);

            // Draw scene
            if (FAILED(DrawModel()))
            {
                return false;
            }

            // Add an end marker to the command buffer queue.
            m_pOcclusionQueryPix[j]->Issue(D3DISSUE_END);
            d3d->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
        }

        for (unsigned int j = 0; j < NUM_QUERIES && iViewpoint + j < m_nViewpointCount; j++)
        {
            // Force the driver to execute the commands from the command buffer.
            // Empty the command buffer and wait until the GPU is idle.
            while (S_FALSE == m_pOcclusionQuery[j]->GetData(&numberOfPixelsDrawn,
                                                            sizeof(DWORD), D3DGETDATA_FLUSH))
                ;

            nOverdraw += numberOfPixelsDrawn;

            while (S_FALSE == m_pOcclusionQueryPix[j]->GetData(&numberOfPixelsDrawnPix,
                                                               sizeof(DWORD), D3DGETDATA_FLUSH))
                ;

            nOverdrawPix += numberOfPixelsDrawnPix;

            if (numberOfPixelsDrawnPix > 0)
            {
                fOverdrawMax = max(fOverdrawMax, numberOfPixelsDrawn / (float)numberOfPixelsDrawnPix);
            }
        }
    }

    if (nOverdrawPix > 0)
    {
        fOverdraw = nOverdraw / (float)nOverdrawPix;
    }
    else
    {
        fOverdraw = 0;
    }

    return true;
}
예제 #20
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;
    
    SetConfigFlags(FLAG_MSAA_4X_HINT);      // Enable Multi Sampling Anti Aliasing 4x (if available)

    InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");

    // Define the camera to look into our 3d world
    Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
    
    Model dwarf = LoadModel("resources/model/dwarf.obj");                   // Load OBJ model
    Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png");   // Load model texture
    SetModelTexture(&dwarf, texture);                                       // Bind texture to model

    Vector3 position = { 0.0, 0.0, 0.0 };                                   // Set model position
    
    Shader shader = LoadShader("resources/shaders/base.vs", 
                               "resources/shaders/bloom.fs");               // Load postpro shader

    SetPostproShader(shader);               // Set fullscreen postprocessing shader
    
    // Setup orbital camera
    SetCameraMode(CAMERA_ORBITAL);          // Set an orbital camera mode
    SetCameraPosition(camera.position);     // Set internal camera position to match our camera position
    SetCameraTarget(camera.target);         // Set internal camera target to match our camera target

    SetTargetFPS(60);                       // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())            // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        UpdateCamera(&camera);              // Update internal camera and our camera
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            Begin3dMode(camera);

                DrawModel(dwarf, position, 2.0f, WHITE);   // Draw 3d model with texture

                DrawGrid(10.0, 1.0);     // Draw a grid

            End3dMode();
            
            DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, BLACK);

            DrawFPS(10, 10);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadShader(shader);       // Unload shader
    UnloadTexture(texture);     // Unload texture
    UnloadModel(dwarf);         // Unload model

    CloseWindow();              // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
예제 #21
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");

    // Define the camera to look into our 3d world
    Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };

    Image image = LoadImage("resources/cubicmap.png");      // Load cubicmap image (RAM)
    Texture2D cubicmap = LoadTextureFromImage(image);       // Convert image to texture to display (VRAM)
    Model map = LoadCubicmap(image);                        // Load cubicmap model (generate model from image)
    
    // NOTE: By default each cube is mapped to one part of texture atlas
    Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");    // Load map texture
    map.material.texDiffuse = texture;                      // Set map diffuse texture
    
    Vector3 mapPosition = { -16.0f, 0.0f, -8.0f };          // Set model position

    UnloadImage(image);     // Unload cubesmap image from RAM, already uploaded to VRAM
    
    SetCameraMode(camera, CAMERA_ORBITAL);  // Set an orbital camera mode

    SetTargetFPS(60);                       // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())            // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        UpdateCamera(&camera);              // Update camera
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            Begin3dMode(camera);

                DrawModel(map, mapPosition, 1.0f, WHITE);

            End3dMode();
            
            DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
            DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
            
            DrawText("cubicmap image used to", 658, 90, 10, GRAY);
            DrawText("generate map 3d model", 658, 104, 10, GRAY);

            DrawFPS(10, 10);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadTexture(cubicmap);    // Unload cubicmap texture
    UnloadTexture(texture);     // Unload map texture
    UnloadModel(map);           // Unload map model

    CloseWindow();              // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
예제 #22
0
void display(void)
{
  printError("pre display");

  // clear the screen (using chosen color earlier)
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glClearColor(1,1,1,0);

  // Set rotation matrix
  phi = ( phi < 2*PI ) ? phi+PI/100 : phi-2*PI+PI/100;

  // Translations for wings/blades
  mat4 rotation_wings = Ry(PI/2);

  // ---------------------------
  // Movement of camera with keyboard
  handle_keyboard(&cameraLocation, &lookAtPoint, &upVector, &movement_speed);

  // Move skybox after cameraLocation is changed by input handling
  skybox_transform = move_skybox(&cameraLocation);
  // Also move camera
  mat4 lookAtMatrix = lookAtv(cameraLocation,lookAtPoint,upVector);
  // ---------------------------


  glUseProgram(skybox_shaders);
  glUniformMatrix4fv(glGetUniformLocation(skybox_shaders, "lookAtMatrix"), 1, GL_TRUE,  lookAtMatrix.m);

  // Draw skybox
  glDisable(GL_DEPTH_TEST);
  glBindTexture(GL_TEXTURE_2D, skybox_tex);
  glUniformMatrix4fv(glGetUniformLocation(skybox_shaders, "transformMatrix"), 1, GL_TRUE,  skybox_transform.m);
  glUniform1i(glGetUniformLocation(skybox_shaders, "tex"), 0);
  DrawModel(skybox, ground_shaders, "in_Position", NULL, "inTexCoord");


  // Draw and texture ground
  glUseProgram(ground_shaders);
  glUniformMatrix4fv(glGetUniformLocation(ground_shaders, "lookAtMatrix"), 1, GL_TRUE,  lookAtMatrix.m);
  glEnable(GL_DEPTH_TEST);
  glBindTexture(GL_TEXTURE_2D, ground_tex);
  glUniform1i(glGetUniformLocation(ground_shaders, "tex"), 0);
  DrawModel(ground, ground_shaders, "in_Position", NULL, "inTexCoord");

  // Model program
  glUseProgram(program);
  glUniform3f(glGetUniformLocation(program, "camera_position"), cameraLocation.x, cameraLocation.y, cameraLocation.z);
  glUniformMatrix4fv(glGetUniformLocation(program, "lookAtMatrix"), 1, GL_TRUE, lookAtMatrix.m);

  // Draw teapot
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_teapot.m);
  DrawModel(teapot, program, "in_Position", "in_Normal", NULL);

  // Draw roof
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_roof.m);
  DrawModel(roof, program, "in_Position", "in_Normal", NULL);

  // Draw balcony
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_balcony.m);
  DrawModel(balcony, program, "in_Position", "in_Normal", NULL);

  // Draw windmill
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_mill.m);
  DrawModel(mill, program, "in_Position", "in_Normal", NULL);

  // Model 2
  for (size_t i = 0; i < 4; i++) {
    transformMatrix = Mult(trans_wings_up, Mult(trans_wings, Rx(phi+i*(PI/2))));
    glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  transformMatrix.m);
    DrawModel(wing, program, "in_Position", "in_Normal", NULL);
  }

  printError("display");

  glutSwapBuffers(); // Swap buffer so that GPU can use the buffer we uploaded to it and we can write to another
}
예제 #23
0
파일: lab3-2.c 프로젝트: Grulfen/tsbk07
void display(void)
{
	printError("pre display");

        t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);

        check_keys();

        r += dr;

        lookAt(&cam_pos, &obj_pos, up.x, up.y, up.z, cam_Matrix);

        glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, cam_Matrix);
        
        // Upload time
        glUniform1f(glGetUniformLocation(program, "t"), t); // Time

	// clear the screen
        glEnable(GL_DEPTH_TEST);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        // Upload the Matrices

        T(0.0,0.0,-20.0, trans);
        Ry(omega_y*t, roty);
        Mult(trans, roty, total);

        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(mill, program, "inPosition", "inNormal", "inTexCoord");

        T(0.0,0.0,-20.0, trans);
        Ry(omega_y*t, roty);
        Mult(trans, roty, total);
        
        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(balcony, program, "inPosition", "inNormal", "inTexCoord");

        T(0.0,0.0,-20, trans);
        Ry(omega_y*t, roty);
        Mult(trans, roty, total);

        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(roof, program, "inPosition", "inNormal", "inTexCoord");

        Ry(0, tilt);

        T(move_before_x,move_before_y,move_before_z, trans);
        Ry(omega_y*t, roty);
        Rx(3.14 + omega_x*r, rotx);
        Mult(rotx, tilt, total);
        Mult(roty, total, total);
        Mult(total, trans, total);
        T(move_x,move_y,move_z, trans);
        Mult(trans, total, total);

        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(blade, program, "inPosition", "inNormal", "inTexCoord");

        T(move_before_x,move_before_y,move_before_z, trans);
        Ry(omega_y*t, roty);
        Rx(3.14/2 + omega_x*r, rotx);
        Mult(rotx, tilt, total);
        Mult(roty, total, total);
        Mult(total, trans, total);
        T(move_x,move_y,move_z, trans);
        Mult(trans, total, total);


        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(blade, program, "inPosition", "inNormal", "inTexCoord");

        T(move_before_x,move_before_y,move_before_z, trans);
        Ry(omega_y*t, roty);
        Rx(-3.14/2 + omega_x*r, rotx);
        Mult(rotx, tilt, total);
        Mult(roty, total, total);
        Mult(total, trans, total);
        T(move_x,move_y,move_z, trans);
        Mult(trans, total, total);

        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(blade, program, "inPosition", "inNormal", "inTexCoord");

        T(move_before_x,move_before_y,move_before_z, trans);
        Ry(omega_y*t, roty);
        Rx(0 + omega_x*r, rotx);
        Mult(rotx, tilt, total);
        Mult(roty, total, total);
        Mult(total, trans, total);
        T(move_x,move_y,move_z, trans);
        Mult(trans, total, total);

        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(blade, program, "inPosition", "inNormal", "inTexCoord");
        
	printError("display");
	
	glutSwapBuffers();
}
예제 #24
0
void display(void) {
    int i, k;

    /* clear the screen*/
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(program);

    GLfloat t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);

    camPos += camMod;

    xValue += xModify * speed;
    yValue += yModify;
    zValue += zModify * speed;

    if (yModify == 0) {
        yCamPos = yValue+2;
    }
    SetVector(xValue + 5 * cos(camPos), yCamPos, zValue + 5 * sin(camPos), &p);
    SetVector(xValue, yCamPos + 0.5, zValue, &l);

    lookAt(&p, &l, 0.0, 1.0, 0.0, cam);
    GLfloat tmp[16];
    CopyMatrix(cam, tmp);
    tmp[3] = 0;
    tmp[7] = 0;
    tmp[11] = 0;
    glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, tmp);
  
/* ================================================================== */

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    T(0, 0, 0, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, skyBoxTex);
    glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(skyBox, program, "inPosition", "inNormal", "inTexCoord");


    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

/* ================================================================== */

    glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, cam);


    T(0, 0, 0, trans);
    S(150,0, 150, shear);
    Mult(trans, shear, total);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");

/* ================================================================== */

    T(10.0f, 5.0f, 0.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");


    T(0.0f, 10.0f, 10.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");


    T(-10.0f, 0.0f, 0.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");


    T(0.0f, 0.0f, -15.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");

/* ================================================================== */

    glUseProgram(programShade);
    glUniform3fv(glGetUniformLocation(programShade, "inCam"), 3, &p);

    glUniformMatrix4fv(glGetUniformLocation(programShade, "camMatrix"), 1, GL_TRUE, cam);
    T(-3.9, 0, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
    //Ry(M_PI, rot);
    //Mult(total, rot, total);
    glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillRoof, programShade, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, 0, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
    //Ry(M_PI, rot);
    //Mult(total, rot, total);
    glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillBalcony, programShade, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, 0, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
    //Ry(M_PI, rot);
    //Mult(total, rot, total);
    glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);    
    DrawModel(windmillWalls, programShade, "inPosition", "inNormal", "inTexCoord");
    for (i = 0; i < 4; i++) {
        T(0, 7.4, 0, trans);
        S(0.5, 0.5, 0.5, shear);
        Mult(trans, shear, total);
        Rx(i * PI / 2 + t/1000, rot);
        Mult(total, rot, total);
        glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(blade, programShade, "inPosition", "inNormal", "inTexCoord");
    }

/* ================================================================== */

    glUseProgram(programMultitex);
    glEnable(GL_BLEND);
    //glDisable(GL_CULL_FACE);
    //glDisable(GL_DEPTH_TEST);

    glUniformMatrix4fv(glGetUniformLocation(programMultitex, "camMatrix"), 1, GL_TRUE, cam);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, bunnyTex);
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, skyBoxTex);
    glUniform1i(glGetUniformLocation(programMultitex, "texUnit"), 1); // Texture unit 1
    glUniform1i(glGetUniformLocation(programMultitex, "texUnit2"), 2); // Texture unit 2

    yValue += yModify;

    if (gravity < 0 && yValue > 0.5) {
        gravity += 0.03;
        yModify -= gravity;
    } else if (yValue > 0.5) {
        gravity += 0.006;
        yModify -= gravity;
    } else {
        gravity = -0.28;
        yValue = 0.55;
        yModify = 0.0;
    }

//    for (k = -7; k < 7; k++) {
        for (i = 2; i > -2; i--) {
//            T(i * 10, yValue, k * 10, trans);
            T(i * 10, 2.5, 10, trans);
            S(5,5,5, shear);
            Mult(trans, shear, total);
            glUniformMatrix4fv(glGetUniformLocation(programMultitex, "mdlMatrix"), 1, GL_TRUE, total);
            DrawModel(bunny, programMultitex, "inPosition", "inNormal", "inTexCoord");
        }
//    }

    //glEnable(GL_DEPTH_TEST);
    //glEnable(GL_CULL_FACE);
    glDisable(GL_BLEND);





    glFlush();
//    glutSwapBuffers();
}
예제 #25
0
// Main
int main() 
{
    GLFWvidmode mode;   // GLFW video mode
    TwBar *bar;         // Pointer to a tweak bar
    
    double time = 0, dt;// Current time and enlapsed time
    double turn = 0;    // Model turn counter
    double speed = 0.3; // Model rotation speed
    int wire = 0;       // Draw model in wireframe?
    float bgColor[] = { 0.1f, 0.2f, 0.4f };         // Background color 
    unsigned char cubeColor[] = { 255, 0, 0, 128 }; // Model color (32bits RGBA)

    // Intialize GLFW   
    if( !glfwInit() )
    {
        // An error occured
        fprintf(stderr, "GLFW initialization failed\n");
        return 1;
    }

    // Create a window
    glfwGetDesktopMode(&mode);
    if( !glfwOpenWindow(640, 480, mode.RedBits, mode.GreenBits, mode.BlueBits, 
                        0, 16, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) )
    {
        // A fatal error occured    
        fprintf(stderr, "Cannot open GLFW window\n");
        glfwTerminate();
        return 1;
    }
    glfwEnable(GLFW_MOUSE_CURSOR);
    glfwEnable(GLFW_KEY_REPEAT);
    glfwSetWindowTitle("AntTweakBar simple example using GLFW");

    // Initialize AntTweakBar
    TwInit(TW_OPENGL, NULL);

    // Create a tweak bar
    bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLFW and OpenGL.' "); // Message added to the help bar.

    // Add 'speed' to 'bar': it is a modifable (RW) variable of type TW_TYPE_DOUBLE. Its key shortcuts are [s] and [S].
    TwAddVarRW(bar, "speed", TW_TYPE_DOUBLE, &speed, 
               " label='Rot speed' min=0 max=2 step=0.01 keyIncr=s keyDecr=S help='Rotation speed (turns/second)' ");

    // Add 'wire' to 'bar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w].
    TwAddVarRW(bar, "wire", TW_TYPE_BOOL32, &wire, 
               " label='Wireframe mode' key=w help='Toggle wireframe display mode.' ");

    // Add 'time' to 'bar': it is a read-only (RO) variable of type TW_TYPE_DOUBLE, with 1 precision digit
    TwAddVarRO(bar, "time", TW_TYPE_DOUBLE, &time, " label='Time' precision=1 help='Time (in seconds).' ");         

    // Add 'bgColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color)
    TwAddVarRW(bar, "bgColor", TW_TYPE_COLOR3F, &bgColor, " label='Background color' ");

    // Add 'cubeColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR32 (32 bits color) with alpha
    TwAddVarRW(bar, "cubeColor", TW_TYPE_COLOR32, &cubeColor, 
               " label='Cube color' alpha help='Color and transparency of the cube.' ");

    // Set GLFW event callbacks
    // - Redirect window size changes to the callback function WindowSizeCB
    glfwSetWindowSizeCallback(WindowSizeCB);
    // - Directly redirect GLFW mouse button events to AntTweakBar
    glfwSetMouseButtonCallback((GLFWmousebuttonfun)TwEventMouseButtonGLFW);
    // - Directly redirect GLFW mouse position events to AntTweakBar
    glfwSetMousePosCallback((GLFWmouseposfun)TwEventMousePosGLFW);
    // - Directly redirect GLFW mouse wheel events to AntTweakBar
    glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW);
    // - Directly redirect GLFW key events to AntTweakBar
    glfwSetKeyCallback((GLFWkeyfun)TwEventKeyGLFW);
    // - Directly redirect GLFW char events to AntTweakBar
    glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW);


    // Initialize time
    time = glfwGetTime();

    // Main loop (repeated while window is not closed and [ESC] is not pressed)
    while( glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC) )
    {
        // Clear frame buffer using bgColor
        glClearColor(bgColor[0], bgColor[1], bgColor[2], 1);
        glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

        // Rotate model
        dt = glfwGetTime() - time;
        if( dt < 0 ) dt = 0;
        time += dt;
        turn += speed*dt;
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotated(360.0*turn, 0.4, 1, 0.2);
        glTranslated(-0.5, -0.5, -0.5);     
    
        // Set color and draw model
        glColor4ubv(cubeColor);
        DrawModel(wire);
        
        // Draw tweak bars
        TwDraw();

        // Present frame buffer
        glfwSwapBuffers();
    }

    // Terminate AntTweakBar and GLFW
    TwTerminate();
    glfwTerminate();

    return 0;
}
예제 #26
0
파일: game_glutobj.c 프로젝트: LeoYao/glm
void Display(void)
{

/*    GLint viewport[4]; */
    /*
       int jitter;

       glGetIntegerv (GL_VIEWPORT, viewport);

       glClear(GL_ACCUM_BUFFER_BIT);
       for (jitter = 0; jitter < ACSIZE; jitter++) {
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       accPerspective (50.0, 
       (GLdouble) viewport[2]/(GLdouble) viewport[3], 
       1.0, 15.0, j8[jitter].x, j8[jitter].y, 0.0, 0.0, 1.0);
       DrawModel(); 
       glAccum(GL_ACCUM, 1.0/ACSIZE);
       }
       glAccum (GL_RETURN, 1.0);
       glFlush();
     */
    if (stereo) {

	/* Clear right and left eye buffers */
	glDrawBuffer(GL_BACK_LEFT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glDrawBuffer(GL_BACK_RIGHT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* Right Eye */
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45, (double) ww / (double) wh, 0.1, -_zFar);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glDrawBuffer(GL_BACK_RIGHT);
	glLoadIdentity();
	gluLookAt(EyeSep / 2, 0, EyeBack, FocusX, FocusY, FocusZ, 0, 1, 0);
	glTranslatef(0, 0, centerZ);
	glMultMatrixd(_matrix);
	if (show_axis)
	    DrawAxis(1.0f);
	if (wireframe)		/* if Wireframe is checked */
	    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	/* draw wireframe */

	else			/* else */
	    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	/* draw filled polygons */
	DrawModel();
	glTranslatef(0, 0, -centerZ);
	glPopMatrix();

	/* Left Eye */
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45, (double) ww / (double) wh, 0.1, -_zFar);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glDrawBuffer(GL_BACK_LEFT);
	glLoadIdentity();
	gluLookAt(-EyeSep / 2, 0, EyeBack, FocusX, FocusY, FocusZ, 0, 1,
		  0);
	glPushMatrix();
	glTranslatef(0, 0, centerZ);
	glMultMatrixd(_matrix);
	if (show_axis)
	    DrawAxis(1.0f);
	if (wireframe)		/* if Wireframe is checked */
	    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	/* draw wireframe */

	else			/* else */
	    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	/* draw filled polygons */
	DrawModel();
	glTranslatef(0, 0, -centerZ);
	glPopMatrix();
	glPopMatrix();
    }

    else {			/* NON stereo mode */

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
	glLoadIdentity();
	glTranslatef(0, 0, centerZ);	/* to center object down Z */
	glMultMatrixd(_matrix);
	if (show_axis)
	    DrawAxis(1.0f);
	if (wireframe)		/* if Wireframe is checked */
	    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	/* draw wireframe */

	else			/* else */
	    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	/* draw filled polygons */
	DrawModel();
	glTranslatef(0, 0, -centerZ);	/* to center object down Z */
	glPopMatrix();
    }
    if (show_help)
	HelpDisplay(ww, wh);
    glutSwapBuffers();
}
예제 #27
0
void CGlObjLoader::Display(void)
{


    /*    GLint viewport[4]; */
    /*255
       int jitter;

       glGetIntegerv (GL_VIEWPORT, viewport);

       glClear(GL_ACCUM_BUFFER_BIT);
       for (jitter = 0; jitter < ACSIZE; jitter++) {
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       accPerspective (50.0,
       (GLdouble) viewport[2]/(GLdouble) viewport[3],
       1.0, 15.0, j8[jitter].x, j8[jitter].y, 0.0, 0.0, 1.0);
       DrawModel();
       glAccum(GL_ACCUM, 2551.0/ACSIZE);
       }
       glAccum (GL_RETURN, 1.0);
       glFlush();
     */

    //if (lighting) {
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
//    } else {
//        glDisable(GL_LIGHTING);
//        glDisable(GL_LIGHT0);
//    }


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();

    glLoadIdentity();
    glTranslatef(0, 0, -0.6);	/* to center object down Z */



    glRotatef(roll, 0.0f, 0.0f , 1.0f);
    glRotatef(yaw, 0.0f, 1.0f, 0.0f);
    glRotatef(pitch, 1.0f, 0.0f, 0.0f);

    glMultMatrixd(_matrix);

    //	if (show_axis)
    //	    DrawAxis(1.0f);
    //	if (wireframe)		/* if Wireframe is checked */
    //	    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	/* draw wireframe */
    //	else			/* else */
    //	    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	/* draw filled polygons */

    DrawModel();
    //glTranslatef(0, 0, 0.3);	/* to center object down Z */
    glPopMatrix();

    //glFlush();
    glutSwapBuffers();


    frontBuffer =  cv::Mat(480,640,CV_8UC3);
    depthBuffer =  cv::Mat(480,640,CV_32F);

//    cv::Mat tempFront(480,640,CV_8UC3);
//    cv::Mat depthFront(480,640,CV_32F);

    glReadPixels(0,0,frontBuffer.cols, frontBuffer.rows, GL_BGR, GL_UNSIGNED_BYTE , frontBuffer.data);
    glReadPixels(0,0,depthBuffer.cols, depthBuffer.rows, GL_DEPTH_COMPONENT , GL_FLOAT,depthBuffer.data);

//    tempFront.copyTo(*frontBuffer);
//    depthFront.copyTo(*depthBuffer);


    cv::flip(frontBuffer, frontBuffer, 0);
    cv::flip(depthBuffer, depthBuffer, 0);

    depthBuffer = depthBuffer * 1050;

    depthBuffer.convertTo(depthBuffer, CV_16U);

    //one = cv::Mat(480,640, CV_8U);
    cv::Mat one = cv::Mat::ones(480,640, CV_16U) * 1050;

    depthBuffer = one  - depthBuffer;

    cv::imwrite("test.png",frontBuffer);
    cv::imwrite("depth.png",depthBuffer);
    //std::cout << depthBuffer << std::endl;
}
void display(void)
{

    //Update matrices and light to scene transformation
    int backup = 1;

    updateScene();

    lightPosition = SetVector(sphereModelMatrix.m[3],sphereModelMatrix.m[7],sphereModelMatrix.m[11]);

    //Create DepthMaps



    if(backup == 1){
        //DRAW  __ALL__ PHONG OBJECTS TO THE SAME FBO (+ Depth test! )
        useFBO(fbo_phong,0L,0L);

        glUseProgram(phongshader);
        glClearColor(0.2, 0.0, 0.0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        //Send info that is the same for all objects (projection, view matrix, light etc)
        glUniformMatrix4fv(glGetUniformLocation(phongshader, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);

        glUniformMatrix4fv(glGetUniformLocation(phongshader, "viewMatrix"), 1, GL_TRUE, viewMatrix.m);
        glUniform3f(glGetUniformLocation(phongshader, "camPosition"),cam.x,cam.y,cam.z);
        glUniform1i(glGetUniformLocation(phongshader, "texUnit"), 0);
        glUniform3f(glGetUniformLocation(phongshader,"lightPosition"), lightPosition.x, lightPosition.y, lightPosition.z);
        glUniform3f(glGetUniformLocation(phongshader,"lightColor"), lightColor.x, lightColor.y, lightColor.z);


        //Enable depth tests and all that
        // Enable Z-buffering
        glEnable(GL_DEPTH_TEST);
        // Enable backface culling
        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);

        drawSinglePhongObject(bunny, modelMatrix, bunnyColor.x,bunnyColor.y, bunnyColor.z);
        drawSinglePhongObject(statue, statueMatrix, 0.3,0.7,0.4);
        drawSinglePhongObject(box, boxMatrix, 1.0,0.2,0.5);
        drawSinglePhongObject(bottom, bottomModelMatrix, sceneColor.x, sceneColor.y, sceneColor.z);
        drawSinglePhongObject(side1, side1ModelMatrix, sceneColor.x, sceneColor.y, sceneColor.z);
        drawSinglePhongObject(side2, side2ModelMatrix, sceneColor.x, sceneColor.y, sceneColor.z);

        //ALL LIGHTSURFACES (SAME FBO as PHONG)
        glUseProgram(lightShader);
        glUniformMatrix4fv(glGetUniformLocation(lightShader, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
        glUniformMatrix4fv(glGetUniformLocation(lightShader, "viewMatrix"), 1, GL_TRUE, viewMatrix.m);

        //sphere
        glUniformMatrix4fv(glGetUniformLocation(lightShader, "modelMatrix"), 1, GL_TRUE, sphereModelMatrix.m);
        DrawModel(sphere, lightShader, "in_Position", NULL, NULL);


        //DRAW ALL TRANSLUCENT OBJECTS TO ANOTHER FBO
        useFBO(fbo_sub, 0L, 0L);
        glClearColor(0.0, 0.0, 0.0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glUseProgram(shader);
        glUniformMatrix4fv(glGetUniformLocation(shader, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
        glUniformMatrix4fv(glGetUniformLocation(shader, "viewMatrix"), 1, GL_TRUE, viewMatrix.m);
        glUniform3f(glGetUniformLocation(shader, "camPosition"),cam.x,cam.y,cam.z);
        glUniform3f(glGetUniformLocation(shader,"lightPosition"), lightPosition.x, lightPosition.y, lightPosition.z);
        glUniform1i(glGetUniformLocation(shader, "texUnit"), 0);

        // Enable Z-buffering
        glDisable(GL_CULL_FACE);

        //bunny
        drawSingleTranslucentObject(thicknessBunny , bunny, modelMatrix, bunnyColor.x,bunnyColor.y, bunnyColor.z);
        drawSingleTranslucentObject(thicknessStatue, statue, statueMatrix, 0.3,0.7,0.4);
        drawSingleTranslucentObject(thicknessBox, box, boxMatrix, 1.0,0.2,0.5);


        //JOIN SHADER
        useFBO(fbo3, fbo_phong, fbo_sub); //write to fbo3, read from fbo2 and from fbo1
        glUseProgram(joinshader);

        glUniform1i(glGetUniformLocation(joinshader, "texUnit"), 0);
        glUniform1i(glGetUniformLocation(joinshader, "texUnit2"), 1);

        glDisable(GL_CULL_FACE);
        glDisable(GL_DEPTH_TEST);
        DrawModel(squareModel, joinshader, "in_Position", NULL, "in_TexCoord");

        //Pass on Shader
        useFBO(0L, fbo3, 0L);
        glClearColor(0.0, 0.0, 0.0, 0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glUseProgram(passShader);
        glUniform1i(glGetUniformLocation(passShader, "texUnit"), 0);
        glDisable(GL_CULL_FACE);
        glDisable(GL_DEPTH_TEST);
        DrawModel(squareModel, passShader, "in_Position", NULL, "in_TexCoord");
    }

    else{


        vec3 cameraPosition = cam;
        lightViewMatrix = lookAt(lightPosition.x, lightPosition.y, lightPosition.z,
                    point.x, point.y, point.z, 0,1,0);

        // Setup the view from the light source
        viewMatrix = lightViewMatrix;

        //Setup projection matrix

        // 1. render scene to FBO 1 with Back culling
        useFBO(fbo_depth, NULL, NULL);
        glViewport(0,0,W,H);
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); // Depth only
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        //Using the simple shader
        glUseProgram(plainShaderId);
        glUniform1i(plainShaderId,TEX_UNIT);
        glActiveTexture(GL_TEXTURE0 + TEX_UNIT);
        glBindTexture(GL_TEXTURE_2D,0);

        glCullFace(GL_BACK);

        printf("%s\n", "mohahahaha");
        drawObjectsFirstPass(plainShaderId);


        // 1. render scene to FBO 2
        useFBO(fbo_depth2, NULL, NULL);
        glViewport(0,0,W,H);
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); // Depth only
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        //Using the simple shader with front culling
        glUseProgram(plainShaderId);
        glUniform1i(plainShaderId,TEX_UNIT);
        glActiveTexture(GL_TEXTURE1 + TEX_UNIT);
        glBindTexture(GL_TEXTURE_2D,1);

        glCullFace(GL_FRONT);

        printf("%s\n", "mohahahaha");
        drawObjectsFirstPass(plainShaderId);


        // Render from Camera

        //Move camera back to original camera position
        //zprInit(&viewMatrix, camtemp,point);
        useFBO(NULL, fbo_depth, fbo_depth2);
        glViewport(0,0,W,H);

        //Enabling color write (previously disabled for light POV z-buffer rendering)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

        // Clear previous frame values
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        //Using the projTex shader
        glUseProgram(projTexShaderId2);

        glUniform1i(glGetUniformLocation(projTexShaderId2, "texxxUnit"), 0);
        glUniform1i(glGetUniformLocation(projTexShaderId2, "texxxUnit2"), 1);


        glUniform1i(projTexMapUniform,TEX_UNIT);
        glActiveTexture(GL_TEXTURE0 + TEX_UNIT);
        glBindTexture(GL_TEXTURE_2D,fbo_depth->depth);

        glUniform1i(projTexMapUniform,TEX_UNIT);
        glActiveTexture(GL_TEXTURE1 + TEX_UNIT);
        glBindTexture(GL_TEXTURE_2D,fbo_depth2->depth);



        // Setup the modelview from the camera
       // modelViewMatrix = lookAt(p_camera.x, p_camera.y, p_camera.z,
        //                l_camera.x, l_camera.y, l_camera.z, 0,1,0);

            // Setup the view from the light source
      // viewMatrix = lookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
      //             point.x, point.y, point.z, 0,1,0);


           printf("%s\n", "yakiyakiyaki");
        glCullFace(GL_BACK);

        drawObjects(projTexShaderId2);
    }

    //Reset scene transformation
    sceneModelMatrix = IdentityMatrix();
}
예제 #29
0
/*******************************************************************************
 * Function Name  : RenderScene
 * Returns		  : true if no error occured
 * Description    : Main rendering loop function of the program. The shell will
 *					call this function every frame.
 *******************************************************************************/
bool OGLESSkinning::RenderScene()
{
	// Increase the frame number
	m_fFrame += 0.3f;

	while(m_fFrame > m_Scene.nNumFrame-1)
		m_fFrame -= m_Scene.nNumFrame-1;

	// Modify the transformation matrix if it is needed
	bool bRebuildTransformation = false;

	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		m_fAngle -= 0.03f;

		if(m_fAngle < PVRT_TWO_PIf)
			m_fAngle += PVRT_TWO_PIf;

		bRebuildTransformation = true;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		m_fAngle += 0.03f;

		if(m_fAngle > PVRT_TWO_PIf)
			m_fAngle -= PVRT_TWO_PIf;

		bRebuildTransformation = true;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
	{
		m_fDistance -= 10.0f;

		if(m_fDistance < -500.0f)
			m_fDistance = -500.0f;

		bRebuildTransformation = true;
	}

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
	{
		m_fDistance += 10.0f;

		if(m_fDistance > 200.0f)
			m_fDistance = 200.0f;

		bRebuildTransformation = true;
	}

	if(bRebuildTransformation)
		m_mTransform = PVRTMat4::Translation(0,0, m_fDistance) * PVRTMat4::RotationY(m_fAngle);

	// Clear the depth and frame buffer
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Set Z compare properties
	glEnable(GL_DEPTH_TEST);

	// Disable Blending
	glDisable(GL_BLEND);

	// Calculate the model view matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(m_mView.f);

	// Draw the model
	DrawModel();

	// Print text on screen
	m_Print3D.DisplayDefaultTitle("Skinning", "", ePVRTPrint3DSDKLogo);

	// Flush all Print3D commands
	m_Print3D.Flush();

	return true;
}
예제 #30
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();
}