|
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- #include <GL/gl.h>
- #include <GL/glut.h>
-
- #include "tb.h"
-
- int w_win = 640;
- int h_win = 480;
-
- static void setcamera(void)
- {
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- gluPerspective(40, (float)w_win / (float)h_win, 1, 1000);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0, 0.0, (float)h_win / 200.0f, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- }
-
- static void myinit(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClearColor(0.5, 0.5, 0.7, 0.0);
- glColor3f(1.0, 1.0, 1.0);
-
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
- glDisable(GL_CULL_FACE);
-
- glShadeModel(GL_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_DEPTH_TEST);
-
- setcamera();
-
- tbInit(GLUT_LEFT_BUTTON);
- tbAnimate(GL_FALSE);
- }
-
- static void parsekey(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 27:
- exit(0);
- break;
- }
- }
-
- static void motion(int x, int y)
- {
- tbMotion(x, y);
- }
-
- static void mouse(int button, int state, int x, int y)
- {
- tbMouse(button, state, x, y);
- }
-
- static void reshape(int w, int h)
- {
- glMatrixMode (GL_MODELVIEW);
- glViewport (0, 0, w, h);
- glLoadIdentity();
-
- w_win = w;
- h_win = h;
- setcamera();
-
- tbReshape(w_win, h_win);
- }
-
- #define F(x) ((x)*1.01 - 0.005)
- #define CP glColor4f(x0,y0,z0,0.9); glVertex3f(x0,y0,z0)
- #define BP glColor3f(0.0,0.0,0.0); glVertex3f(F(x0),F(y0),F(z0))
- #define BLACK x0 = y0 = z0 = 0.0
- #define RED x0 = 1.0; y0 = z0 = 0.0
- //#define XRED x0 = 0.8; y0 = z0 = 0.0
- #define XRED RED
- #define GREEN y0 = 1.0; x0 = z0 = 0.0
- //#define XGREEN y0 = 0.7; x0 = z0 = 0.0
- #define XGREEN GREEN
- #define BLUE z0 = 1.0; x0 = y0 = 0.0
- //#define XBLUE x0 = 0.0; y0 = 0.0; z0 = 0.5
- #define XBLUE BLUE
- #define YELLOW x0 = y0 = 1.0; z0 = 0.0
- #define CYAN y0 = z0 = 1.0; x0 = 0.0
- #define MAGENTA x0 = z0 = 1.0; y0 = 0.0
- #define WHITE x0 = y0 = z0 = 1.0
-
- static void display(void)
- {
- float x0,y0,z0;
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- setcamera();
-
- tbMatrix();
-
- glPushMatrix();
- glTranslatef(-.5, -.5, -.5);
- // Bounding box
- glBegin(GL_LINE_LOOP);
- BLACK; CP; RED; CP; MAGENTA; CP; BLUE; CP;
- CYAN; CP; WHITE; CP; YELLOW; CP; GREEN; CP;
- glEnd();
- glBegin(GL_LINES);
- BLACK; CP; BLUE; CP;
- GREEN; CP; CYAN; CP;
- RED; CP; YELLOW; CP;
- MAGENTA; CP; WHITE; CP;
- glEnd();
- // Our colour space
- glBegin(GL_TRIANGLES); XRED; CP; XGREEN; CP; XBLUE; CP; glEnd();
- glBegin(GL_TRIANGLES); XRED; CP; XGREEN; CP; YELLOW; CP; glEnd();
- glBegin(GL_TRIANGLES); XRED; CP; XBLUE; CP; WHITE; CP; glEnd();
- glBegin(GL_TRIANGLES); XRED; CP; YELLOW; CP; WHITE; CP; glEnd();
- glBegin(GL_TRIANGLES); XBLUE; CP; XGREEN; CP; WHITE; CP; glEnd();
- glBegin(GL_TRIANGLES); YELLOW; CP; XGREEN; CP; WHITE; CP; glEnd();
- // Better edges
- glBegin(GL_LINES);
- XBLUE; BP; XRED; BP; YELLOW; BP; XRED; BP;
- XBLUE; BP; XGREEN; BP; YELLOW; BP; XGREEN; BP;
- XBLUE; BP; WHITE; BP; YELLOW; BP; WHITE; BP;
- XRED; BP; XGREEN; BP;
- XGREEN; BP; WHITE; BP;
- WHITE; BP; XRED; BP;
- glEnd();
- glTranslatef(.5, .5, .4);
- glColor4f(.2, .2, .2, .5);
- glBegin(GL_QUADS);
- glVertex3f(0.891063,-0.45388,0);
- glVertex3f(0.0773943,0.151941,-0.985355);
- glVertex3f(-0.891063,0.45388,0);
- glVertex3f(-0.0773943,-0.151941,0.985355);
- glEnd();
- glPopMatrix();
-
- glutSwapBuffers();
- }
-
- int main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE | GLUT_MULTISAMPLE);
- glutInitWindowPosition(50, 50);
- glutInitWindowSize(w_win, h_win);
- glutCreateWindow("FTGL TEST");
- glutDisplayFunc(display);
- glutKeyboardFunc(parsekey);
- glutMouseFunc(mouse);
- glutMotionFunc(motion);
- glutReshapeFunc(reshape);
- glutIdleFunc(display);
-
- myinit();
- glutMainLoop();
-
- return 0;
- }
|