aboutsummaryrefslogtreecommitdiff
path: root/test_copy_to_front.c
blob: 3d69f81da6fe66da511df0d1dfecbf204b79fa46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <GL/glut.h>
#include <GL/gl.h>
#include <math.h>

static void display(void)
{
	static float a = 0;

	int const win_w = glutGet(GLUT_WINDOW_WIDTH);
	int const win_h = glutGet(GLUT_WINDOW_HEIGHT);
	float const win_a = (float)win_w/(float)win_h;

	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glViewport(0, 0, win_w, win_h);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-win_a, win_a, -1, 1, 1, 5);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0,0,-3);
	glRotatef( a = fmodf(a + 1, 360) , 0,1,0);

	glutWireTeapot(1);

	glFlush();
	glDrawBuffer(GL_FRONT);
	glReadBuffer(GL_BACK);
	glCopyPixels(0, 0, win_w, win_h, GL_COLOR);
	glFinish();
}

int main(int argc, char *argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutCreateWindow("Test copy back->front instead of buffer swap");
	glutDisplayFunc(display);
	glutIdleFunc(glutPostRedisplay);

	glutMainLoop();
	return 0;
}