Beispiel #1
0
Datei: obj.c Projekt: cjxgm/clabs
void render(void)
{
	unsigned int time = glutGet(GLUT_ELAPSED_TIME);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix(); {
		camApply();
		glTranslatef(0, 0, -5);
		glRotatef(90, 1, 0, 0);
		draw_obj(go);
	} glPopMatrix();

	// draw fps
	char buf[128];
	sprintf(buf, "fps: %.2f", fps);
	glColor3f(0.8, 0, 0);
	renderString(10, 10, buf, NULL);
	// camera matrix
	{
		int y, x;
		for (y=0; y<4; y++)
			for (x=0; x<4; x++) {
				sprintf(buf, "%+.3f", camera[y*4+x]);
				renderString(10 + x * 80, 180 - y*20, buf, NULL);
			}
	}

	float pos[3];
	camGetPosition(pos);
	sprintf(buf, "%+.3f %+.3f %+.3f", pos[0], pos[1], pos[2]);
	renderString(10, 40, buf, NULL);

	glutSwapBuffers();

	if (key[27]) exit(0);

	camBegin();
	if (key['w']) camForward(+4 / fps);
	if (key['s']) camForward(-4 / fps);
	if (key['d']) camTurn(+90 / fps);
	if (key['a']) camTurn(-90 / fps);
	if (key['q']) camPan(+4 / fps);
	if (key['e']) camPan(-4 / fps);
	camEnd();

	fps = 1000.0 / (glutGet(GLUT_ELAPSED_TIME) - time);
}
//this is where the actual drawing happens
void display() {

	glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

	glLoadIdentity();

	camApply(g_Camera);

	drawFPS();

	processList();

	glFlush();

	if (!g_bPicking) {
		glutSwapBuffers();
	}
	else {
		finishPicking();
	}
}