X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=sidebyside;f=miniglut.c;h=92682024590c3e97ceb0d5f3ee52dfcddaed68a6;hb=02536825844445fbb648cf2a69c97760e7eef885;hp=04ffcfbb555831e4291ff6601ce3789098eda1eb;hpb=ea1f048408daa719d70e78dd88f7ff12f03ac902;p=miniglut
diff --git a/miniglut.c b/miniglut.c
index 04ffcfb..9268202 100644
--- a/miniglut.c
+++ b/miniglut.c
@@ -15,10 +15,22 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+/*#define MINIGLUT_GCC_NO_BUILTIN*/
+
#ifdef MINIGLUT_USE_LIBC
#define _GNU_SOURCE
#include
#include
+#else
+
+#if defined(__GNUC__) && !defined(MINIGLUT_GCC_NO_BUILTIN)
+#define mglut_sincosf(a, s, c) __builtin_sincosf(a, s, c)
+#define mglut_atan(x) __builtin_atan(x)
+#else
+static void mglut_sincosf(float angle, float *sptr, float *cptr);
+static float mglut_atan(float x);
+#endif
+
#endif
#define PI 3.1415926536f
@@ -71,9 +83,9 @@ struct ctx_info {
};
static void create_window(const char *title);
-static void get_window_pos(Window win, int *x, int *y);
-static void get_window_size(Window win, int *w, int *h);
-static void get_screen_size(Window win, int *scrw, int *scrh);
+static void get_window_pos(int *x, int *y);
+static void get_window_size(int *w, int *h);
+static void get_screen_size(int *scrw, int *scrh);
static long get_msec(void);
static void panic(const char *msg);
@@ -277,16 +289,16 @@ int glutGet(unsigned int s)
int x, y;
switch(s) {
case GLUT_WINDOW_X:
- get_window_pos(win, &x, &y);
+ get_window_pos(&x, &y);
return x;
case GLUT_WINDOW_Y:
- get_window_pos(win, &x, &y);
+ get_window_pos(&x, &y);
return y;
case GLUT_WINDOW_WIDTH:
- get_window_size(win, &x, &y);
+ get_window_size(&x, &y);
return x;
case GLUT_WINDOW_HEIGHT:
- get_window_size(win, &x, &y);
+ get_window_size(&x, &y);
return y;
case GLUT_WINDOW_BUFFER_SIZE:
return ctx_info.rsize + ctx_info.gsize + ctx_info.bsize + ctx_info.asize;
@@ -315,10 +327,10 @@ int glutGet(unsigned int s)
case GLUT_WINDOW_CURSOR:
return cur_cursor;
case GLUT_SCREEN_WIDTH:
- get_screen_size(win, &x, &y);
+ get_screen_size(&x, &y);
return x;
case GLUT_SCREEN_HEIGHT:
- get_screen_size(win, &x, &y);
+ get_screen_size(&x, &y);
return y;
case GLUT_INIT_DISPLAY_MODE:
return init_mode;
@@ -397,8 +409,8 @@ void glutSolidSphere(float rad, int slices, int stacks)
t = gray & 2 ? v + dv : v;
theta = s * PI * 2.0f;
phi = t * PI;
- sincosf(theta, &sintheta, &costheta);
- sincosf(phi, &sinphi, &cosphi);
+ mglut_sincosf(theta, &sintheta, &costheta);
+ mglut_sincosf(phi, &sinphi, &cosphi);
x = sintheta * sinphi;
y = costheta * sinphi;
z = cosphi;
@@ -462,8 +474,9 @@ static void draw_cylinder(float rbot, float rtop, float height, int slices, int
float du = 1.0f / (float)slices;
float dv = 1.0f / (float)stacks;
- phi = atan(fabs(rbot - rtop) / height);
- sincosf(phi, &sinphi, &cosphi);
+ rad = rbot - rtop;
+ phi = mglut_atan((rad < 0 ? -rad : rad) / height);
+ mglut_sincosf(phi, &sinphi, &cosphi);
glBegin(GL_QUADS);
for(i=0; i