示例#1
0
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glRotated(rotation_x, 1.0, 0.0, 0.0);
    \
    glRotated(rotation_y, 0.0, 1.0, 0.0);
    \
    glTranslated(-position_x, -position_y, -position_z);
    \
    \
    glPushMatrix();
    \
    {   \
        glDisable(GL_LIGHTING);
        plane_render(P);

        glTranslated(0.0, 1.0, 0.0);

        glEnable(GL_LIGHTING);
        cube_render(C);
    }                                                                          \
    glPopMatrix();
    \

    glutSwapBuffers();
}
示例#2
0
void display(void)
{
    GLdouble tb = zoom;                                                        \
    GLdouble lr = zoom * glutGet(GLUT_WINDOW_WIDTH)                            \
                       / glutGet(GLUT_WINDOW_HEIGHT);                          \

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);                                               \
    glLoadIdentity();                                                          \
    glFrustum(-lr, lr, -tb, tb, 1.0, 100.0);                                   \
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glRotated(rotation_x, 1.0, 0.0, 0.0);
    glRotated(rotation_y, 0.0, 1.0, 0.0);
    glTranslated(-position_x, -position_y, -position_z);

    glPushMatrix();
    {
        glDisable(GL_LIGHTING);
        plane_render(P);

        glTranslated(0.0, 1.0, 0.0);

        glEnable(GL_LIGHTING);
        cube_render(C);
    }
    glPopMatrix();
    
    glutSwapBuffers();
}
示例#3
0
static void display() {
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	//glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	GLfloat S[16] = {
			0.5f, 0.0f, 0.0f, 0.0f,
			0.0f, 0.5f, 0.0f, 0.0f,
			0.0f, 0.0f, 0.5f, 0.0f,
			0.5f, 0.5f, 0.5f, 1.0f,
    };

	GLdouble size = 16.0;

	switch(spotLightChosen) {
	case SPOTLIGHT1: {
						GLint spotlight1location = glGetUniformLocation(spotlight1loader->getProgram(), "image");
						spotlight1loader->bind();
						glUniform1i(spotlight1location, 0);

						spotlight1loader->bind();
						glActiveTexture(GL_TEXTURE0);
						//std::cout << "Texture 1: " << boxloader->getTexture(0) << std::endl;
						glBindTexture(GL_TEXTURE_2D, spotlight1loader->getTexture(0));
						
						glMatrixMode(GL_TEXTURE);
						{
							glLoadMatrixf(S);
						    glOrtho(-size, +size, -size, +size, -size, +size);
						    glRotated(-light[0], 1.0, 0.0, 0.0);
							glRotated(-light[1], 0.0, 1.0, 0.0);
						}
					}
		break;
	case SPOTLIGHT2:
		break;
	case NOSPOTLIGHT:
		//
		break;
	default:
		std::cout << "OnDraw - spotLightChosen: Shouldn't be here" << std::endl;
		break;
	}

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	lights();

	/*Camera */
	viewglut_apply(camera);
	viewglut_render(camera);

	/*Drawing*/
	glTranslatef(0, 0, -10);

	glPushMatrix(); 
	{
		if(planeEnabled) {
			glDisable(GL_LIGHTING);
			plane_render(p);
			glEnable(GL_LIGHTING);
		}
		
	}
	glPopMatrix();


    glTranslated(0.0, 1.0, 0.0);
	switch(modelChosen) {
	case THIRTEENBOX:{	//glMatrixMode(GL_TEXTURE);
						//glEnable(GL_TEXTURE_2D);
						GLint diffuselocation = glGetUniformLocation(boxloader->getProgram(), "diffuse_texture");
						GLint normallocation = glGetUniformLocation(boxloader->getProgram(), "normal_texture");

						//std::cout << "diffuse location: " << diffuselocation << std::endl;
						//std::cout << "normal location: " << normallocation << std::endl;

						boxloader->bind();
						glUniform1i(diffuselocation, 0);
						glUniform1i(normallocation, 1);

						//glActiveTexture(GL_TEXTURE0 + boxloader->getTexture(0));
						glActiveTexture(GL_TEXTURE0);
						//std::cout << "Texture 1: " << boxloader->getTexture(0) << std::endl;
						glBindTexture(GL_TEXTURE_2D, boxloader->getTexture(0));
						glActiveTexture(GL_TEXTURE1);
						//std::cout << "Texture 2: " << boxloader->getTexture(1) << std::endl;
						glBindTexture(GL_TEXTURE_2D, boxloader->getTexture(1));
					
						obj_render(box);
						
						boxloader->unbind();
					}
					break;
	case TROLL:
		obj_render(troll);
		break;
	case NOMODELS:
		//Nothing gets rendered homeboy
		break;
	default:
		std::cout << "modelChosen Out of Range. Draw Method-modelChosen = " << modelChosen << std::endl;
		break;
	}
	glMatrixMode(GL_MODELVIEW);

	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	glutSwapBuffers();
}