coeng

diff src/test.cc @ 0:14e743b53289

component system test
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 04 Feb 2015 17:23:35 +0200
parents
children 4a1c9597f4d3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/test.cc	Wed Feb 04 17:23:35 2015 +0200
     1.3 @@ -0,0 +1,95 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <assert.h>
     1.7 +
     1.8 +#ifndef __APPLE__
     1.9 +#include <GL/glut.h>
    1.10 +#else
    1.11 +#include <GLUT/glut.h>
    1.12 +#endif
    1.13 +
    1.14 +static bool init();
    1.15 +static void cleanup();
    1.16 +static void display();
    1.17 +static void idle();
    1.18 +static void reshape(int x, int y);
    1.19 +static void keyb(unsigned char key, int x, int y);
    1.20 +static void mouse(int bn, int st, int x, int y);
    1.21 +static void motion(int x, int y);
    1.22 +
    1.23 +
    1.24 +int main(int argc, char **argv)
    1.25 +{
    1.26 +	glutInit(&argc, argv);
    1.27 +	glutInitWindowSize(800, 600);
    1.28 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.29 +	glutCreateWindow("component system test");
    1.30 +
    1.31 +	glutDisplayFunc(display);
    1.32 +	glutIdleFunc(idle);
    1.33 +	glutReshapeFunc(reshape);
    1.34 +	glutKeyboardFunc(keyb);
    1.35 +	glutMouseFunc(mouse);
    1.36 +	glutMotionFunc(motion);
    1.37 +
    1.38 +	if(!init()) {
    1.39 +		return 1;
    1.40 +	}
    1.41 +	atexit(cleanup);
    1.42 +
    1.43 +	glutMainLoop();
    1.44 +	return 0;
    1.45 +}
    1.46 +
    1.47 +static bool init()
    1.48 +{
    1.49 +	glEnable(GL_DEPTH_TEST);
    1.50 +	glEnable(GL_CULL_FACE);
    1.51 +
    1.52 +	return true;
    1.53 +}
    1.54 +
    1.55 +static void cleanup()
    1.56 +{
    1.57 +}
    1.58 +
    1.59 +static void display()
    1.60 +{
    1.61 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.62 +
    1.63 +	glutSwapBuffers();
    1.64 +	assert(glGetError() == GL_NO_ERROR);
    1.65 +}
    1.66 +
    1.67 +static void idle()
    1.68 +{
    1.69 +	glutPostRedisplay();
    1.70 +}
    1.71 +
    1.72 +static void reshape(int x, int y)
    1.73 +{
    1.74 +	glViewport(0, 0, x, y);
    1.75 +
    1.76 +	glMatrixMode(GL_PROJECION);
    1.77 +	glLoadIdentity();
    1.78 +	gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
    1.79 +}
    1.80 +
    1.81 +static void keyb(unsigned char key, int x, int y)
    1.82 +{
    1.83 +	switch(key) {
    1.84 +	case 27:
    1.85 +		exit(0);
    1.86 +	}
    1.87 +}
    1.88 +
    1.89 +static int bnstate[16];
    1.90 +static int prev_x, prev_y;
    1.91 +
    1.92 +static void mouse(int bn, int st, int x, int y)
    1.93 +{
    1.94 +}
    1.95 +
    1.96 +static void motion(int x, int y)
    1.97 +{
    1.98 +}