Fixed some transforms, move to 3d and quaternion math in progress...
[ne.git] / src / backend / shapes.c
blob3ef12be15eafac8ed3e0755d79a689fffce76bb3
1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
18 #include "shapes.h"
20 #include <GL/gl.h>
21 #include <math.h>
23 static GLuint circle, quad, cube, sphere;
25 void shapes_init()
27 static int init = 0;
28 if (init) return;
30 init = 1;
32 quad = glGenLists(1);
34 glNewList(quad,GL_COMPILE);
35 glBegin( GL_QUADS );
36 glNormal3f(0.0,0.0,1.0);
37 glTexCoord2f(1.0,1.0); glVertex2f( 0.5, 0.5);
38 glTexCoord2f(0.0,1.0); glVertex2f(-0.5, 0.5);
39 glTexCoord2f(0.0,0.0); glVertex2f(-0.5,-0.5);
40 glTexCoord2f(1.0,0.0); glVertex2f( 0.5,-0.5);
41 glEnd();
42 glEndList();
45 circle = glGenLists(1);
47 glNewList(circle,GL_COMPILE);
48 int points = 64;
49 glBegin(GL_TRIANGLE_FAN);
50 glNormal3f(0.0f, 0.0f, 1.0f);
51 int i;
52 for (i=0; i<points; i++)
54 float t = (float)i/points;
55 t *= 2 * M_PI;
56 glVertex2f(0.5*cos(t),0.5*sin(t));
58 glEnd();
59 glEndList();
62 cube = glGenLists(1);
64 glNewList(cube,GL_COMPILE);
65 glBegin(GL_QUADS);
66 // front
67 glNormal3f(0.0f, 0.0f, 1.0f);
68 glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f,-0.5f, 0.5f);
69 glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f,-0.5f, 0.5f);
70 glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f, 0.5f);
71 glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f);
72 // back
73 glNormal3f(0.0f, 0.0f,-1.0f);
74 glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f,-0.5f,-0.5f);
75 glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f,-0.5f);
76 glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f,-0.5f);
77 glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f,-0.5f,-0.5f);
78 // top
79 glNormal3f(0.0f, 1.0f, 0.0f);
80 glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f,-0.5f);
81 glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.5f);
82 glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, 0.5f, 0.5f);
83 glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f,-0.5f);
84 // bottom
85 glNormal3f(0.0f,-1.0f, 0.0f);
86 glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f,-0.5f,-0.5f);
87 glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f,-0.5f,-0.5f);
88 glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f,-0.5f, 0.5f);
89 glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f,-0.5f, 0.5f);
90 // right
91 glNormal3f(1.0f, 0.0f, 0.0f);
92 glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f,-0.5f,-0.5f);
93 glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f,-0.5f);
94 glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f, 0.5f);
95 glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f,-0.5f, 0.5f);
96 // left
97 glNormal3f(-1.0f, 0.0f, 0.0f);
98 glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f,-0.5f,-0.5f);
99 glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f,-0.5f, 0.5f);
100 glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f);
101 glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f,-0.5f);
102 glEnd();
103 glEndList();
107 void shapes_texturize(struct texture *tex, int tile)
109 if (tex)
111 glEnable(GL_TEXTURE_2D);
112 glMatrixMode(GL_TEXTURE);
113 glLoadIdentity();
114 glScalef(tile,tile,tile);
115 glMatrixMode(GL_MODELVIEW);
116 t_apply(tex);
118 else
120 glDisable(GL_TEXTURE_2D);
124 void draw_quad()
126 glCallList(quad);
129 void draw_circle()
131 glCallList(circle);
134 void draw_cube()
136 glCallList(cube);
139 void draw_sphere()
141 glCallList(sphere);