1 // vecgl.h
2 //
3 // Copyright (C) 2000, Chris Laurel <claurel@shatters.net>
4 //
5 // Overloaded versions of GL functions
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 
12 #ifndef _VECGL_H_
13 #define _VECGL_H_
14 
15 #include <celmath/vecmath.h>
16 #include <celmath/quaternion.h>
17 #include <celutil/color.h>
18 
19 
glVertex(const Point3f & p)20 inline void glVertex(const Point3f& p)
21 {
22     glVertex3fv(&p.x);
23 }
24 
glVertex(const Vec3f & v)25 inline void glVertex(const Vec3f& v)
26 {
27     glVertex3fv(&v.x);
28 }
29 
glNormal(const Vec3f & n)30 inline void glNormal(const Vec3f& n)
31 {
32     glNormal3fv(&n.x);
33 }
34 
glTexCoord(const Point2f & p)35 inline void glTexCoord(const Point2f& p)
36 {
37     glTexCoord2fv(&p.x);
38 }
39 
glColor(const Color & c)40 inline void glColor(const Color& c)
41 {
42     glColor4f(c.red(), c.green(), c.blue(), c.alpha());
43 }
44 
glColor(const Color & c,float a)45 inline void glColor(const Color& c, float a)
46 {
47     glColor4f(c.red(), c.green(), c.blue(), c.alpha() * a);
48 }
49 
50 
glMatrix(const Mat4f & m)51 inline void glMatrix(const Mat4f& m)
52 {
53     Mat4f trans = m.transpose();
54     glMultMatrixf(&trans[0].x);
55 }
56 
57 
glMatrix(const Mat4d & m)58 inline void glMatrix(const Mat4d& m)
59 {
60     Mat4d trans = m.transpose();
61     glMultMatrixd(&trans[0].x);
62 }
63 
64 
glRotate(const Quatf & q)65 inline void glRotate(const Quatf& q)
66 {
67     glMatrix(q.toMatrix4());
68 }
69 
glRotate(const Quatd & q)70 inline void glRotate(const Quatd& q)
71 {
72     glMatrix(q.toMatrix4());
73 }
74 
glTranslate(const Vec3f & v)75 inline void glTranslate(const Vec3f& v)
76 {
77     glTranslatef(v.x, v.y, v.z);
78 }
79 
glTranslate(const Point3f & p)80 inline void glTranslate(const Point3f& p)
81 {
82     glTranslatef(p.x, p.y, p.z);
83 }
84 
glScale(const Vec3f & v)85 inline void glScale(const Vec3f& v)
86 {
87     glScalef(v.x, v.y, v.z);
88 }
89 
glLightDirection(GLenum light,const Vec3f & dir)90 inline void glLightDirection(GLenum light, const Vec3f& dir)
91 {
92 	Vec4f dir4 = Vec4f(dir.x, dir.y, dir.z, 0.0f);
93     glLightfv(light, GL_POSITION, &(dir4.x));
94 }
95 
glLightPosition(GLenum light,const Point3f & pos)96 inline void glLightPosition(GLenum light, const Point3f& pos)
97 {
98 	Vec4f pos4 = Vec4f(pos.x, pos.y, pos.z, 1.0f);
99     glLightfv(light, GL_POSITION, &(pos4.x));
100 }
101 
glLightColor(GLenum light,GLenum which,const Vec3f & color)102 inline void glLightColor(GLenum light, GLenum which, const Vec3f& color)
103 {
104 	Vec4f color4 = Vec4f(color.x, color.y, color.z, 1.0f);
105     glLightfv(light, which, &(color4.x));
106 }
107 
glLightColor(GLenum light,GLenum which,const Vec4f & color)108 inline void glLightColor(GLenum light, GLenum which, const Vec4f& color)
109 {
110     glLightfv(light, which, &color.x);
111 }
112 
glLightColor(GLenum light,GLenum which,const Color & color)113 inline void glLightColor(GLenum light, GLenum which, const Color& color)
114 {
115 	Vec4f color4 = Vec4f(color.red(), color.green(), color.blue(), color.alpha());
116     glLightfv(light, which, &(color4.x));
117 }
118 
glAmbientLightColor(const Color & color)119 inline void glAmbientLightColor(const Color& color)
120 {
121 	Vec4f color4 = Vec4f(color.red(), color.green(), color.blue(), color.alpha());
122     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &(color4.x));
123 }
124 
125 #endif // _VECGL_H_
126 
127